| Module | Sinatra::Templates |
| In: |
lib/sinatra/base.rb
|
Template rendering methods. Each method takes the name of a template to render as a Symbol and returns a String with the rendered output, as well as an optional hash with additional options.
`template` is either the name or path of the template as symbol (Use `:’subdir/myview’` for views in subdirectories), or a string that will be rendered.
Possible options are:
:content_type The content type to use, same arguments as content_type.
:layout If set to false, no layout is rendered, otherwise
the specified layout is used (Ignored for `sass` and `less`)
:layout_engine Engine to use for rendering the layout.
:locals A hash with local variables that should be available
in the template
:scope If set, template is evaluate with the binding of the given
object rather than the application instance.
:views Views directory to use.
# File lib/sinatra/base.rb, line 458
458: def builder(template=nil, options={}, locals={}, &block)
459: options[:default_content_type] = :xml
460: render_ruby(:builder, template, options, locals, &block)
461: end
# File lib/sinatra/base.rb, line 487
487: def coffee(template, options={}, locals={})
488: options.merge! :layout => false, :default_content_type => :js
489: render :coffee, template, options, locals
490: end
# File lib/sinatra/base.rb, line 431
431: def erb(template, options={}, locals={})
432: render :erb, template, options, locals
433: end
# File lib/sinatra/base.rb, line 435
435: def erubis(template, options={}, locals={})
436: render :erubis, template, options, locals
437: end
Calls the given block for every possible template file in views, named name.ext, where ext is registered on engine.
# File lib/sinatra/base.rb, line 503
503: def find_template(views, name, engine)
504: Tilt.mappings.each do |ext, klass|
505: next unless klass == engine
506: yield ::File.join(views, "#{name}.#{ext}")
507: end
508: end
# File lib/sinatra/base.rb, line 439
439: def haml(template, options={}, locals={})
440: render :haml, template, options, locals
441: end
# File lib/sinatra/base.rb, line 453
453: def less(template, options={}, locals={})
454: options.merge! :layout => false, :default_content_type => :css
455: render :less, template, options, locals
456: end
# File lib/sinatra/base.rb, line 463
463: def liquid(template, options={}, locals={})
464: render :liquid, template, options, locals
465: end
# File lib/sinatra/base.rb, line 483
483: def markaby(template=nil, options={}, locals={}, &block)
484: render_ruby(:mab, template, options, locals, &block)
485: end
# File lib/sinatra/base.rb, line 467
467: def markdown(template, options={}, locals={})
468: render :markdown, template, options, locals
469: end
# File lib/sinatra/base.rb, line 492
492: def nokogiri(template=nil, options={}, locals={}, &block)
493: options[:default_content_type] = :xml
494: render_ruby(:nokogiri, template, options, locals, &block)
495: end
# File lib/sinatra/base.rb, line 479
479: def radius(template, options={}, locals={})
480: render :radius, template, options, locals
481: end
# File lib/sinatra/base.rb, line 475
475: def rdoc(template, options={}, locals={})
476: render :rdoc, template, options, locals
477: end
# File lib/sinatra/base.rb, line 443
443: def sass(template, options={}, locals={})
444: options.merge! :layout => false, :default_content_type => :css
445: render :sass, template, options, locals
446: end
# File lib/sinatra/base.rb, line 448
448: def scss(template, options={}, locals={})
449: options.merge! :layout => false, :default_content_type => :css
450: render :scss, template, options, locals
451: end
# File lib/sinatra/base.rb, line 497
497: def slim(template, options={}, locals={})
498: render :slim, template, options, locals
499: end