Added Less support
Signed-off-by: Simon Rozet <simon@rozet.name>
This commit is contained in:
parent
4d61607176
commit
621bfcbd6a
14
README.rdoc
14
README.rdoc
|
@ -203,6 +203,20 @@ and overridden on an individual basis.
|
|||
sass :stylesheet, :style => :expanded # overridden
|
||||
end
|
||||
|
||||
=== Less Templates
|
||||
|
||||
The less gem/library is required to render Less templates:
|
||||
|
||||
## You'll need to require less in your app
|
||||
require 'less'
|
||||
|
||||
get '/stylesheet.css' do
|
||||
content_type 'text/css', :charset => 'utf-8'
|
||||
less :stylesheet
|
||||
end
|
||||
|
||||
Renders <tt>./views/stylesheet.less</tt>.
|
||||
|
||||
=== Inline Templates
|
||||
|
||||
get '/' do
|
||||
|
|
|
@ -284,7 +284,7 @@ module Sinatra
|
|||
#
|
||||
# Possible options are:
|
||||
# :layout If set to false, no layout is rendered, otherwise
|
||||
# the specified layout is used (Ignored for `sass`)
|
||||
# the specified layout is used (Ignored for `sass` and `less`)
|
||||
# :locals A hash with local variables that should be available
|
||||
# in the template
|
||||
module Templates
|
||||
|
@ -304,6 +304,11 @@ module Sinatra
|
|||
options[:layout] = false
|
||||
render :sass, template, options, locals
|
||||
end
|
||||
|
||||
def less(template, options={}, locals={})
|
||||
options[:layout] = false
|
||||
render :less, template, options, locals
|
||||
end
|
||||
|
||||
def builder(template=nil, options={}, locals={}, &block)
|
||||
options, template = template, nil if template.is_a?(Hash)
|
||||
|
|
|
@ -38,6 +38,7 @@ Gem::Specification.new do |s|
|
|||
test/haml_test.rb
|
||||
test/helper.rb
|
||||
test/helpers_test.rb
|
||||
test/less_test.rb
|
||||
test/mapped_error_test.rb
|
||||
test/middleware_test.rb
|
||||
test/public/favicon.ico
|
||||
|
@ -64,6 +65,7 @@ Gem::Specification.new do |s|
|
|||
test/views/hello.haml
|
||||
test/views/hello.sass
|
||||
test/views/hello.test
|
||||
test/views/hello.less
|
||||
test/views/layout2.builder
|
||||
test/views/layout2.erb
|
||||
test/views/layout2.erubis
|
||||
|
@ -81,6 +83,7 @@ Gem::Specification.new do |s|
|
|||
s.add_development_dependency 'haml'
|
||||
s.add_development_dependency 'builder'
|
||||
s.add_development_dependency 'erubis'
|
||||
s.add_development_dependency 'less'
|
||||
|
||||
s.has_rdoc = true
|
||||
s.homepage = "http://sinatra.rubyforge.org"
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
require File.dirname(__FILE__) + '/helper'
|
||||
require 'less'
|
||||
|
||||
class LessTest < Test::Unit::TestCase
|
||||
def less_app(&block)
|
||||
mock_app {
|
||||
set :views, File.dirname(__FILE__) + '/views'
|
||||
get '/', &block
|
||||
}
|
||||
get '/'
|
||||
end
|
||||
|
||||
it 'renders inline Less strings' do
|
||||
less_app { less "@white_color: #fff; #main { background-color: @white_color }"}
|
||||
assert ok?
|
||||
assert_equal "#main { background-color: #ffffff; }\n", body
|
||||
end
|
||||
|
||||
it 'renders .less files in views path' do
|
||||
less_app { less :hello }
|
||||
assert ok?
|
||||
assert_equal "#main { background-color: #ffffff; }\n", body
|
||||
end
|
||||
|
||||
it 'ignores the layout option' do
|
||||
less_app { less :hello, :layout => :layout2 }
|
||||
assert ok?
|
||||
assert_equal "#main { background-color: #ffffff; }\n", body
|
||||
end
|
||||
|
||||
it "raises error if template not found" do
|
||||
mock_app {
|
||||
get('/') { less :no_such_template }
|
||||
}
|
||||
assert_raise(Errno::ENOENT) { get('/') }
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
@white_colour: #fff;
|
||||
|
||||
#main {
|
||||
background-color: @white_colour;
|
||||
}
|
Loading…
Reference in New Issue