Permalink
Browse files

Adding basic LESS support

  • Loading branch information...
2 parents b5b4591 + f81da0b commit 15c7486923063bc935962b9945a6699a5b365d0e Andy Adams committed Nov 12, 2011
Showing with 28 additions and 2 deletions.
  1. +1 −0 Gemfile
  2. +7 −1 Gemfile.lock
  3. +8 −1 lib/forge/builder.rb
  4. +12 −0 lib/forge/engines.rb
View
1 Gemfile
@@ -13,6 +13,7 @@ gem "sprockets-sass", "~> 0.3.0"
gem "compass", "~> 0.11.5"
gem 'rack', '~> 1.3.5'
gem "guard-livereload", "~> 0.3.1"
+gem "less", "~> 2.0.7"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
View
8 Gemfile.lock
@@ -46,6 +46,9 @@ GEM
git (>= 1.2.5)
rake
json (1.6.1)
+ less (2.0.7)
+ therubyracer (~> 0.9.2)
+ libv8 (3.3.10.2)
multi_json (1.0.3)
rack (1.3.5)
rake (0.9.2)
@@ -68,6 +71,8 @@ GEM
sprockets-sass (0.3.0)
sprockets (~> 2.0)
term-ansicolor (1.0.6)
+ therubyracer (0.9.9)
+ libv8 (~> 3.3.10)
thor (0.14.6)
tilt (1.3.3)
@@ -83,11 +88,12 @@ DEPENDENCIES
guard-livereload (~> 0.3.1)
jeweler (~> 1.6.4)
json (~> 1.6.1)
+ less (~> 2.0.7)
rack (~> 1.3.5)
rcov
rspec
rubyzip (~> 0.9.4)
sass (~> 3.1.8)
sprockets (~> 2.0.2)
sprockets-sass (~> 0.3.0)
- thor (~> 0.14.6)
+ thor (~> 0.14.6)
View
9 lib/forge/builder.rb
@@ -1,8 +1,10 @@
require 'sprockets'
require 'sprockets-sass'
require 'sass'
+require 'less'
require 'zip/zip'
require 'compass'
+require 'forge/engines'
module Forge
class Builder
@@ -188,6 +190,11 @@ def init_sprockets
@sprockets.append_path File.join(@assets_path, dir)
end
+ # Add assets/styleshets to load path for Less Engine
+ Tilt::LessTemplateWithPaths.load_path = File.join(@assets_path, 'stylesheets')
+
+ @sprockets.register_engine '.less', Tilt::LessTemplateWithPaths
+
# Passing the @project instance variable to the Sprockets::Context instance
# used for processing the asset ERB files. Ruby meta-programming, FTW.
@sprockets.context_class.instance_exec(@project) do |project|
@@ -235,7 +242,7 @@ def write_erb(source, destination)
@task.say "Error while building #{File.basename(source)}:"
@task.say e.message + "\n", Thor::Shell::Color::RED
exit
- end
+ end
end
end
end
View
12 lib/forge/engines.rb
@@ -0,0 +1,12 @@
+module Tilt
+ class LessTemplateWithPaths < LessTemplate
+ class << self
+ attr_accessor :load_path
+ end
+
+ def prepare
+ parser = ::Less::Parser.new(:filename => eval_file, :line => line, :paths => [self.class.load_path])
+ @engine = parser.parse(data)
+ end
+ end
+end

0 comments on commit 15c7486

Please sign in to comment.