Permalink
Browse files

Expose default compilers as stitch.compilers and add Eco support

  • Loading branch information...
sstephenson committed Feb 20, 2011
1 parent bf47be9 commit 3631d587d00fbadb65456bd78643101a6a96b5c1
Showing with 46 additions and 10 deletions.
  1. +14 −4 lib/stitch.js
  2. +10 −3 src/stitch.coffee
  3. +4 −0 test/fixtures/eco/hello.html.eco
  4. +18 −3 test/test_stitch.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -4,24 +4,31 @@ fs = require 'fs'
{extname, join, normalize} = require 'path'
defaultCompilers =
exports.compilers = compilers =
js: (module, filename) ->
content = fs.readFileSync filename, 'utf8'
module._compile content, filename
try
CoffeeScript = require 'coffee-script'
defaultCompilers.coffee = (module, filename) ->
compilers.coffee = (module, filename) ->
content = CoffeeScript.compile fs.readFileSync filename, 'utf8'
module._compile content, filename
catch err
try
eco = require 'eco'
compilers.eco = (module, filename) ->
content = eco.compile fs.readFileSync filename, 'utf8'
module._compile content, filename
catch err
exports.Package = class Package
constructor: (config) ->
@identifier = config.identifier ? 'require'
@paths = config.paths ? ['lib']
@compilers = _.extend {}, defaultCompilers, config.compilers
@compilers = _.extend {}, compilers, config.compilers
@cache = config.cache ? true
@mtimeCache = {}
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<html>
<body>
hello <%= @name %>!
View
@@ -6,25 +6,28 @@ fixtureRoot = __dirname + "/fixtures"
fixtures = fixtureRoot + "/default"
altFixtures = fixtureRoot + "/alternate"
addlFixtures = fixtureRoot + "/additional"
ecoFixtures = fixtureRoot + "/eco"
fixtureCount = 11
defaultOptions =
identifier: "testRequire"
paths: [fixtures]
defaultPackage = stitch.createPackage defaultOptions
additionalOptions =
identifier: "testRequire"
paths: [addlFixtures]
additionalPackage = stitch.createPackage additionalOptions
alternateOptions =
paths: [altFixtures]
alternatePackage = stitch.createPackage alternateOptions
ecoOptions =
paths: [ecoFixtures]
ecoPackage = stitch.createPackage ecoOptions
module.exports =
"walk tree": (test) ->
test.expect fixtureCount
@@ -226,3 +229,15 @@ module.exports =
test.same "biz", relative.baz
test.same "BUZ", relative.buz
test.done()
if stitch.compilers.eco
module.exports["eco compiler"] = (test) ->
test.expect 2
ecoPackage.compile (err, sources) ->
test.ok !err
eval sources
html = @require("hello.html")(name: "Sam").trim()
test.same "hello Sam!", html.split("\n").pop()
test.done()

0 comments on commit 3631d58

Please sign in to comment.