Skip to content

Commit

Permalink
Support &attributes in the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Forbes Lindesay committed Dec 12, 2013
1 parent 28c908c commit 94f88c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/nodes/attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var Block = require('./block');

var Attrs = module.exports = function Attrs() {
this.attrs = [];
this.attributeBlocks = [];
};

// Inherit from `Node`.
Expand Down Expand Up @@ -66,3 +67,7 @@ Attrs.prototype.getAttribute = function(name){
}
}
};

Attrs.prototype.addAttributes = function (src) {
this.attributeBlocks.push(src);
};
1 change: 1 addition & 0 deletions lib/nodes/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var Mixin = module.exports = function Mixin(name, args, block, call){
this.args = args;
this.block = block;
this.attrs = [];
this.attributeBlocks = [];
this.call = call;
};

Expand Down
11 changes: 6 additions & 5 deletions lib/nodes/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var inlineTags = require('../inline-tags');
var Tag = module.exports = function Tag(name, block) {
this.name = name;
this.attrs = [];
this.attributeBlocks = [];
this.block = block || new Block;
};

Expand Down Expand Up @@ -65,13 +66,13 @@ Tag.prototype.canInline = function(){
if (node.isBlock) return node.nodes.every(isInline);
return node.isText || (node.isInline && node.isInline());
}

// Empty tag
if (!nodes.length) return true;

// Text-only or inline-only tag
if (1 == nodes.length) return isInline(nodes[0]);

// Multi-line inline-only tag
if (this.block.nodes.every(isInline)) {
for (var i = 1, len = nodes.length; i < len; ++i) {
Expand All @@ -80,7 +81,7 @@ Tag.prototype.canInline = function(){
}
return true;
}

// Mixed tag
return false;
};
};
4 changes: 4 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ Parser.prototype = {
tag.setAttribute(name, val, escaped[name]);
}
continue;
case '&attributes':
var tok = this.advance();
tag.addAttributes(tok.val);
break;
default:
break out;
}
Expand Down

0 comments on commit 94f88c2

Please sign in to comment.