want to specify in a page attribute the layout a page needs

19 views
Skip to first unread message

Tom Cloyd

unread,
Jun 14, 2020, 8:24:35 PM6/14/20
to nanoc
I have tried several things and get this error no matter what:


16:55:53 - ERROR - Compilation failed!

Captain! We’ve been hit!

ArgumentError: The layout passed to #layout must be a string

  0. /home/tomc/gems/gems/nanoc-4.11.17/lib/nanoc/rule_dsl/action_recorder.rb:28:in `layout'
  1. /home/tomc/gems/gems/nanoc-4.11.17/lib/nanoc/rule_dsl/compilation_rule_context.rb:45:in `layout'
  2. /home/tomc/Dropbox/www/__Active/BOCT/Rules:15:in `block in parse'
  3. /home/tomc/gems/gems/nanoc-4.11.17/lib/nanoc/rule_dsl/compilation_rule.rb:20:in `instance_exec'
  4. /home/tomc/gems/gems/nanoc-4.11.17/lib/nanoc/rule_dsl/compilation_rule.rb:20:in `apply_to'
  5. /home/tomc/gems/gems/nanoc-4.11.17/lib/nanoc/rule_dsl/action_sequence_calculator.rb:67:in `new_action_sequence_for_rep'
  6. /home/tomc/gems/gems/nanoc-4.11.17/lib/nanoc/rule_dsl/action_sequence_calculator.rb:47:in `[]'
  7. /home/tomc/gems/gems/nanoc-4.11.17/lib/nanoc/rule_dsl/action_provider.rb:38:in `action_sequence_for'
  8. /home/tomc/gems/gems/nanoc-core-4.11.17/lib/nanoc/core/item_rep_router.rb:39:in `block in run'
  9. /home/tomc/gems/gems/nanoc-core-4.11.17/lib/nanoc/core/item_rep_repo.rb:28:in `each'


 Here is the relevant page attribute:

page_layout: '/default.*'


Here is my rules file:

#!/usr/bin/env ruby

compile '/index.html' do
  filter :erb
#  layout '/default.*'
  layout :page_layout
  write '/index.html'
end

# gets 404 page and any other with html extent
compile '/*.html' do
  filter :kramdown
  filter :erb
#  layout '/default.*'
  layout :page_layout
  write item.identifier.without_ext + '/index.html'
end

# gets homepage
compile '/index.md' do
  filter :kramdown
#  layout '/default.*'
  layout :page_layout 
  write '/index.html'
end

# gets me "pretty URLs", per https://groups.google.com/forum/#!topic/nanoc/b3sXlleJxcA
compile '/*.md' do
  filter :kramdown
#  layout '/default.*'
  layout :page_layout
  write '/' + File.basename(item.identifier.without_ext) + '/index.html' # extent is stripped, then all but the file basename is stripped, leaving just the filename
end

# in the following, the /**/ IS necessary
compile '/**/*' do
  write item.identifier.to_s
end

layout '/**/*', :erb


This whole run is but a test, to see if I can use a page attribute in this way - specifying the layout right for a page on the page itself.

1. I don't see why this isn't working, unless my fundamental idea is flawed.

2. The Rules file has always made my head hurt. I am wondering if I need to do something with the last line. If so, I don't know what it might be.

3. Is there a better way to do this?

If all else fails, I think I could just use the page attribute that specifies a layout needed in a 'if' in Rules to pick the right layout. That seems a bit convoluted, but should work, yes?

Thanks for any and all help offered!

Tom

Thomas Hochstein

unread,
Jun 15, 2020, 1:19:01 AM6/15/20
to na...@googlegroups.com


Am 15. Juni 2020 02:24:35 MESZ schrieb Tom Cloyd <tomclo...@gmail.com>:

>> layout :page_layout

That should be "Item[:page_layout]', not just ':page_layout', In your Rules file.

-thh
Reply all
Reply to author
Forward
0 new messages