avillafiorita / jekyll-datapage_gen

Generate one page per yaml record in Jekyll sites.
369 stars 80 forks source link

NoMethodError: undefined method `tr' for nil:NilClass #53

Closed olea closed 5 years ago

olea commented 5 years ago

Hi:

First all thankyou very much for your plugin. It could solve exactly the problem for my project.

I'm using your last plugin version at the repo. I verified your example runs in my system but when using in my project I got this error:

$ bundle exec jekyll serve --trace
Configuration file: /home/olea/13framework-TFG/webo-29110/_config.yml
            Source: /home/olea/13framework-TFG/webo-29110
       Destination: /home/olea/13framework-TFG/webo-29110/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
bundler: failed to load command: jekyll (/home/olea/.gem/bin/jekyll)
NoMethodError: undefined method `tr' for nil:NilClass
  /home/olea/13framework-TFG/webo-29110/_plugins/data_page_generator.rb:14:in `sanitize_filename'
  /home/olea/13framework-TFG/webo-29110/_plugins/data_page_generator.rb:42:in `initialize'
  /home/olea/13framework-TFG/webo-29110/_plugins/data_page_generator.rb:98:in `new'
  /home/olea/13framework-TFG/webo-29110/_plugins/data_page_generator.rb:98:in `block (2 levels) in generate'
  /home/olea/13framework-TFG/webo-29110/_plugins/data_page_generator.rb:97:in `each'
  /home/olea/13framework-TFG/webo-29110/_plugins/data_page_generator.rb:97:in `block in generate'
  /home/olea/13framework-TFG/webo-29110/_plugins/data_page_generator.rb:72:in `each'
  /home/olea/13framework-TFG/webo-29110/_plugins/data_page_generator.rb:72:in `generate'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/site.rb:175:in `block in generate'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/site.rb:173:in `each'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/site.rb:173:in `generate'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/site.rb:70:in `process'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/command.rb:28:in `process_site'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/commands/build.rb:65:in `build'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/commands/build.rb:36:in `process'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/commands/serve.rb:93:in `block in start'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/commands/serve.rb:93:in `each'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/commands/serve.rb:93:in `start'
  /home/olea/.gem/gems/jekyll-3.8.4/lib/jekyll/commands/serve.rb:75:in `block (2 levels) in init_with_program'
  /home/olea/.gem/ruby/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
  /home/olea/.gem/ruby/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
  /home/olea/.gem/ruby/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
  /home/olea/.gem/ruby/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
  /home/olea/.gem/ruby/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
  /home/olea/.gem/gems/jekyll-3.8.4/exe/jekyll:15:in `<top (required)>'
  /home/olea/.gem/bin/jekyll:23:in `load'
  /home/olea/.gem/bin/jekyll:23:in `<top (required)>

Enviroment:

$ bundle exec jekyll --version; bundle exec  ruby --version
jekyll 3.8.4
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

After several tries I discarded a plugin or configuration conflict. Or a bug in my layout. My main suspect is the _data/29110.csv file, but I can't really diagnose what the problem is. Things I know:

I ran out of ideas and don't know ruby so I can't deep investigating-

Any suggestion? Thanks in advance.

PS: If you want to check my project you can download it: http://olea.org/tmp/webo-29110.zip

avillafiorita commented 5 years ago

Hi, thanks for your report!

The tr function sanitizes the value of the field used to generated the filename for the record being processed.

There are two possible explanations for the error you are experiencing:

  1. the configuration file does not reference a field of your data (double check the value of the name field in _config.yml)
  2. one record in your data has an empty value for the field used to generate the page title (make sure all records have a non-empty value for the field you have chosen to generate the page title).

Having said that, the plugin might be a bit more informative about what is going on. Added to the todo list!

Let me know if it fixes your issue!

avillafiorita commented 5 years ago

I have pushed a new version which complains about the records which would cause tr to fail.

Give it a try, it might be simpler than checking the data files by hand.

olea commented 5 years ago

Thanks!

It's amazing!

BTW: how do you generate the name of each file? Seems you are not using neither slugify or url_encoder, so it would be needed to add code to for correct cross references :-m

olea commented 5 years ago

BTW: how do you generate the name of each file? Seems you are not using neither slugify or url_encoder, so it would be needed to add code to for correct cross references :-m

I've learned the plugin provides datapage_url to get this info. I would suggest to use slugify for creation of the file names giving more flexibility for developers.

Again, thankyou very much. I'm advancing in my development. Definitively this plugin deserves to be published as a gem!