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.

Methods

builder   coffee   erb   erubis   find_template   haml   less   liquid   markaby   markdown   nokogiri   radius   rdoc   sass   scss   slim   textile  

Classes and Modules

Module Sinatra::Templates::ContentTyped

Public Instance methods

[Source]

     # File lib/sinatra/base.rb, line 485
485:     def builder(template=nil, options={}, locals={}, &block)
486:       options[:default_content_type] = :xml
487:       render_ruby(:builder, template, options, locals, &block)
488:     end

[Source]

     # File lib/sinatra/base.rb, line 514
514:     def coffee(template, options={}, locals={})
515:       options.merge! :layout => false, :default_content_type => :js
516:       render :coffee, template, options, locals
517:     end

[Source]

     # File lib/sinatra/base.rb, line 458
458:     def erb(template, options={}, locals={})
459:       render :erb, template, options, locals
460:     end

[Source]

     # File lib/sinatra/base.rb, line 462
462:     def erubis(template, options={}, locals={})
463:       render :erubis, template, options, locals
464:     end

Calls the given block for every possible template file in views, named name.ext, where ext is registered on engine.

[Source]

     # File lib/sinatra/base.rb, line 530
530:     def find_template(views, name, engine)
531:       yield ::File.join(views, "#{name}.#{@preferred_extension}")
532:       Tilt.mappings.each do |ext, engines|
533:         next unless ext != @preferred_extension and Array(engines).include? engine
534:         yield ::File.join(views, "#{name}.#{ext}")
535:       end
536:     end

[Source]

     # File lib/sinatra/base.rb, line 466
466:     def haml(template, options={}, locals={})
467:       render :haml, template, options, locals
468:     end

[Source]

     # File lib/sinatra/base.rb, line 480
480:     def less(template, options={}, locals={})
481:       options.merge! :layout => false, :default_content_type => :css
482:       render :less, template, options, locals
483:     end

[Source]

     # File lib/sinatra/base.rb, line 490
490:     def liquid(template, options={}, locals={})
491:       render :liquid, template, options, locals
492:     end

[Source]

     # File lib/sinatra/base.rb, line 510
510:     def markaby(template=nil, options={}, locals={}, &block)
511:       render_ruby(:mab, template, options, locals, &block)
512:     end

[Source]

     # File lib/sinatra/base.rb, line 494
494:     def markdown(template, options={}, locals={})
495:       render :markdown, template, options, locals
496:     end

[Source]

     # File lib/sinatra/base.rb, line 519
519:     def nokogiri(template=nil, options={}, locals={}, &block)
520:       options[:default_content_type] = :xml
521:       render_ruby(:nokogiri, template, options, locals, &block)
522:     end

[Source]

     # File lib/sinatra/base.rb, line 506
506:     def radius(template, options={}, locals={})
507:       render :radius, template, options, locals
508:     end

[Source]

     # File lib/sinatra/base.rb, line 502
502:     def rdoc(template, options={}, locals={})
503:       render :rdoc, template, options, locals
504:     end

[Source]

     # File lib/sinatra/base.rb, line 470
470:     def sass(template, options={}, locals={})
471:       options.merge! :layout => false, :default_content_type => :css
472:       render :sass, template, options, locals
473:     end

[Source]

     # File lib/sinatra/base.rb, line 475
475:     def scss(template, options={}, locals={})
476:       options.merge! :layout => false, :default_content_type => :css
477:       render :scss, template, options, locals
478:     end

[Source]

     # File lib/sinatra/base.rb, line 524
524:     def slim(template, options={}, locals={})
525:       render :slim, template, options, locals
526:     end

[Source]

     # File lib/sinatra/base.rb, line 498
498:     def textile(template, options={}, locals={})
499:       render :textile, template, options, locals
500:     end

[Validate]