Jump To …

createHelpers.coffee

path = require 'path'

module.exports = createHelpers = (options, suffixes) ->
  context = options.helperContext
  expandRoute = (shortRoute, ext, rootDir) ->
    unless shortRoute.match EXPLICIT_PATH
      shortRoute = path.join rootDir, shortRoute
    if shortRoute.indexOf(ext, shortRoute.length - ext.length) is -1
      shortRoute += ext
    shortRoute

  cssExt = '.css'
  context.css = (route) ->
    route = expandRoute route, cssExt, context.css.root
    if suffixes[route]
      route = route.replace /\.css$/, "#{suffixes[route]}.css"
    "<link rel='stylesheet' href='#{route}'>"
  context.css.root = '/css'

  jsExt = '.js'
  context.js = (route) ->
    route = expandRoute route, jsExt, context.js.root
    if options.src? and !route.match REMOTE_PATH and !context.js.concatenate
      dependencyTags = ''
      filePath = path.join options.src, route
      updateDependenciesSync filePath
      return generateTags(filePath, options).join('\n')
    else if suffixes[route]
      route = route.replace /\.js$/, "#{suffixes[route]}.js"
    "<script src='#{route}'></script>"
  context.js.root = '/js'
  context.js.concatenate = process.env.NODE_ENV is 'production'

Utility functions

relPath = (root, fullPath) ->
  fullPath.slice root.length

productionJsPath = (filePath, str, options) ->
  suffix = options.suffixGenerator filePath, str
  filePath.replace /\.js$/, ".complete#{suffix}.js"