Innate::Helper::Render

Public Class Methods

included(into) click to toggle source

Enables you to simply call:

@example of added functionality

  YourController.render_partial(:foo, :x => 42)
    # File lib/innate/helper/render.rb, line 8
 8:       def self.included(into)
 9:         into.extend(self)
10:       end

Public Instance Methods

render_custom(action_name, variables = {}) click to toggle source

@api internal @author manveru

     # File lib/innate/helper/render.rb, line 136
136:       def render_custom(action_name, variables = {})
137:         unless action = resolve(action_name.to_s, :needs_method => false)
138:           raise(ArgumentError, "No Action %p on #{self}" % [action_name])
139:         end
140: 
141:         action.sync_variables(self.action)
142:         action.instance = action.node.new
143:         action.variables = action.variables.merge(variables)
144: 
145:         yield(action) if block_given?
146: 
147:         valid_action = action.view || action.method
148:         Log.warn("Empty action: %p" % [action]) unless valid_action
149:         action.render
150:       end
render_file(filename, variables = {}) click to toggle source

Use the given file as a template and render it in the same scope as the current action. The filename may be an absolute path or relative to the process working directory.

@example usage

  path = '/home/manveru/example/app/todo/view/index.xhtml'
  render_file(path)
  render_file(path, :title => :foo)

Ramaze will emit a warning if you try to render an Action without a method or view template, but will still try to render it. The usual {Action#valid?} doesn’t apply here, as sometimes you just cannot have a method associated with a template.

@api external @see render_custom @author manveru

     # File lib/innate/helper/render.rb, line 118
118:       def render_file(filename, variables = {})
119:         action = Action.create(:view => filename)
120:         action.sync_variables(self.action)
121: 
122:         action.node      = self.class
123:         action.engine    = self.action.engine
124:         action.instance  = action.node.new
125:         action.variables.merge!(variables)
126: 
127:         yield(action) if block_given?
128: 
129:         valid_action = action.view || action.method
130:         Log.warn("Empty action: %p" % [action]) unless valid_action
131:         action.render
132:       end
render_full(path, query = {}) click to toggle source

Renders the full action in the way a real request would.

Please be aware that, if this is the first request from a client, you will not have access to the session in the action being rendered, as no actual session has been put into place yet.

It should work as expected on any subsequent requests.

As usual, patches welcome.

@example usage

  render_full('/blog/article/1')
  render_full('/blog/article/1', :lang => :de)

Please note that you have to give the full path in the same way you’d do in a direct request with curl or a browser.

@api external @see Mock.session @author manveru

    # File lib/innate/helper/render.rb, line 33
33:       def render_full(path, query = {})
34:         uri = URI(path.to_s)
35:         uri.query = Rack::Utils.build_query(query)
36: 
37:         if cookie = request.env['HTTP_COOKIE']
38:           Mock.session do |mock|
39:             mock.cookie = cookie
40:             return mock.get(uri.to_s).body
41:           end
42:         else
43:           Mock.get(uri.to_s).body
44:         end
45:       end
render_partial(action_name, variables = {}) click to toggle source

Renders an action without any layout. You can further tweak the action to be rendered by passing a block.

@example usage

  render_partial(:index)
  render_partial(:index, :title => :foo)

Please note that you only have to supply the action name, if your action requires arguments then you have to pass a name suitable for that.

@example usage with action that requires arguments

  # requires two arguments
  def foo(a, b)
  end

  # pass two suitable arguments
  render_partial('foo/1/2')

@api external @see render_custom @author manveru

    # File lib/innate/helper/render.rb, line 71
71:       def render_partial(action_name, variables = {})
72:         render_custom(action_name, variables) do |action|
73:           action.layout = nil
74:           yield(action) if block_given?
75:         end
76:       end
render_view(action_name, variables = {}) click to toggle source

Renders an action view and does not execute any methods. The rendered view will not be wrapped in a layout and instead will use the layout of the current action. You can further tweak the action to be rendered by passing a block.

@example usage

  render_view(:index)
  render_view(:index, :title => :foo)

@api external @see render_custom @author manveru

    # File lib/innate/helper/render.rb, line 91
91:       def render_view(action_name, variables = {})
92:         render_custom(action_name, variables) do |action|
93:           action.layout = nil
94:           action.method = nil
95:           yield(action) if block_given?
96:         end
97:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.