Skip to content

Commit

Permalink
Added Sass module and 'sass' method for rendering Sass stylesheets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickolas Means committed Apr 8, 2008
1 parent 4efbbef commit 2baa78d
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions lib/sinatra.rb
Expand Up @@ -475,6 +475,66 @@ def render_haml(content, options = {}, &b)

end

# 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.
#
# === 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 http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html for comprehensive documentation on Sass.


module Sass

def sass(content)
require 'sass'
render(:sass, content)
end

private

def render_sass(content, options = {})
::Sass::Engine.new(content).render
end
end

# Generating conservative XML content using Builder templates.
#
# Builder templates can be inline by passing a block to the builder method, or in
Expand Down Expand Up @@ -574,6 +634,7 @@ class EventContext
include Erb
include Haml
include Builder
include Sass

attr_accessor :request, :response

Expand Down

0 comments on commit 2baa78d

Please sign in to comment.