-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2fd61c3
Showing
9 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*~ | ||
*.bak | ||
.DS_Store | ||
npm-debug.log | ||
lib/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.lock-wscript | ||
.svn/ | ||
.hg/ | ||
.git/ | ||
CVS/ | ||
*~ | ||
*.bak | ||
.DS_Store | ||
npm-debug.log | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## swig-brunch | ||
Compiles Swig template files for use in [brunch](http://brunch.io). Plugin checks for files that have one of the following extensions: | ||
|
||
- .html | ||
- .swig | ||
|
||
|
||
## Usage | ||
Add `"swig-brunch": "x.y.z"` to `package.json` of your brunch app. | ||
|
||
Pick a plugin version that corresponds to your minor (y) brunch version. | ||
|
||
If you want to use git version of plugin, add | ||
`"swig-brunch": "git+ssh://git@github.com:wmdmark/swig-brunch.git"`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "swig-brunch", | ||
"version": "1.0.0", | ||
"description": "Compiles swig templates for brunch.", | ||
"author": "Mark Johnson", | ||
"homepage": "https://github.com/wmdmark/swig-brunch", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:wmdmark/swig-brunch.git" | ||
}, | ||
"main": "./lib/index", | ||
"scripts": { | ||
"prepublish": "node setup.js prepublish", | ||
"postpublish": "node setup.js postpublish", | ||
"test": "node setup.js test" | ||
}, | ||
"engines": { | ||
"node": "~0.6.10 || 0.8 || 0.9" | ||
}, | ||
"dependencies": { | ||
"coffee-script": "1.4.0", | ||
"swig": "*" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.8.1", | ||
"chai": "1.4.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var exec = require('child_process').exec; | ||
var sysPath = require('path'); | ||
var fs = require('fs'); | ||
|
||
// Cross-platform node.js postinstall & test script for coffeescript projects. | ||
|
||
var mode = process.argv[2]; | ||
|
||
var fsExists = fs.exists || sysPath.exists; | ||
|
||
var getBinaryPath = function(binary) { | ||
return sysPath.join('node_modules', '.bin', binary); | ||
}; | ||
|
||
var execute = function(path, params, callback) { | ||
if (callback == null) callback = function() {}; | ||
var command = 'node ' + path + ' ' + params; | ||
console.log('Executing', command); | ||
exec(command, function(error, stdout, stderr) { | ||
if (error != null) return process.stderr.write(stderr.toString()); | ||
console.log(stdout.toString()); | ||
}); | ||
}; | ||
|
||
var togglePostinstall = function(add) { | ||
var pkg = require('./package.json'); | ||
|
||
if (add) { | ||
if (!pkg.scripts) pkg.scripts = {}; | ||
pkg.scripts.postinstall = 'node setup.js test'; | ||
} else if (pkg.scripts && pkg.scripts.postinstall) { | ||
delete pkg.scripts.postinstall; | ||
} | ||
|
||
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | ||
}; | ||
|
||
switch (mode) { | ||
// Remove `.postinstall` script to prevent stupid npm bugs. | ||
case 'prepublish': | ||
togglePostinstall(false); | ||
execute(getBinaryPath('coffee'), '-o lib/ src/'); | ||
break; | ||
|
||
// Bring back `.postinstall` script. | ||
case 'postpublish': | ||
togglePostinstall(true); | ||
break; | ||
|
||
// Compile coffeescript for git users. | ||
case 'postinstall': | ||
fsExists(sysPath.join(__dirname, 'lib'), function(exists) { | ||
if (exists) return; | ||
execute(getBinaryPath('coffee'), '-o lib/ src/'); | ||
}); | ||
break; | ||
|
||
// Run tests. | ||
case 'test': | ||
execute( | ||
getBinaryPath('mocha'), | ||
'--compilers coffee:coffee-script --require test/common.js --colors' | ||
); | ||
break; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
fs = require "fs" | ||
swig = require 'swig' | ||
sysPath = require 'path' | ||
|
||
module.exports = class SwigCompiler | ||
brunchPlugin: yes | ||
type: 'template' | ||
extension: 'html' | ||
pattern: /(\.(html|swig))$/ | ||
|
||
compile: (data, path, callback) -> | ||
try | ||
filename = sysPath.basename(path).split(".")[0] | ||
result = "module.exports = swig.compile(#{JSON.stringify(data)}, { filename: '#{filename}'});"; | ||
catch err | ||
error = err | ||
finally | ||
callback error, result | ||
|
||
include: [ | ||
(sysPath.join __dirname, '..', 'vendor', | ||
'swig.pack.min.js') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
global.expect = require('chai').expect; | ||
global.Plugin = require('../lib/index'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
sysPath = require('path') | ||
swig = require('swig') | ||
|
||
describe 'Plugin', -> | ||
|
||
plugin = null | ||
|
||
beforeEach -> | ||
plugin = new Plugin(paths: root: '.'); | ||
|
||
it 'should be an object', -> | ||
expect(plugin).to.be.ok | ||
|
||
it 'should has #compile method', -> | ||
expect(plugin.compile).to.be.an.instanceof(Function) | ||
|
||
it 'should compile and produce valid result', (done)-> | ||
content = 'Hi {{name}}!' | ||
expected = 'Hi Mark!' | ||
plugin.compile content, 'main', (error, data)-> | ||
expect(error).not.to.be.ok | ||
tmpl = eval(data) | ||
expect(tmpl(name: 'Mark')).to.equal(expected) | ||
done() |
Large diffs are not rendered by default.
Oops, something went wrong.