Browse files

Added lesscss implementation

Signed-off-by: Ben Schwarz <ben.schwarz@gmail.com>
  • Loading branch information...
1 parent cf53334 commit 667bbd6bc93087728bc693808fab1c1aaa94e6ee @benschwarz benschwarz committed Jan 8, 2010
Showing with 39 additions and 0 deletions.
  1. +19 −0 lib/tilt.rb
  2. +20 −0 test/tilt_lesstemplate_test.rb
View
19 lib/tilt.rb
@@ -325,6 +325,25 @@ def sass_options
register 'sass', SassTemplate
+ # Lessscss template implementation. See:
+ # http://lesscss.org/
+ #
+ # Less templates do not support object scopes, locals, or yield.
+ class LessTemplate < Template
+ def initialize_engine
+ require_template_library 'less' unless defined? ::Less::Engine
+ end
+
+ def compile!
+ @engine = ::Less::Engine.new(data)
+ end
+
+ def evaluate(scope, locals, &block)
+ @engine.to_css
+ end
+ end
+ register 'less', LessTemplate
+
# Builder template implementation. See:
# http://builder.rubyforge.org/
class BuilderTemplate < Template
View
20 test/tilt_lesstemplate_test.rb
@@ -0,0 +1,20 @@
+require 'contest'
+require 'tilt'
+
+begin
+ require 'less'
+
+ class LessTemplateTest < Test::Unit::TestCase
+ test "is registered for '.less' files" do
+ assert_equal Tilt::LessTemplate, Tilt['test.less']
+ end
+
+ test "compiles and evaluates the template on #render" do
+ template = Tilt::LessTemplate.new { |t| ".bg { background-color: #0000ff; } \n#main\n { .bg; }\n" }
+ assert_equal ".bg, #main { background-color: #0000ff; }\n", template.render
+ end
+ end
+
+rescue LoadError => boom
+ warn "Tilt::LessTemplate (disabled)\n"
+end

0 comments on commit 667bbd6

Please sign in to comment.