Module Sinatra::Sass

  1. lib/sinatra.rb

Generate valid CSS using Sass (part of Haml)

Sass templates can be in external files with .sass extension or can use Sinatra’s in_file_templates. In either case, the file can be rendered by passing the name of the template to the sass method as a symbol.

Unlike Haml, Sass does not support a layout file, so the sass method will ignore both the default layout.sass file and any parameters passed in as :layout in the options hash.

Sass Template Files

Sass templates can be stored in separate files with a .sass extension under the view path.

Example:

get '/stylesheet.css' do
  header 'Content-Type' => 'text/css; charset=utf-8'
  sass :stylesheet
end

The “views/stylesheet.sass“ file might contain the following:

body
  #admin
    :background-color #CCC
  #main
    :background-color #000
#form
  :border-color #AAA
  :border-width 10px

And yields the following output:

body #admin {
  background-color: #CCC; }
body #main {
  background-color: #000; }

#form {
  border-color: #AAA;
  border-width: 10px; }

NOTE: Haml must be installed or a LoadError will be raised the first time an attempt is made to render a Sass template.

See haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html for comprehensive documentation on Sass.

Methods

public instance

  1. sass

Public instance methods

sass (content, options = {})
[show source]
     # File lib/sinatra.rb, line 670
670:     def sass(content, options = {})
671:       require 'sass'
672: 
673:       # Sass doesn't support a layout, so we override any possible layout here
674:       options[:layout] = false
675: 
676:       render(:sass, content, options)
677:     end