Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'mustache'
- module ExistentialMethodMissing
- def method_missing(method, *args)
- return super unless method.to_s =~ /\?$/
- val = send(method.to_s.chomp('?'))
- val.respond_to?(:empty?) ? !val.empty? : !!val
- end
- def respond_to?(method)
- super method.to_s.chomp('?')
- end
- end
- class MyView < Mustache
- include ExistentialMethodMissing
- self.template = <<template
- {{# people?}}
- <ul>
- {{# people}}
- <li>{{ name }}</li>
- {{/ people}}
- </ul>
- {{/ people?}}
- template
- def people
- return [
- { :name => "Chris" },
- { :name => "Bob" },
- { :name => "Mislav" }
- ]
- end
- end
- puts MyView.render
Add Comment
Please, Sign In to add comment