Module: Waves::Views::Mixin

Includes:
ResponseMixin
Included in:
Base
Defined in:
lib/views/mixin.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ResponseMixin

#app, #app_name, #attributes, #basename, #captured, #extension, #log, #model, #model_name, #params, #paths, #query, #redirect, #resource, #response, #traits

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.



53
# File 'lib/views/mixin.rb', line 53

def method_missing(name,*args) ; render( name, *args ) ; end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



28
29
30
# File 'lib/views/mixin.rb', line 28

def request
  @request
end

Class Method Details

.included(target) ⇒ Object



32
33
34
35
36
# File 'lib/views/mixin.rb', line 32

def self.included( target )
  def target.process( request, *args, &block )
    self.new( request ).instance_exec( *args, &block )
  end
end

Instance Method Details

#initialize(request) ⇒ Object



38
# File 'lib/views/mixin.rb', line 38

def initialize( request ) ; @request = request ; @layout = :default ; end

#render(path, 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>



46
47
48
49
50
# File 'lib/views/mixin.rb', line 46

def render( path, assigns = {} )
  qpath = "#{self.class.basename.snake_case}/#{path}"
  Waves.log.debug "Rendering template: #{qpath}"
  Views.render( :templates / qpath, assigns.merge!( :request => request ))
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.



42
# File 'lib/views/mixin.rb', line 42

def renderer(path) ; Views.renderer_for( :templates / path) ; end