Skip to content

Commit

Permalink
Expose default compilers as stitch.compilers and add Eco support
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Feb 20, 2011
1 parent bf47be9 commit 3631d58
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
18 changes: 14 additions & 4 deletions lib/stitch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/stitch.coffee
Expand Up @@ -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 = {}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/eco/hello.html.eco
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<html>
<body>
hello <%= @name %>!
21 changes: 18 additions & 3 deletions test/test_stitch.coffee
Expand Up @@ -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
Expand Down Expand Up @@ -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.