Module: Roda::RodaPlugins::Render::InstanceMethods

Defined in:
lib/roda/plugins/render.rb

Instance Method Summary collapse

Instance Method Details

#render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block) ⇒ Object Also known as: render_template

Render the given template. See Render for details.



343
344
345
346
347
348
349
350
351
352
# File 'lib/roda/plugins/render.rb', line 343

def render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block)
  if optimized_template
    send(optimized_template, OPTS, &block)
  elsif !no_opts && opts.length == 1 && (locals = opts[:locals]) && (optimized_template = _optimized_render_method_for_locals(template, locals))
    send(optimized_template, locals, &block)
  else
    opts = render_template_opts(template, opts)
    retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||OPTS), &block)
  end
end

#render_optsObject

Return the render options for the instance’s class.



355
356
357
# File 'lib/roda/plugins/render.rb', line 355

def render_opts
  self.class.render_opts
end

#view(template, opts = (optimized_template = _cached_template_method(template); OPTS)) ⇒ Object

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. See Render for details.



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/roda/plugins/render.rb', line 362

def view(template, opts = (optimized_template = _cached_template_method(template); OPTS))
  if optimized_template
    content = send(optimized_template, OPTS)

    render_opts = self.class.opts[:render]
    if layout_template = render_opts[:optimize_layout]
      method_cache = render_opts[:template_method_cache]
      unless layout_method = method_cache[:_roda_layout]
        retrieve_template(:template=>layout_template, :cache_key=>nil, :template_method_cache_key => :_roda_layout)
        layout_method = method_cache[:_roda_layout]
      end

      if layout_method
        return send(layout_method, OPTS){content}
      end
    end
  else
    opts = parse_template_opts(template, opts)
    content = opts[:content] || render_template(opts)
  end

  if layout_opts  = view_layout_opts(opts)
    content = render_template(layout_opts){content}
  end

  content
end