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