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
510 def render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block)
511   if optimized_template
512     send(optimized_template, OPTS, &block)
513   elsif !no_opts && opts.length == 1 && (locals = opts[:locals]) && (optimized_template = _optimized_render_method_for_locals(template, locals))
514     send(optimized_template, locals, &block)
515   else
516     opts = render_template_opts(template, opts)
517     retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||OPTS), &block)
518   end
519 end
render_opts()

Return the render options for the instance’s class.

[show source]
    # File lib/roda/plugins/render.rb
522 def render_opts
523   self.class.render_opts
524 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
531 def view(template, opts = (content = _optimized_view_content(template) unless defined?(yield); OPTS), &block)
532   if content
533     # First, check if the optimized layout method has already been created,
534     # and use it if so.  This way avoids the extra conditional and local variable
535     # assignments in the next section.
536     if layout_method = _layout_method
537       return send(layout_method, OPTS){content}
538     end
539 
540     # If we have an optimized template method but no optimized layout method, create the
541     # optimized layout method if possible and use it.  If you can't create the optimized
542     # layout method, fall through to the slower approach.
543     if layout_template = self.class.opts[:render][:optimize_layout]
544       retrieve_template(:template=>layout_template, :cache_key=>nil, :template_method_cache_key => :_roda_layout)
545       if layout_method = _layout_method
546         return send(layout_method, OPTS){content}
547       end
548     end
549   else
550     opts = parse_template_opts(template, opts)
551     content = opts[:content] || render_template(opts, &block)
552   end
553 
554   if layout_opts  = view_layout_opts(opts)
555     content = render_template(layout_opts){content}
556   end
557 
558   content
559 end