Skip to content

Instantly share code, notes, and snippets.

@defunkt
Created March 6, 2010 06:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save defunkt/323534 to your computer and use it in GitHub Desktop.
Save defunkt/323534 to your computer and use it in GitHub Desktop.
how to do arguments in mustache.rb
require 'rubygems'
require 'mustache'
class HandleBar < Mustache
def respond_to?(methodname)
methodname = methodname.to_s.split(':').first
super methodname
end
def method_missing(methodname, *args)
methodname, args = methodname.to_s.split(/:\s*/)
args = [args].flatten.join.split(/,\s*/)
send methodname, *args
end
def wax_me *args
"you've been waxed! #{args.reverse.join(', ')}"
end
end
if $0 == __FILE__
h = HandleBar.new
h.template = "Mustache doesn't do arguments you say?\n\n{{wax_me: foo, bar, baz}}"
puts h.to_html
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment