Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 22d0a002ead0b336cd82a1620b1711ff10c9eb1a @paulmillr paulmillr committed Dec 25, 2011
No changes.
@@ -0,0 +1,33 @@
+{
+ "author": "Brunch team (http://brunch.io/)",
+ "name": "brunch-extensions",
+ "description": "Brunch extensions",
+ "version": "0.1.0-dev",
+ "homepage": "https://github.com/brunch/brunch-extensions",
+ "repository": {
+ "type": "git",
+ "url": "git@github.com:brunch/brunch-extensions.git"
+ },
+ "main": "./lib/index",
+ "scripts": {
+ "postinstall": "./node_modules/coffee-script/bin/coffee -o lib/ src/",
+ "test": "./node_modules/mocha/bin/mocha"
+ },
+ "engines": {
+ "node": "~0.6.6"
+ },
+ "dependencies": {
+ "async": "0.1.15",
+ "mkdirp": "0.2.1",
+ "coffee-script": "1.2.0",
+ "roy": "0.1.3",
+ "eco": "1.0.3",
+ "jade": "0.19.0",
+ "stylus": "0.21.2",
+ "less": "1.1.6"
+ },
+ "devDependencies": {
+ "mocha": "0.3.6",
+ "expect.js": "0.1.1"
+ }
+}
@@ -0,0 +1,8 @@
+fs = require 'fs'
+util = require 'util'
+
+# Copies single file and executes callback when done.
+exports.copyFile = (source, destination, callback) ->
+ read = fs.createReadStream source
+ write = fs.createWriteStream destination
+ util.pump read, write, -> callback?()
@@ -0,0 +1,3 @@
+module.exports =
+ languages: require './languages'
+ plugins: require './plugins'
@@ -0,0 +1,22 @@
+fs = require 'fs'
+path = require 'path'
+async = require 'async'
+
+class exports.BaseLanguage
+ queue: async.queue fs.readFile, 5
+
+ constructor: (@config) ->
+ null
+
+ getRootPath: (subPathes...) ->
+ path.join @config.rootPath, subPathes...
+
+ getBuildPath: (subPathes...) ->
+ path.join @config.buildPath, subPathes...
+
+ readFile: (file, callback) ->
+ @queue.push file, (error, data) ->
+ callback error, data.toString()
+
+ compile: (file, callback) ->
+ @readFile file, callback
@@ -0,0 +1,11 @@
+coffeescript = require 'coffee-script'
+{BaseLanguage} = require './base'
+
+class exports.CoffeeScriptLanguage extends BaseLanguage
+ compile: (file, callback) ->
+ @readFile file, (error, data) ->
+ return callback error if error?
+ try
+ callback null, coffeescript.compile data
+ catch error
+ callback error
@@ -0,0 +1,3 @@
+{BaseLanguage} = require './base'
+
+class exports.CSSLanguage extends BaseLanguage
@@ -0,0 +1,8 @@
+eco = require 'eco'
+{BaseLanguage} = require './base'
+
+class exports.EcoLanguage extends BaseLanguage
+ compile: (file, callback) ->
+ @readFile file, (error, data) =>
+ return callback error if error?
+ eco.compile data, callback
@@ -0,0 +1,10 @@
+{BaseLanguage} = require './base'
+{CoffeeScriptLanguage} = require './coffeescript'
+{CSSLanguage} = require './css'
+{JavaScriptLanguage} = require './javascript'
+{StylusLanguage} = require './stylus'
+
+module.exports = {
+ BaseLanguage, CoffeeScriptLanguage, CSSLanguage, JavaScriptLanguage,
+ StylusLanguage
+}
@@ -0,0 +1,12 @@
+jade = require 'jade'
+{BaseLanguage} = require './base'
+
+class exports.JadeLanguage extends BaseLanguage
+ compile: (file, callback) ->
+ @readFile file, (error, data) ->
+ return callback error if error?
+ try
+ content = jade.compile data, compileDebug: no, client: yes
+ callback null, "module.exports = #{content};"
+ catch error
+ callback error
@@ -0,0 +1,3 @@
+{BaseLanguage} = require './base'
+
+class exports.JavaScriptLanguage extends BaseLanguage
@@ -0,0 +1,9 @@
+less= require 'less'
+{BaseLanguage} = require './base'
+
+class exports.LESSLanguage extends BaseLanguage
+ compile: (file, callback) ->
+ @readFile file, (error, data) ->
+ return callback error if error?
+ less.render data, (error, css) ->
+ callback error, css
@@ -0,0 +1,11 @@
+roy = require 'roy'
+{BaseLanguage} = require './base'
+
+class exports.RoyLanguage extends BaseLanguage
+ compile: (file, callback) ->
+ @readFile file, (error, data) ->
+ callback error if error?
+ try
+ callback null, (roy.compile data).output
+ catch error
+ callback error
@@ -0,0 +1,20 @@
+stylus = require 'stylus'
+{BaseLanguage} = require './base'
+
+# NIB is an official stylus library of useful mixins etc.
+# just like Compass.
+try
+ nib = require('nib')()
+catch error
+ null
+
+class exports.StylusLanguage extends BaseLanguage
+ compile: (file, callback) ->
+ @readFile file, (error, data) =>
+ return callback error if error?
+ compiler = stylus(data)
+ .set('compress', yes)
+ .set('firebug', !!@config.stylus?.firebug)
+
+ compiler.use nib if nib
+ compiler.render callback
@@ -0,0 +1,20 @@
+path = require 'path'
+mkdirp = require 'mkdirp'
+helpers = require '../helpers'
+{BasePlugin} = require './base'
+
+
+class exports.AssetsPlugin extends BasePlugin
+ compile: (callback) ->
+ sourceDirectory = path.resolve @getRootPath 'app', 'assets'
+ async.forEach files, (source, next) =>
+ destination = @getBuildPath path.resolve(source).replace sourceDirectory, ''
+ copy = =>
+ helpers.copyFile source, destination, next
+ destinationDirectory = path.dirname destination
+ fs.stat destinationDirectory, (error, stats) =>
+ if error?
+ mkdirp path.resolve(destinationDirectory), 0755, copy
+ else
+ copy()
+ , callback
@@ -0,0 +1,12 @@
+class exports.BasePlugin
+ constructor: (@options) ->
+ null
+
+ getRootPath: (subPathes...) ->
+ path.join @options.rootPath, subPathes...
+
+ getBuildPath: (subPathes...) ->
+ path.join @options.buildPath, subPathes...
+
+ compile: (callback) ->
+ callback()
@@ -0,0 +1,6 @@
+{AssetsPlugin} = require './assets'
+{BasePlugin} = require './base'
+
+module.exports = {
+ AssetsPlugin, BasePlugin
+}

0 comments on commit 22d0a00

Please sign in to comment.