Permalink
Browse files

Add special __date object to context if the object is a date. This al…

…lows custom date formatters as functions
  • Loading branch information...
1 parent e3c9242 commit cf01781237c4f2fd748ba20dac04024076f583e6 @raycmorgan committed Oct 4, 2012
Showing with 17 additions and 3 deletions.
  1. +6 −2 lib/mu/renderer.js
  2. +1 −1 package.json
  3. +1 −0 test/examples/date.html
  4. +7 −0 test/examples/date.js
  5. +1 −0 test/examples/date.txt
  6. +1 −0 test/run_examples_test.js
View
@@ -156,8 +156,12 @@ function smashContext(context) {
for (var i = 0; i < context.length; i++) {
var level = context[i];
- for (var k in level) {
- obj[k] = level[k];
+ if (level instanceof Date) {
+ obj.__date = level;
+ } else {
+ for (var k in level) {
+ obj[k] = level[k];
+ }
}
}
View
@@ -1,7 +1,7 @@
{ "name": "mu2"
, "description": "A Mustache template engine for Node.js"
, "keywords": ["template", "mustache"]
-, "version" : "0.5.16"
+, "version" : "0.5.17"
, "homepage": "http://github.com/raycmorgan/mu"
, "author" : "RayMorgan <ray@rumgr.com>"
, "main" : "lib/mu"
View
@@ -0,0 +1 @@
+Date {{#today}}{{year}}{{/today}}
View
@@ -0,0 +1,7 @@
+{
+ today: new Date(2012, 0, 1),
+
+ year: function () {
+ return this.__date.getFullYear();
+ }
+}
View
@@ -0,0 +1 @@
+Date 2012
@@ -11,6 +11,7 @@ mu.root = path.join(__dirname, 'examples');
'carriage_return',
'comments',
'complex',
+ 'date',
'deep_partial',
// 'delimiters',
'error_not_found',

0 comments on commit cf01781

Please sign in to comment.