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 481 481: def builder(template=nil, options={}, locals={}, &block) 482: options[:default_content_type] = :xml 483: render_ruby(:builder, template, options, locals, &block) 484: end
# File lib/sinatra/base.rb, line 510 510: def coffee(template, options={}, locals={}) 511: options.merge! :layout => false, :default_content_type => :js 512: render :coffee, template, options, locals 513: end
# File lib/sinatra/base.rb, line 454 454: def erb(template, options={}, locals={}) 455: render :erb, template, options, locals 456: end
# File lib/sinatra/base.rb, line 458 458: def erubis(template, options={}, locals={}) 459: render :erubis, template, options, locals 460: 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 526 526: def find_template(views, name, engine) 527: yield ::File.join(views, "#{name}.#{@preferred_extension}") 528: Tilt.mappings.each do |ext, engines| 529: next unless ext != @preferred_extension and Array(engines).include? engine 530: yield ::File.join(views, "#{name}.#{ext}") 531: end 532: end
# File lib/sinatra/base.rb, line 462 462: def haml(template, options={}, locals={}) 463: render :haml, template, options, locals 464: end
# File lib/sinatra/base.rb, line 476 476: def less(template, options={}, locals={}) 477: options.merge! :layout => false, :default_content_type => :css 478: render :less, template, options, locals 479: end
# File lib/sinatra/base.rb, line 486 486: def liquid(template, options={}, locals={}) 487: render :liquid, template, options, locals 488: end
# File lib/sinatra/base.rb, line 506 506: def markaby(template=nil, options={}, locals={}, &block) 507: render_ruby(:mab, template, options, locals, &block) 508: end
# File lib/sinatra/base.rb, line 490 490: def markdown(template, options={}, locals={}) 491: render :markdown, template, options, locals 492: end
# File lib/sinatra/base.rb, line 515 515: def nokogiri(template=nil, options={}, locals={}, &block) 516: options[:default_content_type] = :xml 517: render_ruby(:nokogiri, template, options, locals, &block) 518: end
# File lib/sinatra/base.rb, line 502 502: def radius(template, options={}, locals={}) 503: render :radius, template, options, locals 504: end
# File lib/sinatra/base.rb, line 498 498: def rdoc(template, options={}, locals={}) 499: render :rdoc, template, options, locals 500: end
# File lib/sinatra/base.rb, line 466 466: def sass(template, options={}, locals={}) 467: options.merge! :layout => false, :default_content_type => :css 468: render :sass, template, options, locals 469: end
# File lib/sinatra/base.rb, line 471 471: def scss(template, options={}, locals={}) 472: options.merge! :layout => false, :default_content_type => :css 473: render :scss, template, options, locals 474: end
# File lib/sinatra/base.rb, line 520 520: def slim(template, options={}, locals={}) 521: render :slim, template, options, locals 522: end