0
@@ -55,18 +55,27 @@ module Waves
0
- class NoTemplateError < Exception ; end
0
# A class method that returns the known Renderers, which is any module that is defined within Waves::Renderers and includes the Renderers::Mixin. You can define new Renderers simply be reopening Waves::Renderers and defining a module that mixes in Renderers::Mixin.
0
- return [] if Renderers.constants.nil?
0
- Renderers.constants.sort.inject([]) do |rx,cname|
0
- ( Module === (c=Renderers.const_get(cname)) &&
0
- c < Renderers::Mixin ) ? ( rx << c ) : rx
0
+ def self.renderer_for(path)
0
+ @renderers.find do |renderer|
0
+ File.exists?( renderer.filename( path ) )
0
+ def self.render( path, assigns = {} )
0
+ template = Views.renderer_for(path) || Views.renderer_for( :generic / File.basename(path) )
0
+ raise NoTemplateError.new( path ) if template.nil?
0
+ template.render( path, assigns )
0
- # The View mixin simply sets up the machinery for invoking a template, along with methods for accessing the request context and the standard interface for invoking a view method.
0
+ class NoTemplateError < Exception # :nodoc:
0
+ # The View mixin simply sets up the machinery for invoking a template, along with methods for accessing the request assigns and the standard interface for invoking a view method.
0
@@ -87,25 +96,24 @@ module Waves
0
# Return the first renderer for which a template file can be found.
0
# Uses Renderers::Mixin.filename to construct the filename for each renderer.
0
- Views.renderers.find do |renderer|
0
- File.exists?( renderer.filename( path ) )
0
+ Views.renderer_for(path)
0
- def render( path, context = {} )
0
- context.merge!( :request => request )
0
- template = renderer( path ) || renderer( :generic / File.basename(path) )
0
- raise NoTemplateError.new( path ) if template.nil?
0
- template.render( path, context )
0
+ # Render the template found in the directory named after this view (snake cased, of course)
0
+ # E.g. App::Views::Gnome.new.render( "stink" ) would look for templates/gnome/stink.<ext>
0
+ def render( path, assigns = {} )
0
+ Views.render("#{self.class.basename.snake_case}/#{path}", assigns.merge!( :request => request ))
0
+ # Render the template with the name of the missing method.
0
def method_missing(name,*args)
0
- render(
"/#{self.class.basename.snake_case}/#{name}", *args )
0
+ # An emoticon means never having to say you're sorry.
0
const_set( :Base, Class.new ).module_eval { include Mixin }
Comments
No one has commented yet.