rbuchberger / jekyll_picture_tag

Easy responsive images for Jekyll.
https://rbuchberger.github.io/jekyll_picture_tag/
BSD 3-Clause "New" or "Revised" License
623 stars 106 forks source link

Liquid Exception: undefined method `[]' for nil:NilClass in _drafts/JekyllAnchors.md/#excerpt #64

Closed vitalyrepin closed 9 years ago

vitalyrepin commented 9 years ago

When I try to use the picture tag I am constantly getting this error:

Liquid Exception: undefined method `[]' for nil:NilClass in _drafts/JekyllAnchors.md/#excerpt

Trace:

  Liquid Exception: undefined method `[]' for nil:NilClass in _drafts/JekyllAnchors.md/#excerpt
/home/vit/work/vrepinblog/_plugins/jekyll-picture-tag.rb:43:in `render': undefined method `[]' for nil:NilClass (NoMethodError)
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/block.rb:109:in `block in render_all'
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/block.rb:96:in `each'
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/block.rb:96:in `render_all'
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/block.rb:82:in `render'
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/template.rb:128:in `render'
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/template.rb:138:in `render!'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/convertible.rb:106:in `render_liquid'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/convertible.rb:233:in `do_layout'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/post.rb:258:in `render'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:298:in `block in render'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:297:in `each'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:297:in `render'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:51:in `process'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/command.rb:28:in `process_site'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:56:in `build'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:34:in `process'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `call'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `block in execute'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `each'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `execute'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary/program.rb:42:in `go'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary.rb:19:in `program'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/bin/jekyll:20:in `<top (required)>'
    from /usr/bin/jekyll:9:in `load'
    from /usr/bin/jekyll:9:in `<main>'

My source file has basically one line in the content section:

{% picture anchor.jpg %}

Jekyll version: 2.5.3

_config related to picture:

picture:
  source: "assets/imgs/_fullsize"
  output: "generated"
  markup: "picture"

I use redcarpet processor and re-define excerpt_separator.

btobolaski commented 9 years ago

I believe you need to define presets, so something like this:

picture:
  source: "assets/imgs/_fullsize"
  output: "generated"
  markup: "picture"
  presets:
    default:
      ppi: [1, 1.5]
    source_medium:
      media: "(min-width: 40em)"
      width: "600"
      height: "300"
    source_default: 
      width: "300"
vitalyrepin commented 9 years ago

I did it:

picture:
  source: "assets/imgs/_fullsize"
  output: "generated"
  markup: "picture"
  presets:
    default:
      ppi: [1, 1.5]
    source_medium:
      media: "(min-width: 40em)"
      width: "600"
      height: "300"
    source_default:
      width: "300"

Unfortunately the behavior is exactly the same:

$ jekyll b --drafts --trace
Configuration file: /home/vit/work/vrepinblog/_config.yml
            Source: /home/vit/work/vrepinblog
       Destination: /home/vit/work/vrepinblog/_site
      Generating... 
  Liquid Exception: undefined method `[]' for nil:NilClass in _drafts/JekyllAnchors.md/#excerpt
/home/vit/work/vrepinblog/_plugins/jekyll-picture-tag.rb:162:in `render': undefined method `[]' for nil:NilClass (NoMethodError)
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/block.rb:109:in `block in render_all'
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/block.rb:96:in `each'
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/block.rb:96:in `render_all'
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/block.rb:82:in `render'
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/template.rb:128:in `render'
    from /usr/lib64/ruby/gems/2.1.0/gems/liquid-2.6.2/lib/liquid/template.rb:138:in `render!'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/convertible.rb:106:in `render_liquid'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/convertible.rb:233:in `do_layout'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/post.rb:258:in `render'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:298:in `block in render'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:297:in `each'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:297:in `render'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:51:in `process'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/command.rb:28:in `process_site'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:56:in `build'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:34:in `process'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `call'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `block in execute'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `each'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `execute'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary/program.rb:42:in `go'
    from /usr/lib64/ruby/gems/2.1.0/gems/mercenary-0.3.5/lib/mercenary.rb:19:in `program'
    from /usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/bin/jekyll:20:in `<top (required)>'
    from /usr/bin/jekyll:9:in `load'
    from /usr/bin/jekyll:9:in `<main>'
btobolaski commented 9 years ago

You appear to be using a version of the plugin from before it was converted into a gem. I've looked through a few of the most recent commits and I couldn't find anything that would cause that stack trace. Could you try installing the gem and post an updated stack trace?

vitalyrepin commented 9 years ago

I just copied https://raw.githubusercontent.com/robwierzbowski/jekyll-picture-tag/master/lib/jekyll-picture-tag.rb to _plugins folder of my blog. Shall I install something else in addition to it?

I tried to switch to gems but everything stopped to work for me (not a problem with your plugin but something weird with Gentoo Jekyll setup). Can I somehow put your code to my setup without using gems?

paulc010 commented 9 years ago

I had the same error and it was because of the wrong indenting in config.yml: source_medium: should be indented to under ppi otherwise it's interpreted as a preset, not a property of the default preset (same goes for all the subsequent lines. It's a copy-paste thing.

vitalyrepin commented 9 years ago

Thank you! It was my case also.

Working config:

picture:
  source: "_assets/imgs/_fullsize"
  output: "generated"
  markup: "picture"
  presets:
    default:
      ppi: [1, 1.5]
      source_medium:
        media: "(min-width: 40em)"
        width: "600"
        height: "300"
      source_default:
        width: "300"