Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can now call functions with static arguments from your Mustache templ…
…ate! Yay. Also: renovated parsing.js to use dicts instead of lists.
- Loading branch information
Showing
14 changed files
with
200 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,2 +1,4 @@ | |||
.DS_Store | .DS_Store | ||
test/spec/ | test/spec/ | ||
notes.txt | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,62 @@ | |||
var fs = require('fs'), | |||
path = require('path'), | |||
amulet = require('../lib/amulet'), | |||
Stream = require('stream').Stream, | |||
Buffer = require('buffer').Buffer, | |||
yaml2json = require('./lib').yaml2json; | |||
|
|||
var ignore_whitespace = true; | |||
console.log('ignore_whitespace = ' + ignore_whitespace); | |||
|
|||
String.prototype.capitalize = function() { | |||
return this.charAt(0).toUpperCase() + this.slice(1); | |||
}; | |||
String.prototype.titleize = function() { | |||
var result = []; | |||
var parts = this.split(" "); | |||
for (i in parts) { | |||
result.push(capitalize(parts[i])); | |||
} | |||
return result.join(" "); | |||
}; | |||
String.prototype.humanize = function() { | |||
return titleize(this.replace('_', ' ')); | |||
}; | |||
String.prototype.equals = function(test) { | |||
return this.valueOf() === test; | |||
}; | |||
|
|||
yaml2json('extended_spec.yaml', 'extended_spec.json', function() { | |||
var tests = JSON.parse(fs.readFileSync('extended_spec.json')).tests; | |||
var i = 0; | |||
(function next() { | |||
if (i < tests.length) { | |||
var spec = tests[i++], context; | |||
process.stdout.write(' Spec: ' + spec.description + ' '); | |||
amulet.parseTemplate(spec.description, spec.template); | |||
try { | |||
context = eval('(' + spec.context + ')'); | |||
} | |||
catch (e) { | |||
console.error('Reading context failed', e, spec.context); | |||
} | |||
|
|||
amulet.renderString(spec.description, context, function(err, output) { | |||
if ( | |||
output == spec.output || | |||
(ignore_whitespace && output.replace(/\s+/g, '') == spec.output.replace(/\s+/g, '')) | |||
) { | |||
process.stdout.write('[Success]\n'); | |||
} | |||
else { | |||
process.stdout.write('[Failed]\n Expected:\n' + spec.output + '\n Actual:\n' + output + '\n'); | |||
} | |||
|
|||
next(); | |||
}); | |||
} | |||
else { | |||
console.log('Done.'); | |||
} | |||
})(); | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
{"tests": [{"output": "<span color=\"green\">Thanks for paying $314.15!</span>\n", "description": "function calls no. 1", "context": "{ status: 'paid', amount: '$314.15' }\n", "template": "{{#status.equals('owed')}}\n <span color=\"red\">You owe {{amount}}</span>\n{{/}}\n{{#status.equals('paid')}}\n <span color=\"green\">Thanks for paying {{amount}}!</span>\n{{/}}\n"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
tests: | |||
- description: function calls no. 1 | |||
context: | | |||
{ status: 'paid', amount: '$314.15' } | |||
template: | | |||
{{#status.equals('owed')}} | |||
<span color="red">You owe {{amount}}</span> | |||
{{/}} | |||
{{#status.equals('paid')}} | |||
<span color="green">Thanks for paying {{amount}}!</span> | |||
{{/}} | |||
output: | | |||
<span color="green">Thanks for paying $314.15!</span> |
Oops, something went wrong.