Skip to content

Instantly share code, notes, and snippets.

@denisdefreyne
Last active December 30, 2015 06:29
Show Gist options
  • Save denisdefreyne/7789295 to your computer and use it in GitHub Desktop.
Save denisdefreyne/7789295 to your computer and use it in GitHub Desktop.
Mustache + nanoc requirements

Goal: excellent Mustache support in nanoc

Need alternatives for:

  • <%= item[:blah] %>{{ item:blah }}
  • <%= item.path %>{{ item.path }}
  • <%= layout[:blah] %>{{ layout:blah }}
  • <%= config[:blah] %>{{ config:blah }}
  • <%= some_helper(…) %> → ???
  • <% some_helper(…) do %>…<% end %> → ???

Maybe these (not sure whether these are necessary in logicless templates):

  • <%= @items['/some/item/'][:blah] %> → ???
  • <%= @items['/some/item/'].path %> (and compiled_content etc) → ???

Conventions used here:

  • {{ item:blah }}: access attribute :blah in current item (totally not sure whether I like the :)
  • {{ item.path }}: call “method” path on current item (not really a method call, because you won’t be able to just call any method)
@denisdefreyne
Copy link
Author

Some ideas on accessing “custom” (e.g. :title) vs “built-in” attributes (e.g. path):

  • {{ item.:title }} and {{ item.path }}
  • {{ item.meta.title }} and {{ item.path }}
  • {{ item.attr.title }} and {{ item.path }}

@jugglinmike
Copy link

It looks like defunkt/mustache already performs string -> symbol mapping. Example

require 'mustache'

context = {
    'item' => {
        'string' => 'string key',
        :symbol => 'symbol key',
        'both' => 'string key',
        :both => 'symbol key'
    }
}

puts Mustache.render(".string\t{{item.string}}", context)
puts Mustache.render(".symbol\t{{item.symbol}}", context)
puts Mustache.render(".both\t{{item.both}}", context)

...outputs:

.string string key
.symbol symbol key
.both   symbol key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment