miloshadzic / middleman-inline

Middleman extension to inline your JS and css
GNU General Public License v3.0
6 stars 2 forks source link

NoMethodError: undefined method `render' for nil:NilClass #6

Open caeleth opened 7 years ago

caeleth commented 7 years ago

I am trying to inline CSS but got this exception:

NoMethodError: undefined method `render' for nil:NilClass
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-inline-0.0.2/lib/middleman-inline/extension.rb:25:in `render_resource'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-inline-0.0.2/lib/middleman-inline/extension.rb:7:in `block in inline_css'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-inline-0.0.2/lib/middleman-inline/extension.rb:6:in `map'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-inline-0.0.2/lib/middleman-inline/extension.rb:6:in `inline_css'
        layouts/blog_layout.html.slim:8:in `block (2 levels) in singleton class'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/padrino-helpers-0.13.3.4/lib/padrino-helpers/output_helpers/abstract_handler.rb:33:in `capture_from_template'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/core_extensions/default_helpers.rb:68:in `capture_html'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/template_context.rb:82:in `wrap_layout'
        layouts/blog_layout.html.slim:1:in `block in singleton class'
        layouts/blog_layout.html.slim:-7:in `instance_eval'
        layouts/blog_layout.html.slim:-7:in `singleton class'
        layouts/blog_layout.html.slim:-10:in `__tilt_70336272885460'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/tilt-2.0.8/lib/tilt/template.rb:170:in `call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/tilt-2.0.8/lib/tilt/template.rb:170:in `evaluate'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/tilt-2.0.8/lib/tilt/template.rb:109:in `render'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/renderers/slim.rb:6:in `render'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/padrino-helpers-0.13.3.4/lib/padrino/rendering.rb:17:in `render'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/file_renderer.rb:79:in `render'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/contracts-0.13.0/lib/contracts/method_reference.rb:43:in `send_to'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/contracts-0.13.0/lib/contracts/call_with.rb:76:in `call_with'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/contracts-0.13.0/lib/contracts/method_handler.rb:138:in `block in redefine_method'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/template_renderer.rb:157:in `block in render'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.0.5/lib/active_support/notifications.rb:166:in `instrument'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/util.rb:21:in `instrument'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/template_renderer.rb:156:in `render'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/contracts-0.13.0/lib/contracts/method_reference.rb:43:in `send_to'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/contracts-0.13.0/lib/contracts/call_with.rb:76:in `call_with'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/contracts-0.13.0/lib/contracts/method_handler.rb:138:in `block in redefine_method'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/sitemap/resource.rb:154:in `render'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/contracts-0.13.0/lib/contracts/method_reference.rb:43:in `send_to'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/contracts-0.13.0/lib/contracts/call_with.rb:76:in `call_with'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/contracts-0.13.0/lib/contracts/method_handler.rb:138:in `block in redefine_method'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-blog-4.0.2/lib/middleman-blog/blog_article.rb:64:in `render'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/rack.rb:112:in `process_request'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/rack.rb:66:in `block in call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/rack.rb:65:in `catch'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/middleman-core-4.2.1/lib/middleman-core/rack.rb:65:in `call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/urlmap.rb:68:in `block in call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `each'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/show_exceptions.rb:23:in `call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/htmlcompressor-0.2.0/lib/htmlcompressor/rack.rb:36:in `call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/head.rb:12:in `call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/lint.rb:49:in `_call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/lint.rb:37:in `call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/builder.rb:153:in `call'
        ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/handler/webrick.rb:86:in `service'
        ~/.rbenv/versions/2.4.1/lib/ruby/2.4.0/webrick/httpserver.rb:140:in `service'
        ~/.rbenv/versions/2.4.1/lib/ruby/2.4.0/webrick/httpserver.rb:96:in `run'
        ~/.rbenv/versions/2.4.1/lib/ruby/2.4.0/webrick/server.rb:290:in `block in start_thread'

I have followed the instructions in the readme file.

This is my code:

= inline_css 'style', 'highlighting.css'

Alternative approach works fine but I want to inline that CSS, not just put a link outside the head:

= stylesheet_link_tag 'highlighting.css'

Is your gem compatible with latest version of middleman?

cowholio4 commented 6 years ago

@girlonrails I had this problem too. ended up just skipping the gem.

My example uses slim but should work in other templating languages. I am rendering "critical.css" in the header.

css:
   #{sitemap.resources.find{|r| r.source_file.match('critical.css')}.render}