Skip to content

Commit

Permalink
Allowing options.src to be an absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorBurnham committed Oct 23, 2011
1 parent cde838d commit 412cddd
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cakefile
Expand Up @@ -37,6 +37,7 @@ task 'test', 'Run the test suite (and re-run if anything changes)', ->
suiteNames = [
'DevelopmentIntegration'
'ProductionIntegration'
'AbsoluteIntegration'
'RemoteIntegration'
]
suiteIndex = 0
Expand Down
5 changes: 4 additions & 1 deletion docs/assets.html
Expand Up @@ -131,7 +131,10 @@
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;No file found for route #{route}&quot;</span><span class="p">)</span>

<span class="nv">absPath: </span><span class="nf">(route) -&gt;</span>
<span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">(),</span> <span class="nx">@options</span><span class="p">.</span><span class="nx">src</span><span class="p">,</span> <span class="nx">route</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h2>Asset compilers</h2> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.cssCompilers = cssCompilers =</span>
<span class="k">if</span> <span class="nx">@options</span><span class="p">.</span><span class="nx">src</span><span class="p">.</span><span class="nx">match</span> <span class="nx">EXPLICIT_PATH</span>
<span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">@options</span><span class="p">.</span><span class="nx">src</span><span class="p">,</span> <span class="nx">route</span>
<span class="k">else</span>
<span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">(),</span> <span class="nx">@options</span><span class="p">.</span><span class="nx">src</span><span class="p">,</span> <span class="nx">route</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h2>Asset compilers</h2> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.cssCompilers = cssCompilers =</span>

<span class="nv">styl:</span>
<span class="nv">optionsMap: </span><span class="p">{}</span>
Expand Down
6 changes: 5 additions & 1 deletion lib/assets.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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": {
Expand Down
5 changes: 4 additions & 1 deletion src/assets.coffee
Expand Up @@ -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 =
Expand Down
33 changes: 33 additions & 0 deletions 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 = "<link rel='stylesheet' href='/css/button.css'>"
# 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 = """<script src='/js/subdir/nested/hobbits.js'></script>
<script src='/js/tree-dependent.js'></script>
"""
test.equals js('tree-dependent'), jsTags
test.done()
app.close()

0 comments on commit 412cddd

Please sign in to comment.