Module: Waves::Views::Mixin
Overview
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.
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(request) ⇒ Object
- #method_missing(name, *args) ⇒ Object
- #render(path, context = {}) ⇒ Object
-
#renderer(path) ⇒ Object
Return the first renderer for which a template file can be found.
Methods included from ResponseMixin
#blackboard, #controllers, #domain, #log, #models, #not_found, #params, #path, #redirect, #response, #session, #url, #views
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
102 103 104 |
# File 'lib/views/mixin.rb', line 102 def method_missing(name,*args) render( "/#{self.class.basename.snake_case}/#{name}", *args ) end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
72 73 74 |
# File 'lib/views/mixin.rb', line 72 def request @request end |
Class Method Details
.included(c) ⇒ Object
76 77 78 79 80 |
# File 'lib/views/mixin.rb', line 76 def self.included( c ) def c.process( request, *args, &block ) self.new( request ).instance_exec( *args, &block ) end end |
Instance Method Details
#initialize(request) ⇒ Object
82 83 84 85 |
# File 'lib/views/mixin.rb', line 82 def initialize( request ) @request = request @layout = :default end |
#render(path, context = {}) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/views/mixin.rb', line 95 def render( path, context = {} ) context.merge!( :request => request ) template = renderer( path ) || renderer( :generic / File.basename(path) ) raise NoTemplateError.new( path ) if template.nil? template.render( path, context ) end |
#renderer(path) ⇒ Object
Return the first renderer for which a template file can be found. Uses Renderers::Mixin.filename to construct the filename for each renderer.
89 90 91 92 93 |
# File 'lib/views/mixin.rb', line 89 def renderer(path) Views.renderers.find do |renderer| File.exists?( renderer.filename( path ) ) end end |