Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #805 from slang800/remove_AST_filters

removing ast filters closes #790
  • Loading branch information...
commit 8376e068eb939beab3440da76daa420db5a01679 2 parents 343d192 + d148caf
TJ Holowaychuk tj authored
1  Readme.md
View
@@ -65,7 +65,6 @@
- transparent iteration over objects, arrays, and even non-enumerables via `each`
- block comments
- no tag prefix
- - AST filters
- filters
- :stylus must have [stylus](http://github.com/LearnBoost/stylus) installed
- :less must have [less.js](http://github.com/cloudhead/less.js) installed
8 examples/nested-filters.jade
View
@@ -1,8 +0,0 @@
-stylesheets:
- stylesheet('/path/to/a.css')
- stylesheet('/path/to/b.css')
- stylesheet('/path/to/c.css')
- javascripts:
- js('/path/to/a.js')
- js('/path/to/b.js')
- js('/path/to/c.js')
73 examples/nested-filters.js
View
@@ -1,73 +0,0 @@
-
-/**
- * Module dependencies.
- */
-
-var jade = require('./../lib/jade'),
- nodes = jade.nodes,
- Compiler = jade.Compiler;
-
-jade.renderFile(__dirname + '/nested-filters.jade', function(err, html){
- if (err) throw err;
- console.log(html);
-});
-
-// :javascripts
-
-jade.filters.javascripts = function(block, compiler){
- return new JavascriptsVisitor(block, compiler.options).compile();
-};
-
-function JavascriptsVisitor(node, options) {
- Compiler.call(this, node, options);
-}
-
-// Inherit from Compiler
-
-JavascriptsVisitor.prototype.__proto__ = Compiler.prototype;
-
-// Overwrite visitTag method
-
-JavascriptsVisitor.prototype.visitTag = function(node){
- var parent = Compiler.prototype.visitTag;
- switch (node.name) {
- case 'js':
- var script = new nodes.Tag('script');
- script.setAttribute('type', "'text/javascript'");
- script.setAttribute('src', "'" + node.attrs[0].name + "'")
- parent.call(this, script);
- break;
- default:
- parent.call(this, node);
- }
-};
-
-// :stylesheets
-
-jade.filters.stylesheets = function(block, compiler){
- return new StylesheetsVisitor(block, compiler.options).compile();
-};
-
-function StylesheetsVisitor(node, options) {
- Compiler.call(this, node, options);
-}
-
-// Inherit from Compiler
-
-StylesheetsVisitor.prototype.__proto__ = Compiler.prototype;
-
-// Overwrite visitTag method
-
-StylesheetsVisitor.prototype.visitTag = function(node){
- var parent = Compiler.prototype.visitTag;
- switch (node.name) {
- case 'stylesheet':
- var style = new nodes.Tag('link');
- style.setAttribute('rel', "'stylesheet'");
- style.setAttribute('href', "'" + node.attrs[0].name + "'")
- parent.call(this, style);
- break;
- default:
- parent.call(this, node);
- }
-};
24 lib/compiler.js
View
@@ -409,22 +409,14 @@ Compiler.prototype = {
var fn = filters[filter.name];
// unknown filter
- if (!fn) {
- if (filter.isASTFilter) {
- throw new Error('unknown ast filter "' + filter.name + ':"');
- } else {
- throw new Error('unknown filter ":' + filter.name + '"');
- }
- }
-
- if (filter.isASTFilter) {
- this.buf.push(fn(filter.block, this, filter.attrs));
- } else {
- var text = filter.block.nodes.map(function(node){ return node.val }).join('\n');
- filter.attrs = filter.attrs || {};
- filter.attrs.filename = this.options.filename;
- this.buffer(utils.text(fn(text, filter.attrs)));
- }
+ if (!fn) throw new Error('unknown filter ":' + filter.name + '"');
+
+ var text = filter.block.nodes.map(
+ function(node){ return node.val; }
+ ).join('\n');
+ filter.attrs = filter.attrs || {};
+ filter.attrs.filename = this.options.filename;
+ this.buffer(utils.text(fn(text, filter.attrs)));
},
/**
3  lib/nodes/filter.js
View
@@ -13,7 +13,7 @@ var Node = require('./node')
, Block = require('./block');
/**
- * Initialize a `Filter` node with the given
+ * Initialize a `Filter` node with the given
* filter `name` and `block`.
*
* @param {String} name
@@ -25,7 +25,6 @@ var Filter = module.exports = function Filter(name, block, attrs) {
this.name = name;
this.block = block;
this.attrs = attrs;
- this.isASTFilter = !block.nodes.every(function(node){ return node.isText });
};
/**
22 lib/parser.js
View
@@ -361,23 +361,6 @@ Parser.prototype = {
},
/**
- * tag ':' attrs? block
- */
-
- parseASTFilter: function(){
- var block
- , tok = this.expect('tag')
- , attrs = this.accept('attrs');
-
- this.expect(':');
- block = this.block();
-
- var node = new nodes.Filter(tok.val, block, attrs && attrs.attrs);
- node.line = this.line();
- return node;
- },
-
- /**
* each block
*/
@@ -607,11 +590,6 @@ Parser.prototype = {
// ast-filter look-ahead
var i = 2;
if ('attrs' == this.lookahead(i).type) ++i;
- if (':' == this.lookahead(i).type) {
- if ('indent' == this.lookahead(++i).type) {
- return this.parseASTFilter();
- }
- }
var tok = this.advance()
, tag = new nodes.Tag(tok.val);
Please sign in to comment.
Something went wrong with that request. Please try again.