Permalink
Browse files

Merge branch 'master' of https://github.com/linkedin/dustjs

  • Loading branch information...
2 parents 4e5b39f + 7c87e28 commit ee5d228bda73857991cc9d81237fb00ed4f6452e Veena Basavaraj committed Apr 23, 2012
View
9 .travis.yml
@@ -0,0 +1,9 @@
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
+ - 0.7 # development version of 0.8, may be unstable
+notifications:
+ email:
+ - jdemorais@linkedin.com
+ - vbasavaraj@linkedin.com
View
4 README.md
@@ -1,4 +1,4 @@
-Dust
+Dust [![Build Status](https://secure.travis-ci.org/linkedin/dustjs.png)](http://travis-ci.org/linkedin/dustjs)
====
This is the LinkedIn fork of dust.js
@@ -248,4 +248,4 @@ Dynamic Partials
The name of the partial can be determined at render time. Primarily useful when a partial is loaded based on the ab-test key.
-{>"/path/{abkey}.tl"/}
+{>"/path/{abkey}.tl"/}
View
74 dist/dust-core-0.3.0.js → dist/dust-core-0.4.0.js
@@ -1,5 +1,5 @@
//
-// Dust - Asynchronous Templating v0.3.0
+// Dust - Asynchronous Templating v0.4.0
// http://akdubya.github.com/dustjs
//
// Copyright (c) 2010, Aleksander Williams
@@ -157,6 +157,12 @@ Context.prototype.getPath = function(cur, down) {
};
Context.prototype.push = function(head, idx, len) {
+ if( head ){
+ // loop index for a block section
+ head['$idx'] = idx;
+ // loop size for a block section
+ head['$len'] = len;
+ }
return new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks);
};
@@ -503,7 +509,7 @@ dust.escapeJs = function(s) {
if (typeof exports !== "undefined") {
dust.helpers = require("./dust-helpers").helpers;
- if (typeof process !== "undefined") {
+ if (typeof process !== "undefined" && typeof window === "undefined") {
require('./server')(dust);
}
module.exports = dust;
@@ -522,78 +528,16 @@ var helpers = {
idx: function(chunk, context, bodies) {
return bodies.block(chunk, context.push(context.stack.index));
},
- /*
- * Dust can only do simple string interpolation ex:
- * {#context foo="{bar}"} and not {#context foo="{bar.baz}"}. Boo!
- * This prevents us from passing {bar.baz} into a context as a param.
- * So, when we need lookup baz by crawling out from the curent context...
- * usage: {@lookup key="bar.baz"/}
- *
- * Note: This should be corrected in dust.
- */
- lookup: function( chunk, context, bodies, params ){
- var path = params.path.split( '.' ),
- value,
- index = 0,
- depth = path.length - 1;
-
- //Crawl up the stack and Test to see if the path exists
- ( function test( subject ){
-
- //Restart the test with the next branch
- function next() {
- subject = context.stack.tail.head;
- index = 0;
- test( subject );
- }
-
- if( subject[path[index]] ){
- subject = subject[path[index]];
- if( index < depth ) {
- if( typeof subject === "object" && subject.hasOwnProperty ) {
- //Its an object, so continue
- index += 1;
- test( subject );
- } else {
- //It's not an object,
- //and we have not reached the end of our path.
- //Test the next branch
- next();
- }
- } else {
- //we have exhausted our path and have a subject
- value = subject;
- }
- } else {
- //It dose not exist on this branch.
- next();
- }
- }( context.stack.tail.head ) );
-
- chunk.write( value );
- return chunk;
-
- },
- if: function( chunk, context, bodies, params ){
+ "if": function( chunk, context, bodies, params ){
var cond = ( params.cond );
if( params && params.cond ){
// resolve dust references in the expression
if( typeof cond === "function" ){
cond = '';
- boundary = '';
chunk.tap( function( data ){
- if( boundary !== '' && boundary[boundary.length - 1] === "{" ) {
- data = ( data === '' || data === '}' ) ? false : true;
- boundary = '';
- } else {
- boundary = data;
- }
cond += data;
- // replace the { } tokens from the cond value
- cond = cond.replace( "{", "" );
- cond = cond.replace( "}", "" );
return '';
} ).render( params.cond, context ).untap();
if( cond === '' ){
View
74 dist/dust-full-0.3.0.js → dist/dust-full-0.4.0.js
@@ -1,5 +1,5 @@
//
-// Dust - Asynchronous Templating v0.3.0
+// Dust - Asynchronous Templating v0.4.0
// http://akdubya.github.com/dustjs
//
// Copyright (c) 2010, Aleksander Williams
@@ -157,6 +157,12 @@ Context.prototype.getPath = function(cur, down) {
};
Context.prototype.push = function(head, idx, len) {
+ if( head ){
+ // loop index for a block section
+ head['$idx'] = idx;
+ // loop size for a block section
+ head['$len'] = len;
+ }
return new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks);
};
@@ -503,7 +509,7 @@ dust.escapeJs = function(s) {
if (typeof exports !== "undefined") {
dust.helpers = require("./dust-helpers").helpers;
- if (typeof process !== "undefined") {
+ if (typeof process !== "undefined" && typeof window === "undefined") {
require('./server')(dust);
}
module.exports = dust;
@@ -522,78 +528,16 @@ var helpers = {
idx: function(chunk, context, bodies) {
return bodies.block(chunk, context.push(context.stack.index));
},
- /*
- * Dust can only do simple string interpolation ex:
- * {#context foo="{bar}"} and not {#context foo="{bar.baz}"}. Boo!
- * This prevents us from passing {bar.baz} into a context as a param.
- * So, when we need lookup baz by crawling out from the curent context...
- * usage: {@lookup key="bar.baz"/}
- *
- * Note: This should be corrected in dust.
- */
- lookup: function( chunk, context, bodies, params ){
- var path = params.path.split( '.' ),
- value,
- index = 0,
- depth = path.length - 1;
-
- //Crawl up the stack and Test to see if the path exists
- ( function test( subject ){
-
- //Restart the test with the next branch
- function next() {
- subject = context.stack.tail.head;
- index = 0;
- test( subject );
- }
-
- if( subject[path[index]] ){
- subject = subject[path[index]];
- if( index < depth ) {
- if( typeof subject === "object" && subject.hasOwnProperty ) {
- //Its an object, so continue
- index += 1;
- test( subject );
- } else {
- //It's not an object,
- //and we have not reached the end of our path.
- //Test the next branch
- next();
- }
- } else {
- //we have exhausted our path and have a subject
- value = subject;
- }
- } else {
- //It dose not exist on this branch.
- next();
- }
- }( context.stack.tail.head ) );
-
- chunk.write( value );
- return chunk;
-
- },
- if: function( chunk, context, bodies, params ){
+ "if": function( chunk, context, bodies, params ){
var cond = ( params.cond );
if( params && params.cond ){
// resolve dust references in the expression
if( typeof cond === "function" ){
cond = '';
- boundary = '';
chunk.tap( function( data ){
- if( boundary !== '' && boundary[boundary.length - 1] === "{" ) {
- data = ( data === '' || data === '}' ) ? false : true;
- boundary = '';
- } else {
- boundary = data;
- }
cond += data;
- // replace the { } tokens from the cond value
- cond = cond.replace( "{", "" );
- cond = cond.replace( "}", "" );
return '';
} ).render( params.cond, context ).untap();
if( cond === '' ){
View
2 lib/dust-helpers.js
@@ -13,7 +13,7 @@ var helpers = {
return bodies.block(chunk, context.push(context.stack.index));
},
- if: function( chunk, context, bodies, params ){
+ "if": function( chunk, context, bodies, params ){
var cond = ( params.cond );
if( params && params.cond ){
View
2 lib/dust.js
@@ -501,7 +501,7 @@ dust.escapeJs = function(s) {
if (typeof exports !== "undefined") {
dust.helpers = require("./dust-helpers").helpers;
- if (typeof process !== "undefined") {
+ if (typeof process !== "undefined" && typeof window === "undefined") {
require('./server')(dust);
}
module.exports = dust;
View
2 test/jasmine-test/client/specRunner.html
@@ -15,7 +15,7 @@
<script src="../spec/renderTestSpec.js" type="text/javascript" charset="utf-8"></script>
<!-- include source files here... -->
- <script src="../../../dist/dust-full-0.3.0.js" type="text/javascript" charset="utf-8"></script>
+ <script src="../../../dist/dust-full-0.4.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
(function() {
View
8 test/jasmine-test/spec/examples.js
@@ -389,7 +389,13 @@ var dustExamples = [
expected: "<div> X exists and is 1 </div>",
message: "should test the simplest case of @if helper with else using exists /and"
},
-
+ {
+ name: "@if helper",
+ source: '{#list}{@if cond="( {$idx} == 1 )"}<div>{y}</div>{/if}{/list}',
+ context: { x : 1, list: [ { y: 'foo' }, { y: 'bar'} ]},
+ expected: "<div>bar</div>",
+ message: "should test the use of $idx in @if helper condition"
+ },
];

0 comments on commit ee5d228

Please sign in to comment.