Skip to content

Commit

Permalink
Release 0.16.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Oct 24, 2011
1 parent 4ef0bf9 commit ec7ad0e
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 13 deletions.
8 changes: 8 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

0.16.3 / 2011-10-24
==================

* Added: allow leading space for conditional comments
* Added quick implementation of a switch statement
* Fixed parens in mixin args. Closes #380
* Fixed: include files with a .jade extension as jade files

0.16.2 / 2011-09-30
==================

Expand Down
190 changes: 180 additions & 10 deletions jade.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,39 @@ Compiler.prototype = {
return this['visit' + name](node);
},

/**
* Visit case `node`.
*
* @param {Literal} node
* @api public
*/

visitCase: function(node){
var _ = this.withinCase;
this.withinCase = true;
this.buf.push('switch (' + node.expr + '){');
this.visit(node.block);
this.buf.push('}');
this.withinCase = _;
},

/**
* Visit when `node`.
*
* @param {Literal} node
* @api public
*/

visitWhen: function(node){
if ('default' == node.expr) {
this.buf.push('default:');
} else {
this.buf.push('case ' + node.expr + ':');
}
this.visit(node.block);
this.buf.push(' break;');
},

/**
* Visit literal `node`.
*
Expand Down Expand Up @@ -386,8 +419,8 @@ Compiler.prototype = {

visitBlockComment: function(comment){
if (!comment.buffer) return;
if (0 == comment.val.indexOf('if')) {
this.buffer('<!--[' + comment.val + ']>');
if (0 == comment.val.trim().indexOf('if')) {
this.buffer('<!--[' + comment.val.trim() + ']>');
this.visit(comment.block);
this.buffer('<![endif]-->');
} else {
Expand Down Expand Up @@ -681,7 +714,7 @@ var Parser = require('./parser')
* Library version.
*/

exports.version = '0.16.1';
exports.version = '0.16.2';

/**
* Expose self closing tags.
Expand Down Expand Up @@ -1132,17 +1165,41 @@ Lexer.prototype = {
return this.scan(/^include +([^\n]+)/, 'include');
},

/**
* Case.
*/

case: function() {
return this.scan(/^case +([^\n]+)/, 'case');
},

/**
* When.
*/

when: function() {
return this.scan(/^when +([^:\n]+)/, 'when');
},

/**
* Default.
*/

default: function() {
return this.scan(/^default */, 'default');
},

/**
* Assignment.
*/

assignment: function() {
var captures;
if (captures = /^(\w+) += *([^\n]+)/.exec(this.input)) {
if (captures = /^(\w+) += *([^;\n]+)( *;? *)/.exec(this.input)) {
this.consume(captures[0].length);
var name = captures[1]
, val = captures[2];
return this.tok('code', 'var ' + name + ' = (' + val + ')');
return this.tok('code', 'var ' + name + ' = (' + val + ');');
}
},

Expand All @@ -1152,7 +1209,7 @@ Lexer.prototype = {

mixin: function(){
var captures;
if (captures = /^mixin +([-\w]+)(?:\(([^\)]+)\))?/.exec(this.input)) {
if (captures = /^mixin +([-\w]+)(?:\((.*)\))?/.exec(this.input)) {
this.consume(captures[0].length);
var tok = this.tok('mixin', captures[1]);
tok.args = captures[2];
Expand Down Expand Up @@ -1475,6 +1532,9 @@ Lexer.prototype = {
|| this.eos()
|| this.pipelessText()
|| this.doctype()
|| this.case()
|| this.when()
|| this.default()
|| this.extends()
|| this.block()
|| this.include()
Expand Down Expand Up @@ -1638,6 +1698,57 @@ Block.prototype.lastBlock = function(){

}); // module: nodes/block.js

require.register("nodes/case.js", function(module, exports, require){

/*!
* Jade - nodes - Case
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/

/**
* Module dependencies.
*/

var Node = require('./node');

/**
* Initialize a new `Case` with `expr`.
*
* @param {String} expr
* @api public
*/

var Case = exports = module.exports = function Case(expr, block){
this.expr = expr;
this.block = block;
};

/**
* Inherit from `Node`.
*/

Case.prototype = new Node;
Case.prototype.constructor = Case;


var When = exports.When = function When(expr, block){
this.expr = expr;
this.block = block;
this.debug = false;
};

/**
* Inherit from `Node`.
*/

When.prototype = new Node;
When.prototype.constructor = When;



}); // module: nodes/case.js

require.register("nodes/code.js", function(module, exports, require){

/*!
Expand Down Expand Up @@ -1841,6 +1952,7 @@ exports.Node = require('./node');
exports.Tag = require('./tag');
exports.Code = require('./code');
exports.Each = require('./each');
exports.Case = require('./case');
exports.Text = require('./text');
exports.Block = require('./block');
exports.Mixin = require('./mixin');
Expand Down Expand Up @@ -1874,7 +1986,9 @@ var Node = require('./node');
*/

var Literal = module.exports = function Literal(str) {
this.str = str;
this.str = str
.replace(/\n/g, "\\n")
.replace(/'/g, "\\'");
};

/**
Expand Down Expand Up @@ -2271,6 +2385,12 @@ Parser.prototype = {
return this.parseMixin();
case 'block':
return this.parseBlock();
case 'case':
return this.parseCase();
case 'when':
return this.parseWhen();
case 'default':
return this.parseDefault();
case 'extends':
return this.parseExtends();
case 'include':
Expand Down Expand Up @@ -2308,7 +2428,51 @@ Parser.prototype = {
node.line = this.line();
return node;
},

/**
* ':' expr
* | block
*/

parseBlockExpansion: function(){
if (':' == this.peek().type) {
this.advance();
return new nodes.Block(this.parseExpr());
} else {
return this.block();
}
},

/**
* case
*/

parseCase: function(){
var val = this.expect('case').val
, node = new nodes.Case(val);
node.line = this.line();
node.block = this.block();
return node;
},

/**
* when
*/

parseWhen: function(){
var val = this.expect('when').val
return new nodes.Case.When(val, this.parseBlockExpansion());
},

/**
* default
*/

parseDefault: function(){
this.expect('default');
return new nodes.Case.When('default', this.parseBlockExpansion());
},

/**
* code
*/
Expand Down Expand Up @@ -2398,8 +2562,9 @@ Parser.prototype = {

parseEach: function(){
var tok = this.expect('each')
, node = new nodes.Each(tok.code, tok.val, tok.key, this.block());
, node = new nodes.Each(tok.code, tok.val, tok.key);
node.line = this.line();
node.block = this.block();
return node;
},

Expand Down Expand Up @@ -2461,14 +2626,19 @@ Parser.prototype = {
if (!this.filename)
throw new Error('the "filename" option is required to use includes');

// no extension
if (!~basename(path).indexOf('.')) {
path += '.jade';
}

// non-jade
if (~basename(path).indexOf('.')) {
if ('.jade' != path.substr(-5)) {
var path = join(dir, path)
, str = fs.readFileSync(path, 'utf8');
return new nodes.Literal(str);
}

var path = join(dir, path + '.jade')
var path = join(dir, path)
, str = fs.readFileSync(path, 'utf8')
, parser = new Parser(str, path, this.options);

Expand Down
2 changes: 1 addition & 1 deletion jade.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/jade.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var Parser = require('./parser')
* Library version.
*/

exports.version = '0.16.2';
exports.version = '0.16.3';

/**
* Expose self closing tags.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jade",
"description": "Jade template engine",
"version": "0.16.2",
"version": "0.16.3",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"repository": "git://github.com/visionmedia/jade",
"main": "./index.js",
Expand Down

0 comments on commit ec7ad0e

Please sign in to comment.