Skip to content

Commit

Permalink
Add ability to add javascript paths to load path of environment after…
Browse files Browse the repository at this point in the history
… initialization
  • Loading branch information
DEfusion committed Jul 22, 2014
1 parent df6a5f0 commit 8d92d1d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ source 'https://rubygems.org'

gemspec

gem 'commonjs', git: 'git://github.com/bandzoogle/commonjs.rb.git'

This comment has been minimized.

Copy link
@kares

kares Jul 25, 2014

we need to play with the official common.js ... is this opened as a PR ?
also, please use 1.8 syntax here ... we're still testing against 1.8 rubies on travis-ci

This comment has been minimized.

Copy link
@DEfusion

DEfusion Jul 25, 2014

Author Member

Yes this is an open PR on commonjs.rb cowboyd/commonjs.rb#15 once that is accepted I can remove the specific git path in the gemfile


gem "therubyracer", "~> 0.12.0", :require => nil, :platforms => :ruby
gem "therubyrhino", ">= 2.0.2", :require => nil, :platforms => :jruby

Expand Down
2 changes: 1 addition & 1 deletion less.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency "commonjs", "~> 0.2.7"
s.add_dependency "commonjs", "~> 0.2.8"
end
12 changes: 8 additions & 4 deletions lib/less.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

module Less
extend Less::Defaults
# NOTE: keep the @loader as less-rails depends on

# NOTE: keep the @loader as less-rails depends on
# it as it overrides some less/tree.js functions!
@loader = Less::Loader.new
@less = @loader.require('less/index')

def self.[](name)
@less[name]
end

# exposes less.Parser
def self.Parser
self['Parser']
Expand All @@ -28,5 +28,9 @@ def self.Parser
def self.tree
self['tree']
end


def self.add_javascript_path(path)
@loader.add_javascript_path(path)
end

end
4 changes: 4 additions & 0 deletions lib/less/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def require(module_id)
@environment.require(module_id)
end

def add_javascript_path(path)
@environment.add_path(path)
end

# JS exports (required by less.js) :

class Process # :nodoc:
Expand Down
2 changes: 1 addition & 1 deletion lib/less/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Less
VERSION = '2.6.0'
VERSION = '2.7.0'
end
14 changes: 14 additions & 0 deletions spec/less/loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,18 @@
after { Less.javascript_paths.delete path }
end

describe '.add_javascript_path' do
let(:path) { Pathname(__FILE__).dirname.join('js') }

before { subject.add_javascript_path(path) }

it 'should be able to include javascript from that path' do
lambda { subject.environment.require 'test.js' }.should_not raise_error
end

it 'should be able to include javascript from lib path' do
lambda { subject.environment.require 'less/index' }.should_not raise_error
end
end

end

0 comments on commit 8d92d1d

Please sign in to comment.