Created
May 18, 2010 01:19
-
-
Save defunkt/404480 to your computer and use it in GitHub Desktop.
Section separators in mustache.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mustache' | |
require 'yaml' | |
class Sep < Mustache | |
def last? | |
self[:to_s] == self[:names].last.to_s | |
end | |
end | |
template = <<template | |
Gem Names: | |
* {{#names}}{{to_s}}{{^last?}}{{separator}}{{/last?}}{{/names}}{{! hack}} | |
* {{#names}}{{to_s}}{{^last?}}, {{/last?}}{{/names}}{{! hack}} | |
template | |
data = YAML.load(<<yaml) | |
names: [ mustache, sinatra, rack] | |
separator: " - " | |
yaml | |
puts Sep.render(template, data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby sep.rb | |
Gem Names: | |
* mustache - sinatra - rack | |
* mustache, sinatra, rack |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment