Skip to content

Commit

Permalink
Added function to get src urls without html markup
Browse files Browse the repository at this point in the history
  • Loading branch information
sweetpi committed Feb 27, 2015
1 parent 843511e commit 110aa41
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions lib/nap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,40 @@ module.exports = (options = {}) =>

@

# Run js pre-processors & output the packages in dev.

# Returns the script / css urls
#
# @param {String} type Must be 'js' or 'css'
# @param {String} pkg The name of the package to output
# @return {String} Script tag(s) pointing to the ouput package(s)

module.exports.js = (pkg, gzip = @gzip) =>
throw new Error "Cannot find package '#{pkg}'" unless @assets.js[pkg]?
module.exports.getSrcUrls = getSrcUrls = (type, pkg, gzip) =>
throw new Error "Cannot find package '#{pkg}'" unless @assets[type][pkg]?

if @mode is 'production'
fingerprint = '-' + fingerprintForPkg('js', pkg) if @mode is 'production'
src = (@cdnUrl ? @_assetsDir) + '/' + "#{pkg}#{fingerprint ? ''}.js"
src += '.jgz' if gzip
return "<script src='#{src}' type='text/javascript'></script>"
fingerprint = '-' + fingerprintForPkg(type, pkg)
extension = "#{type}"
extension += ".#{type[0]}gz" if gzip
src = (@cdnUrl ? @_assetsDir) + '/' + "#{pkg}#{fingerprint ? ''}.#{extension}"
return [src]

expandAssetGlobs()

output = ''
for filename, contents of preprocessPkg pkg, 'js'
urls = []
for filename, contents of preprocessPkg pkg, type
writeFile filename, contents unless @usingMiddleware
output += "<script src='#{@_assetsDir}/#{filename}' type='text/javascript'></script>"
urls.push "#{@_assetsDir}/#{filename}"
return urls

# Run js pre-processors & output the packages in dev.
#
# @param {String} pkg The name of the package to output
# @return {String} Script tag(s) pointing to the ouput package(s)

module.exports.js = (pkg, gzip = @gzip) =>
urls = getSrcUrls('js', pkg, gzip)
output = ''
for url in urls
output += "<script src='#{url}' type='text/javascript'></script>"
output

# Run css pre-processors & output the packages in dev.
Expand All @@ -90,20 +104,10 @@ module.exports.js = (pkg, gzip = @gzip) =>
# @return {String} Link tag(s) pointing to the ouput package(s)

module.exports.css = (pkg, gzip = @gzip) =>
throw new Error "Cannot find package '#{pkg}'" unless @assets.css[pkg]?

if @mode is 'production'
fingerprint = '-' + fingerprintForPkg('css', pkg) if @mode is 'production'
src = (@cdnUrl ? @_assetsDir) + '/' + "#{pkg}#{fingerprint ? ''}.css"
src += '.cgz' if gzip
return "<link href='#{src}' rel='stylesheet' type='text/css'>"

expandAssetGlobs()

urls = getSrcUrls('css', pkg, gzip)
output = ''
for filename, contents of preprocessPkg pkg, 'css'
writeFile filename, contents unless @usingMiddleware
output += "<link href='#{@_assetsDir}/#{filename}' rel='stylesheet' type='text/css'>"
for url in urls
output += "<link href='#{url}' rel='stylesheet' type='text/css'>"
output

# Compile the templates into JST['file/path'] : functionString pairs in dev
Expand Down

0 comments on commit 110aa41

Please sign in to comment.