Permalink
Browse files

Adding scss support through specific command

  • Loading branch information...
pedromenezes1 authored and rkh committed Aug 30, 2010
1 parent 5556dbe commit cf3c218a6c519688c1d44677030a4524fe588701
Showing with 125 additions and 1 deletion.
  1. +26 −0 README.rdoc
  2. +5 −0 lib/sinatra/base.rb
  3. +25 −0 lib/sinatra/tilt.rb
  4. +2 −1 sinatra.gemspec
  5. +64 −0 test/scss_test.rb
  6. +3 −0 test/views/hello.scss
View
@@ -203,6 +203,32 @@ and overridden on an individual basis.
sass :stylesheet, :style => :expanded # overridden
end
+=== Scss Templates
+
+The sass gem/library is required to render Scss templates:
+
+ ## You'll need to require haml or sass in your app
+ require 'sass'
+
+ get '/stylesheet.css' do
+ content_type 'text/css', :charset => 'utf-8'
+ scss :stylesheet
+ end
+
+Renders <tt>./views/stylesheet.scss</tt>.
+
+{Scss' options}[http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options]
+can be set globally through Sinatra's configurations,
+see {Options and Configurations}[http://www.sinatrarb.com/configuration.html],
+and overridden on an individual basis.
+
+ set :scss, {:style => :compact } # default Scss style is :nested
+
+ get '/stylesheet.css' do
+ content_type 'text/css', :charset => 'utf-8'
+ scss :stylesheet, :style => :expanded # overridden
+ end
+
=== Less Templates
The less gem/library is required to render Less templates:
View
@@ -317,6 +317,11 @@ def sass(template, options={}, locals={})
render :sass, template, options, locals
end
+ def scss(template, options={}, locals={})
+ options[:layout] = false
+ render :scss, template, options, locals
+ end
+
def less(template, options={}, locals={})
options[:layout] = false
render :less, template, options, locals
View
@@ -514,6 +514,31 @@ def sass_options
register 'sass', SassTemplate
+ # Scss template implementation.
+ #
+ # Scss templates do not support object scopes, locals, or yield.
+ class ScssTemplate < Template
+ def initialize_engine
+ return if defined? ::Sass::Engine
+ require_template_library 'sass'
+ end
+
+ def prepare
+ @engine = ::Sass::Engine.new(data, scss_options)
+ end
+
+ def evaluate(scope, locals, &block)
+ @output ||= @engine.render
+ end
+
+ private
+ def scss_options
+ options.merge(:filename => eval_file, :line => line, :syntax => :scss)
+ end
+ end
+ register 'scss', ScssTemplate
+
+
# Lessscss template implementation. See:
# http://lesscss.org/
#
View
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
s.name = 'sinatra'
s.version = '1.0'
- s.date = '2010-03-23'
+ s.date = '2010-08-29'
s.description = "Classy web-development dressed in a DSL"
s.summary = "Classy web-development dressed in a DSL"
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
AUTHORS
CHANGES
LICENSE
+ README.de.rdoc
README.jp.rdoc
README.rdoc
Rakefile
View
@@ -0,0 +1,64 @@
+require File.dirname(__FILE__) + '/helper'
+
+begin
+require 'sass'
+
+class ScssTest < Test::Unit::TestCase
+ def scss_app(&block)
+ mock_app {
+ set :views, File.dirname(__FILE__) + '/views'
+ get '/', &block
+ }
+ get '/'
+ end
+
+ it 'renders inline Scss strings' do
+ scss_app { scss "#scss {\n background-color: white; }\n" }
+ assert ok?
+ assert_equal "#scss {\n background-color: white; }\n", body
+ end
+
+ it 'renders .scss files in views path' do
+ scss_app { scss :hello }
+ assert ok?
+ assert_equal "#scss {\n background-color: white; }\n", body
+ end
+
+ it 'ignores the layout option' do
+ scss_app { scss :hello, :layout => :layout2 }
+ assert ok?
+ assert_equal "#scss {\n background-color: white; }\n", body
+ end
+
+ it "raises error if template not found" do
+ mock_app {
+ get('/') { scss :no_such_template }
+ }
+ assert_raise(Errno::ENOENT) { get('/') }
+ end
+
+ it "passes scss options to the scss engine" do
+ scss_app {
+ scss "#scss {\n background-color: white;\n color: black\n}",
+ :style => :compact
+ }
+ assert ok?
+ assert_equal "#scss { background-color: white; color: black; }\n", body
+ end
+
+ it "passes default scss options to the scss engine" do
+ mock_app {
+ set :scss, {:style => :compact} # default scss style is :nested
+ get '/' do
+ scss "#scss {\n background-color: white;\n color: black;\n}"
+ end
+ }
+ get '/'
+ assert ok?
+ assert_equal "#scss { background-color: white; color: black; }\n", body
+ end
+end
+
+rescue
+ warn "#{$!.to_s}: skipping scss tests"
+end
View
@@ -0,0 +1,3 @@
+#scss {
+ background-color: white
+}

0 comments on commit cf3c218

Please sign in to comment.