Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Sass module and 'sass' method for rendering Sass stylesheets.

  • Loading branch information...
commit 2baa78d95ef6d69c5c62bca2d47af2ae658e5bd5 1 parent 4efbbef
@nmeans nmeans authored
Showing with 61 additions and 0 deletions.
  1. +61 −0 lib/sinatra.rb
View
61 lib/sinatra.rb
@@ -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
@@ -574,6 +634,7 @@ class EventContext
include Erb
include Haml
include Builder
+ include Sass
attr_accessor :request, :response
Please sign in to comment.
Something went wrong with that request. Please try again.