From 412cddd3622b3e3ff432aa13d9f6afa53759dd67 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Sun, 23 Oct 2011 14:42:49 -0400 Subject: [PATCH] Allowing options.src to be an absolute path --- Cakefile | 1 + docs/assets.html | 5 ++++- lib/assets.js | 6 +++++- package.json | 2 +- src/assets.coffee | 5 ++++- test/AbsoluteIntegration.coffee | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 test/AbsoluteIntegration.coffee diff --git a/Cakefile b/Cakefile index 83977c3..a9a76e1 100644 --- a/Cakefile +++ b/Cakefile @@ -37,6 +37,7 @@ task 'test', 'Run the test suite (and re-run if anything changes)', -> suiteNames = [ 'DevelopmentIntegration' 'ProductionIntegration' + 'AbsoluteIntegration' 'RemoteIntegration' ] suiteIndex = 0 diff --git a/docs/assets.html b/docs/assets.html index 536f9ce..2e06d1c 100644 --- a/docs/assets.html +++ b/docs/assets.html @@ -131,7 +131,10 @@ throw new Error("No file found for route #{route}") absPath: (route) -> - path.join process.cwd(), @options.src, route

Asset compilers

exports.cssCompilers = cssCompilers =
+    if @options.src.match EXPLICIT_PATH
+      path.join @options.src, route
+    else
+      path.join process.cwd(), @options.src, route

Asset compilers

exports.cssCompilers = cssCompilers =
 
   styl:
     optionsMap: {}
diff --git a/lib/assets.js b/lib/assets.js
index a460188..e15cd04 100644
--- a/lib/assets.js
+++ b/lib/assets.js
@@ -255,7 +255,11 @@
       throw new Error("No file found for route " + route);
     };
     ConnectAssets.prototype.absPath = function(route) {
-      return path.join(process.cwd(), this.options.src, route);
+      if (this.options.src.match(EXPLICIT_PATH)) {
+        return path.join(this.options.src, route);
+      } else {
+        return path.join(process.cwd(), this.options.src, route);
+      }
     };
     return ConnectAssets;
   })();
diff --git a/package.json b/package.json
index 5da4f3b..23916fd 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
   "dependencies": {
     "connect-file-cache": "0.2.3",
     "mime": "1.2.2",
-    "snockets": "1.3.1",
+    "snockets": "1.3.2",
     "underscore": "1.1.7"
   },
   "devDependencies": {
diff --git a/src/assets.coffee b/src/assets.coffee
index 0928b2e..15068f0 100644
--- a/src/assets.coffee
+++ b/src/assets.coffee
@@ -148,7 +148,10 @@ class ConnectAssets
     throw new Error("No file found for route #{route}")
 
   absPath: (route) ->
-    path.join process.cwd(), @options.src, route
+    if @options.src.match EXPLICIT_PATH
+      path.join @options.src, route
+    else
+      path.join process.cwd(), @options.src, route
 
 # ## Asset compilers
 exports.cssCompilers = cssCompilers =
diff --git a/test/AbsoluteIntegration.coffee b/test/AbsoluteIntegration.coffee
new file mode 100644
index 0000000..814b453
--- /dev/null
+++ b/test/AbsoluteIntegration.coffee
@@ -0,0 +1,33 @@
+process.env.NODE_ENV = 'development'
+path = require 'path'
+request = require 'request'
+
+app = require('connect').createServer()
+assets = require('../lib/assets.js')
+app.use assets src: path.join(__dirname, 'assets')
+app.listen 3590
+
+# exports['Compiled stylesheets work from absolute options.src'] = (test) ->
+#   cssTag = ""
+#   test.equals css('button'), cssTag
+#   test.done()
+
+#   request 'http://localhost:3588/css/button.css', (err, res, body) ->
+#     throw err if err
+#     expectedBody = '''
+#     .button {
+#       -webkit-border-radius: 5px;
+#       -moz-border-radius: 5px;
+#       border-radius: 5px;
+#     }\n
+#     '''
+#     test.equals body, expectedBody
+#     test.done()
+
+exports['JS dependencies work from absolute options.src'] = (test) ->
+  jsTags = """
+  
+  """
+  test.equals js('tree-dependent'), jsTags
+  test.done()
+  app.close()
\ No newline at end of file