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