Module: Roda::RodaPlugins::Render::InstanceMethods
- Defined in:
- lib/roda/plugins/render.rb
Instance Method Summary collapse
-
#render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block) ⇒ Object
(also: #render_template)
Render the given template.
-
#render_opts ⇒ Object
Return the render options for the instance’s class.
-
#view(template, opts = (yield); OPTS), &block) ⇒ Object
Render the given template.
Instance Method Details
#render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block) ⇒ Object Also known as: render_template
Render the given template. See Render for details.
591 592 593 594 595 596 597 598 599 600 |
# File 'lib/roda/plugins/render.rb', line 591 def render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block) if optimized_template _call_optimized_template_method(optimized_template, OPTS, &block) elsif !no_opts && opts.length == 1 && (locals = opts[:locals]) && (optimized_template = _optimized_render_method_for_locals(template, locals)) _call_optimized_template_method(optimized_template, locals, &block) else opts = render_template_opts(template, opts) retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||OPTS), &block) end end |
#render_opts ⇒ Object
Return the render options for the instance’s class.
603 604 605 |
# File 'lib/roda/plugins/render.rb', line 603 def render_opts self.class.render_opts end |
#view(template, opts = (yield); OPTS), &block) ⇒ 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. Blocks passed to view are passed to render when rendering the template. See Render for details.
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 |
# File 'lib/roda/plugins/render.rb', line 612 def view(template, opts = (content = _optimized_view_content(template) unless defined?(yield); OPTS), &block) if content # First, check if the optimized layout method has already been created, # and use it if so. This way avoids the extra conditional and local variable # assignments in the next section. if layout_method = _layout_method return _call_optimized_template_method(layout_method, OPTS){content} end # If we have an optimized template method but no optimized layout method, create the # optimized layout method if possible and use it. If you can't create the optimized # layout method, fall through to the slower approach. if layout_template = self.class.opts[:render][:optimize_layout] retrieve_template(:template=>layout_template, :cache_key=>nil, :template_method_cache_key => :_roda_layout) if layout_method = _layout_method return _call_optimized_template_method(layout_method, OPTS){content} end end else opts = parse_template_opts(template, opts) content = opts[:content] || render_template(opts, &block) end if layout_opts = view_layout_opts(opts) content = render_template(layout_opts){content} end content end |