Module: Sinatra::Effigy::Helpers
- Defined in:
- lib/sinatra/effigy.rb
Instance Method Summary collapse
Instance Method Details
#effigy(name, *locals) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sinatra/effigy.rb', line 7 def effigy(name, *locals) view_file = "#{.views}/#{name}.rb" template_file = "#{.templates}/#{name}.html" if File.exists?(view_file) camel_name = "#{name}_view". gsub(' ', '_'). gsub(/\/(.)/) { "::#{$1.upcase}" }. gsub(/(?:^|_)(.)/) { $1.upcase } view = Object.const_get(camel_name).new(*locals) template = File.read(template_file) view.render(template) else File.read(template_file) end end |