Skip to content

Commit

Permalink
fix conflict in examples file
Browse files Browse the repository at this point in the history
  • Loading branch information
jairodemorais committed Jul 17, 2012
2 parents c731363 + 446ad26 commit 76bee75
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 278 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: node_js
node_js:
- 0.4
- 0.6
- 0.8
notifications:
email:
- jdemorais@linkedin.com
Expand Down
88 changes: 2 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,7 @@
Dust [![Build Status](https://secure.travis-ci.org/linkedin/dustjs.png)](http://travis-ci.org/linkedin/dustjs)
====

Demo & Guide
------------
Extensive docs and a full demo are available at <http://linkedin.github.com/dustjs/>

This is the LinkedIn fork of Dust.

Highlights!
----

Use Dust if you want these things:

* async/streaming operation
* browser/node compatibility
* extended Mustache/ctemplate syntax
* clean, low-level API
* [high performance](http://akdubya.github.com/dustjs/benchmark/index.html)
* composable templates


This is the LinkedIn fork of dust.js
====================================

Details in the blog post : http://engineering.linkedin.com/frontend/leaving-jsps-dust-moving-linkedin-dustjs-client-side-templates

We will gradually be extending this library with helper functions and bug fixes.

Current LinkedIn additions include:
--------------------------

* Fix to peg.js to print the line and column number for syntax errors in dust templates
* Fix to support > node0.4
* Addition of jasmine test suite, BDD with dust.js
* There are cases of rendering logic that are best done in templates. @if helper that relies entirely on the js eval for expression evaluation, The perf results are here: <http://jsperf.com/dust-if>. We intend to replace the slow js eval with a expression parser soon
* Section index for lists of maps stored in the dust context for ease of writing simple logic in templates
* Section size for lists of maps stored in the dust context for ease of writing simple logic in templates
* Automated Travis CI integration, jasmine for BDD, code coverage report
* Extend grammar to relax whitespace/eol
* Add support for rhino in the dust core
* improve compile times by 10X with changes to how we use peg parser
* Extend filters for JSON.stringify and JSON.parse
* logic helpers for select/ switch
* Support numbers in dust inline params
* Extend partials to support inline params
* Support for array references, hence list elements can be accessed via the [] notation
* Support dynamic blocks, similar to dynamic partials
* Add pipe support for node
* Documentation/wiki on the best practices for using dustjs


Installation
------------

For Linkedin Dustjs

$ npm install dustjs-linkedin

To render compiled templates in the browser:

<script src="dust-core-1.0.0.min.js"></script>

To compile a template on the command line, use the dustc command.
Its syntax is:

dustc [{-n|--name}=<template_name>] {inputfilename|-} [<outputfilename>]

For example, to compile a template on the command line and have it
registered under the same name as the source file:

$ dustc template.html

You can customize the name under which the template is registered:

$ dustc --name=mytemplate template.html

Running Tests
------------

To run tests:

$ make test

To generate code coverage report:

$ npm install cover -g
$ make coverage

To view HTML test coverage report:

$ open cover_html/index.html
Read more here : <http://linkedin.github.com/dustjs/>
30 changes: 23 additions & 7 deletions lib/dust-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ function isSelect(context) {

function filter(chunk, context, bodies, params, filter) {
var params = params || {},
actual, expected;
actual,
expected;
if (params.key) {
actual = context.get(params.key);
actual = helpers.tap(params.key, chunk, context);
} else if (isSelect(context)) {
actual = context.current().value;
actual = context.current().selectKey;
if (context.current().isResolved) {
filter = function() { return false; };
}
Expand Down Expand Up @@ -91,6 +92,14 @@ var helpers = {
return output;
},

/**
if helper
@param cond, either a string literal value or a dust reference
a string literal value, is enclosed in double quotes, e.g. cond="2>3"
a dust reference is also enclosed in double quotes, e.g. cond="'{val}'' > 3"
cond argument should evaluate to a valid javascript expression
**/

"if": function( chunk, context, bodies, params ){
if( params && params.cond ){
var cond = params.cond;
Expand All @@ -110,11 +119,18 @@ var helpers = {
return chunk;
},

/**
select/eq/lt/lte/gt/gte/default helper
@param key, either a string literal value or a dust reference
a string literal value, is enclosed in double quotes, e.g. key="foo"
a dust reference may or may not be enclosed in double quotes, e.g. key="{val}" and key=val are both valid
@param type (optiona), supported types are number, boolean, string, date, context, defaults to string
**/
select: function(chunk, context, bodies, params) {
if( params && params.key){
var key = params.key;
key = this.tap(key, chunk, context);
return chunk.render(bodies.block, context.push({ isSelect: true, isResolved: false, value: context.get(key) }));
// returns given input as output, if the input is not a dust reference, else does a context lookup
var key = this.tap(params.key, chunk, context);
return chunk.render(bodies.block, context.push({ isSelect: true, isResolved: false, selectKey: key }));
}
// no key
else {
Expand Down Expand Up @@ -143,7 +159,7 @@ var helpers = {
return filter(chunk, context, bodies, params, function(expected, actual) { return actual >= expected; });
},

"else": function(chunk, context, bodies, params) {
"default": function(chunk, context, bodies, params) {
return filter(chunk, context, bodies, params, function(expected, actual) { return true; });
}
};
Expand Down
30 changes: 14 additions & 16 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Dust original Unit tests
Dust core unit-tests
------------------------
This test are developed to be run with nodejs,
so if you want to run them you should execute this command in the terminal: "node test/server.js"
core tests run on node, use the following command

Dust Unit tests using jasmine
-----------------------------
node test/server.js

How to run the unit-tests with jasmine?
Dust unit-tests using jasmine
-----------------------------

In the current distribution of dust, we have unit tests in Jasmine for both the client and the nodejs version.
In the current distribution of dust, we have unit tests in jasmine for both the client and the nodejs version.
If you want to run the client version just open the html page called specRunner.html located in

test/jasmine-test/client/specRunner.html
Expand All @@ -17,22 +16,22 @@ Pre-requisites for tests on node server version:
----------------------------------
* install nodejs 0.6 or greater
* install npm
* install Jasmine test framework : npm install -g jasmine-node
* install jasmine test framework : npm install -g jasmine-node

In order to run the node.js version of dust, run this command in the terminal

node test/jasmine-test/server/specRunner.js


With make
Run tests with make
-------------------
* original unit tests:
* core unit tests:
make test

* jasmine unit test
make jasmine

Note: the above commands has to be executed in the project root folder.
Note: the above commands has to be run in the project root folder.

Code coverage report
-----------------------------
Expand All @@ -43,16 +42,15 @@ We are using a tool called node-cover, it can be installed by npm with the follo

Once you have installed cover, you can use it to generate the code coverage results

Execute Cover
Run Cover
--------------

cover run test/jasmine-test/server/specRunner.js // executes all the test and creates a folder with results.
cover run test/jasmine-test/server/specRunner.js // runs all the test and creates a folder with results.

cover report // shows you a table with % code covered, missed lines, #lines, %blocks, missed blocks and # blocks.

cover report html //creates a folder the location where you executed the command and the report is in html.
cover report html //creates a folder the location where you run the command and the report is in html.

The results are very complete, it creates one html file per js file used by the test.
The lines that are not covered are shown on red.
Cover creates one html file per js file used by the test. The lines that are not covered are shown on red.


Loading

0 comments on commit 76bee75

Please sign in to comment.