Module: Innate::Helper::Render

Defined in:
lib/innate/helper/render.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(into) ⇒ Object

Enables you to simply call:

Examples:

of added functionality

YourController.render_partial(:foo, :x => 42)


9
10
11
# File 'lib/innate/helper/render.rb', line 9

def self.included(into)
  into.extend(self)
end

Instance Method Details

#render_custom(action_name, variables = {}) {|action| ... } ⇒ Object

Yields:

  • (action)


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/innate/helper/render.rb', line 63

def render_custom(action_name, variables = {})
  action = resolve(action_name.to_s)

  action.sync_variables(self.action)
  action.instance = action.node.new
  action.variables = action.variables.merge(variables)

  yield(action) if block_given?

  if action.valid?
    action.render
  else
    Log.warn("Invalid action: %p" % action)
  end
end

#render_full(path, query = {}) ⇒ Object

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.

See Also:



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/innate/helper/render.rb', line 26

def render_full(path, query = {})
  uri = URI(path.to_s)
  uri.query = Rack::Utils.build_query(query)

  if cookie = request.env['HTTP_COOKIE']
    Mock.session do |mock|
      mock.cookie = cookie
      return mock.get(uri.to_s).body
    end
  else
    Mock.get(uri.to_s).body
  end
end

#render_partial(action_name, variables = {}) ⇒ Object

Renders an action without any layout.

See Also:



44
45
46
47
48
# File 'lib/innate/helper/render.rb', line 44

def render_partial(action_name, variables = {})
  render_custom(action_name, variables) do |action|
    action.layout = nil
  end
end

#render_view(action_name, variables = {}) ⇒ Object

Renders an action view, doesn’t execute any methods and won’t wrap it into a layout.

See Also:



56
57
58
59
60
61
# File 'lib/innate/helper/render.rb', line 56

def render_view(action_name, variables = {})
  render_custom(action_name, variables) do |action|
    action.layout = nil
    action.method = nil
  end
end