Module: Roda::RodaPlugins::Render::InstanceMethods
- Defined in:
- lib/roda/plugins/render.rb
Instance Method Summary collapse
-
#render(template, opts = OPTS, &block) ⇒ Object
Render the given template.
-
#render_opts ⇒ Object
Return the render options for the instance’s class.
-
#view(template, opts = OPTS) ⇒ Object
Render the given template.
Instance Method Details
#render(template, opts = OPTS, &block) ⇒ Object
Render the given template. See Render for details.
146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/roda/plugins/render.rb', line 146 def render(template, opts = OPTS, &block) opts = find_template(parse_template_opts(template, opts)) cached_template(opts) do template_opts = render_opts[:template_opts] current_template_opts = opts[:template_opts] if opts[:opts] && !current_template_opts RodaPlugins.deprecate("The render method :opts option is deprecated and will be removed in Roda 2. Switch to using the :template_opts option") current_template_opts = opts[:opts] end template_opts = template_opts.merge(current_template_opts) if current_template_opts opts[:template_class].new(opts[:path], 1, template_opts, &opts[:template_block]) end.render(self, (opts[:locals]||OPTS), &block) end |
#render_opts ⇒ Object
Return the render options for the instance’s class. While this is not currently frozen, it may be frozen in a future version, so you should not attempt to modify it.
163 164 165 |
# File 'lib/roda/plugins/render.rb', line 163 def render_opts self.class.render_opts end |
#view(template, opts = OPTS) ⇒ Object
Render the given template. If there is a default layout for the class, take the result of the template rendering and render it inside the layout. See Render for details.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/roda/plugins/render.rb', line 170 def view(template, opts=OPTS) opts = parse_template_opts(template, opts) content = opts[:content] || render(opts) if layout = opts.fetch(:layout, (OPTS if render_opts[:layout])) layout_opts = render_opts[:layout_opts] if opts[:layout_opts] layout_opts = opts[:layout_opts].merge(layout_opts) end content = render(layout, layout_opts){content} end content end |