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 493 def render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block) 494 if optimized_template 495 send(optimized_template, OPTS, &block) 496 elsif !no_opts && opts.length == 1 && (locals = opts[:locals]) && (optimized_template = _optimized_render_method_for_locals(template, locals)) 497 send(optimized_template, locals, &block) 498 else 499 opts = render_template_opts(template, opts) 500 retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||OPTS), &block) 501 end 502 end
render_opts()
Return the render options for the instance’s class.
[show source]
# File lib/roda/plugins/render.rb 505 def render_opts 506 self.class.render_opts 507 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 514 def view(template, opts = (content = _optimized_view_content(template) unless defined?(yield); OPTS), &block) 515 if content 516 # First, check if the optimized layout method has already been created, 517 # and use it if so. This way avoids the extra conditional and local variable 518 # assignments in the next section. 519 if layout_method = _layout_method 520 return send(layout_method, OPTS){content} 521 end 522 523 # If we have an optimized template method but no optimized layout method, create the 524 # optimized layout method if possible and use it. If you can't create the optimized 525 # layout method, fall through to the slower approach. 526 if layout_template = self.class.opts[:render][:optimize_layout] 527 retrieve_template(:template=>layout_template, :cache_key=>nil, :template_method_cache_key => :_roda_layout) 528 if layout_method = _layout_method 529 return send(layout_method, OPTS){content} 530 end 531 end 532 else 533 opts = parse_template_opts(template, opts) 534 content = opts[:content] || render_template(opts, &block) 535 end 536 537 if layout_opts = view_layout_opts(opts) 538 content = render_template(layout_opts){content} 539 end 540 541 content 542 end