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 617 def render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block) 618 if optimized_template 619 _call_optimized_template_method(optimized_template, OPTS, &block) 620 elsif !no_opts && opts.length == 1 && (locals = opts[:locals]) && (optimized_template = _optimized_render_method_for_locals(template, locals)) 621 _call_optimized_template_method(optimized_template, locals, &block) 622 else 623 opts = render_template_opts(template, opts) 624 retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||OPTS), &block) 625 end 626 end
render_opts()
Return the render options for the instance’s class.
[show source]
# File lib/roda/plugins/render.rb 629 def render_opts 630 self.class.render_opts 631 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 638 def view(template, opts = (content = _optimized_view_content(template) unless defined?(yield); OPTS), &block) 639 if content 640 # First, check if the optimized layout method has already been created, 641 # and use it if so. This way avoids the extra conditional and local variable 642 # assignments in the next section. 643 if layout_method = _layout_method 644 return _call_optimized_template_method(layout_method, OPTS){content} 645 end 646 647 # If we have an optimized template method but no optimized layout method, create the 648 # optimized layout method if possible and use it. If you can't create the optimized 649 # layout method, fall through to the slower approach. 650 if layout_template = self.class.render_opts[:optimize_layout] 651 retrieve_template(:template=>layout_template, :cache_key=>nil, :template_method_cache_key => :_roda_layout) 652 if layout_method = _layout_method 653 return _call_optimized_template_method(layout_method, OPTS){content} 654 end 655 end 656 else 657 opts = parse_template_opts(template, opts) 658 content = opts[:content] || render_template(opts, &block) 659 end 660 661 if layout_opts = view_layout_opts(opts) 662 content = render_template(layout_opts){content} 663 end 664 665 content 666 end