From cfdce839250df4b30e092140c290bd6f670a9cd0 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sat, 27 Aug 2011 15:01:31 -0700 Subject: [PATCH] require() can take absolute paths --- src/bootstrap.coffee | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/bootstrap.coffee b/src/bootstrap.coffee index fd49feeca..fe3344a1b 100644 --- a/src/bootstrap.coffee +++ b/src/bootstrap.coffee @@ -5,8 +5,7 @@ console.log = (thing) -> OSX.NSLog thing.toString() modules = {} paths = ['src', 'vendor'] read = (path) -> - root = OSX.NSBundle.mainBundle.resourcePath - OSX.NSString.stringWithContentsOfFile "#{root}/#{path}" + OSX.NSString.stringWithContentsOfFile path this.require = (file) -> # hack for stupid requirejs if file.indexOf('ace/requirejs/text!') > -1 @@ -16,12 +15,17 @@ this.require = (file) -> return modules[file] if modules[file] code = null - paths.forEach (path) -> - return code if code - if text - code = read "#{path}/#{file}" - else - code = read("#{path}/#{file}.js") or read("#{path}/#{file}/index.js") + if file[0] is '/' + code = read("#{file}.js") or read("#{file}/index.js") + else + root = OSX.NSBundle.mainBundle.resourcePath + paths.forEach (path) -> + return code if code + if text + code = read "#{root}/#{path}/#{file}" + else + code = read("#{root}/#{path}/#{file}.js") or + read("#{root}/#{path}/#{file}/index.js") if text modules[file] = code.toString()