Module: Innate::Helper::Render
- Defined in:
- innate/lib/innate/helper/render.rb
Class Method Summary
- + (Object) included(into) Enables you to simply call:.
Instance Method Summary
- - (Object) render_custom(action_name, variables = {}) {|action| ... }
- - (Object) render_file(filename, variables = {}) {|action| ... } Use the given file as a template and render it in the same scope as the current action.
- - (Object) render_full(path, query = {}) Renders the full action in the way a real request would.
- - (Object) render_partial(action_name, variables = {}) Renders an action without any layout.
- - (Object) render_view(action_name, variables = {}) Renders an action view, doesn’t execute any methods and won’t wrap it into a layout.
Class Method Details
+ (Object) included(into)
Enables you to simply call:
8 9 10 |
# File 'innate/lib/innate/helper/render.rb', line 8 def self.included(into) into.extend(self) end |
Instance Method Details
- (Object) render_custom(action_name, variables = {}) {|action| ... }
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'innate/lib/innate/helper/render.rb', line 135 def render_custom(action_name, variables = {}) unless action = resolve(action_name.to_s) raise(ArgumentError, "No Action %p on #{self}" % [action_name]) end action.sync_variables(self.action) action.instance = action.node.new action.variables = action.variables.merge(variables) yield(action) if block_given? valid_action = action.view || action.method Log.warn("Empty action: %p" % [action]) unless valid_action action.render end |
- (Object) render_file(filename, variables = {}) {|action| ... }
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.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'innate/lib/innate/helper/render.rb', line 117 def render_file(filename, variables = {}) action = Action.create(:view => filename) action.sync_variables(self.action) action.node = self.class action.engine = self.action.engine action.instance = action.node.new action.variables.merge!(variables) yield(action) if block_given? valid_action = action.view || action.method Log.warn("Empty action: %p" % [action]) unless valid_action action.render end |
- (Object) render_full(path, query = {})
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.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'innate/lib/innate/helper/render.rb', line 33 def render_full(path, query = {}) uri = URI(path.to_s) uri.query = Rack::Utils.build_query(query) if = request.env['HTTP_COOKIE'] Mock.session do |mock| mock. = return mock.get(uri.to_s).body end else Mock.get(uri.to_s).body end end |
- (Object) render_partial(action_name, variables = {})
Renders an action without any layout. You can further tweak the action to be rendered by passing a block.
71 72 73 74 75 76 |
# File 'innate/lib/innate/helper/render.rb', line 71 def render_partial(action_name, variables = {}) render_custom(action_name, variables) do |action| action.layout = nil yield(action) if block_given? end end |
- (Object) render_view(action_name, variables = {})
Renders an action view, doesn’t execute any methods and won’t wrap it into a layout. You can further tweak the action to be rendered by passing a block.
90 91 92 93 94 95 96 |
# File 'innate/lib/innate/helper/render.rb', line 90 def render_view(action_name, variables = {}) render_custom(action_name, variables) do |action| action.layout = nil action.method = nil yield(action) if block_given? end end |