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
608 def render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block)
609   if optimized_template
610     _call_optimized_template_method(optimized_template, OPTS, &block)
611   elsif !no_opts && opts.length == 1 && (locals = opts[:locals]) && (optimized_template = _optimized_render_method_for_locals(template, locals))
612     _call_optimized_template_method(optimized_template, locals, &block)
613   else
614     opts = render_template_opts(template, opts)
615     retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||OPTS), &block)
616   end
617 end
render_opts()

Return the render options for the instance’s class.

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