coffee-assets
v0.1.5
Published
Sprockets syntax for aggregating/minifying/gzipping CoffeeTemplates, CoffeeStylesheets, and CoffeeSprites.
Downloads
3
Readme
Why CoffeeAssets?
CoffeeAssets will bulk compile CoffeeTemplates, CoffeeScript, and CoffeeStylesheets with support for CoffeeSprites.
Optionally aggregating these using Sprockets-like #= require ./../file
directives, minifying with Google Closure, suffixing a digest,
writing a manifest.json
, and gzipping into the neat little production-quality packages you expect. Additionally, its
incredibly fast, with no meddling middleware dependencies, or slow transpilers inbetween.
Inspired by mincer, coffee-sprites, and buildr.npm.
Quick Examples
# CoffeeScripts
watch [
in: 'precompile'
suffix: '/server.js.coffee'
out: ''
,
in: 'precompile/controllers/server'
out: 'static/app/controllers'
,
in: 'precompile/controllers/shared'
out: 'static/public/assets/controllers'
,
in: 'precompile/models/server'
out: 'static/app/models'
,
in: 'precompile/models/shared'
out: 'static/public/assets/models'
,
in: [
'precompile/assets/behaviors'
'precompile/vendor/assets'
]
out: 'static/public/assets'
], '/**/*.{js,js.coffee}', (infile, outfile) ->
assets.precompile infile, assets.compiler(), (err, compiled) ->
return notify 'Cake CoffeeAssets CoffeeScript compiler', err, true, true if err
write outfile.replace(/\.coffee$/,''), compiled
# CoffeeStylesheets
watch [
in: [
'precompile/assets/stylesheets'
'precompile/vendor/assets'
],
out: 'static/public/assets'
# filenames with underscore prefix are only compiled via require
], '/**/!(@(_))*.{css,css.coffee}', (infile, outfile) ->
assets.precompile infile, assets.compiler(
stylesheet_options:
format: true
sprite_options:
image_path: 'precompile/assets/sprites/'
sprite_path: 'static/public/assets/'
sprite_url: '/assets/'
), (err, compiled) ->
return notify 'Cake CoffeeAssets CoffeeStylesheets compiler', err, true, true if err
write outfile.replace(/\.coffee/,''), compiled
# CoffeeTemplates (server-side; single function per file)
watch [
in: 'precompile/views/server'
out: 'static/app/views'
], '/**/*.html.coffee', (infile, outfile) ->
assets.precompile infile, assets.compiler(
template_options:
format: true
), (err, compiled) ->
return notify 'Cake CoffeeAssets CoffeeTemplates compiler', err, true, true if err
write outfile.replace(/\.html.coffee/,'.js'), compiled
# CoffeeTemplates (client-side; multi-function aggregated to single file)
watch 'precompile/views/shared/**/*.html.coffee', ->
# if ANY template file changes, ALL must be recompiled
# because they are aggregated into a single templates.js file and function()
assets.precompile_templates 'precompile/views/shared', {
template_options:
format: true
}, (err, compiled) ->
return notify 'Cake CoffeeAssets CoffeeTemplates compiler', err, true, true if err
write 'static/public/assets/templates.js', compiled
For the most recent and comprehensive examples, see CoffeeShop's Cakefile.