module Roda::RodaPlugins::Render::InstanceMethods

  1. lib/roda/plugins/render.rb

Methods

Public Instance

  1. render
  2. render_opts
  3. view

Public Instance methods

render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block)

Render the given template. See Render for details.

[show source]
    # File lib/roda/plugins/render.rb
620 def render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block)
621   if optimized_template
622     _call_optimized_template_method(optimized_template, OPTS, &block)
623   elsif !no_opts && opts.length == 1 && (locals = opts[:locals]) && (optimized_template = _optimized_render_method_for_locals(template, locals))
624     _call_optimized_template_method(optimized_template, locals, &block)
625   else
626     opts = render_template_opts(template, opts)
627     retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||OPTS), &block)
628   end
629 end
render_opts()

Return the render options for the instance’s class.

[show source]
    # File lib/roda/plugins/render.rb
632 def render_opts
633   self.class.render_opts
634 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
641 def view(template, opts = (content = _optimized_view_content(template) unless defined?(yield); OPTS), &block)
642   if content
643     # First, check if the optimized layout method has already been created,
644     # and use it if so.  This way avoids the extra conditional and local variable
645     # assignments in the next section.
646     if layout_method = _layout_method
647       return _call_optimized_template_method(layout_method, OPTS){content}
648     end
649 
650     # If we have an optimized template method but no optimized layout method, create the
651     # optimized layout method if possible and use it.  If you can't create the optimized
652     # layout method, fall through to the slower approach.
653     if layout_template = self.class.opts[:render][:optimize_layout]
654       retrieve_template(:template=>layout_template, :cache_key=>nil, :template_method_cache_key => :_roda_layout)
655       if layout_method = _layout_method
656         return _call_optimized_template_method(layout_method, OPTS){content}
657       end
658     end
659   else
660     opts = parse_template_opts(template, opts)
661     content = opts[:content] || render_template(opts, &block)
662   end
663 
664   if layout_opts  = view_layout_opts(opts)
665     content = render_template(layout_opts){content}
666   end
667 
668   content
669 end