Permalink
Browse files

Add coffeescript filter

  • Loading branch information...
1 parent e4eae41 commit be87cb987c573b0a715293e5c10e9011c6a93693 @mirhampt mirhampt committed with tj Oct 19, 2010
Showing with 26 additions and 0 deletions.
  1. +1 −0 Readme.md
  2. +10 −0 lib/filters.js
  3. +15 −0 test/filters.test.js
View
@@ -25,6 +25,7 @@
- :markdown must have [markdown-js](http://github.com/evilstreak/markdown-js) installed or [node-discount](http://github.com/visionmedia/node-discount)
- :cdata
- :javascript
+ - :coffeescript must have [coffee-script](http://jashkenas.github.com/coffee-script/) installed
- [TextMate Bundle](http://github.com/miksago/jade-tmbundle)
- [Screencasts](http://tjholowaychuk.com/post/1004255394/jade-screencast-template-engine-for-nodejs)
View
@@ -56,5 +56,15 @@ module.exports = {
return (md.toHTML
? md.toHTML(str)
: md.parse(str)).replace(/\n/g, '\\n').replace(/'/g,''');
+ },
+
+ /**
+ * Transform coffeescript to javascript.
+ */
+
+ coffeescript: function(str){
+ str = str.replace(/\\n/g, '\n');
+ var js = require('coffee-script').compile(str).replace(/\n/g, '\\n');
+ return '<script type="text/javascript">\\n' + js + '</script>';
}
};
View
@@ -90,6 +90,21 @@ module.exports = {
'<style>.class {\n width: 20px;\n}\n</style>',
render(':less\n | .class { width: 10px * 2 }'));
},
+
+ 'test :coffeescript filter': function(assert){
+ var js = [
+ '(function() {',
+ ' var square;',
+ ' square = function(x) {',
+ ' return x * x;',
+ ' };',
+ '})();'
+ ].join('\n');
+
+ assert.equal(
+ '<script type="text/javascript">\n' + js + '\n</script>',
+ render(':coffeescript\n | square = (x) ->\n | x * x'));
+ },
'test parse tree': function(assert){
var str = [

0 comments on commit be87cb9

Please sign in to comment.