Class: Less::Loader
Defined Under Namespace
Classes: Console, Fs, Path, Process, Sys
Instance Method Summary collapse
-
#initialize ⇒ Loader
constructor
A new instance of Loader.
- #require(path) ⇒ Object
Methods included from CallJS
Constructor Details
#initialize ⇒ Loader
Returns a new instance of Loader.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/less/loader.rb', line 6 def initialize lock do @cxt = V8::Context.new @path = Pathname(__FILE__).dirname.join('js','lib') @exports = { "path" => Path.new, "sys" => Sys.new, "fs" => Fs.new } @process = Process.new @cxt['console'] = Console.new end end |
Instance Method Details
#require(path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/less/loader.rb', line 20 def require(path) unless exports = @exports[path] filename = path =~ /\.js$/ ? path : "#{path}.js" filepath = @path.join(filename) fail LoadError, "no such file: #{filename}" unless filepath.exist? lock do load = @cxt.eval("(function(process, require, exports, __dirname) {require.paths = [];#{File.read(filepath)}})", filepath.) @exports[path] = exports = @cxt['Object'].new load.call(@process, method(:require), exports, Dir.pwd) end end return exports end |