Module: Waves::Views::Templated
- Defined in:
- lib/waves/views/templated.rb
Instance Method Summary collapse
-
#method_missing(name, *args) ⇒ Object
Render the template with the name of the missing method.
-
#render(name, assigns = {}) ⇒ Object
Render the template found in the directory named after this view (snake cased, of course) E.g.
- #template_file(name) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Render the template with the name of the missing method. E.g. App::Views::Gnome.new.stink would look for templates/gnome/stink
33 |
# File 'lib/waves/views/templated.rb', line 33 def method_missing(name,*args) ; render( name, *args ) ; end |
Instance Method Details
#render(name, assigns = {}) ⇒ Object
Render the template found in the directory named after this view (snake cased, of course) E.g. App::Views::Gnome.new.render( “stink” ) would look for templates/gnome/stink.<ext>
24 25 26 27 28 29 |
# File 'lib/waves/views/templated.rb', line 24 def render( name, assigns={}) file = template_file(name) ext = File.extname(file).slice(1..-1) Waves.log.debug "Rendering: #{file}" self.send( ext, File.read(file), assigns.merge!( :request => request )) end |
#template_file(name) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/waves/views/templated.rb', line 13 def template_file(name) template = "templates/#{self.class.basename.snake_case}/#{name}" extensions = Views.extensions.join(',') # globbing on a {x,y,z} group returns the found files in x,y,z order raise NoTemplateError.new( path ) unless file = Dir["#{template}.{#{extensions}}"].first file end |