forked from raycmorgan/Mu
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
RayMorgan
committed
Jan 26, 2010
0 parents
commit 033e607
Showing
52 changed files
with
1,075 additions
and
0 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
Mu - Mustache template compiler for Node.js | ||
=========================================== | ||
|
||
Mustache is a simply awesome template language inspired by | ||
[ctemplate](http://code.google.com/p/google-ctemplate/) and | ||
[et](http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html). | ||
|
||
Mu is a Mustache based template engine for Node.js. Mu compiles mustache | ||
templates into an extremely fast executable function. | ||
|
||
|
||
Benchmarks | ||
---------- | ||
|
||
Rendering examples/complex.html.mu 1 million times yields the following results: | ||
|
||
Ruby Mustache - 112 secs (benchmarks/rb/complex_view.rb) | ||
Mu - 24 secs (benchmarks/million_complex.js) | ||
|
||
Tested on a 2.4 GHz Intel Core 2 Duo MacBook Pro | ||
|
||
|
||
Usage (from demo.js) | ||
-------------------- | ||
|
||
var sys = require('sys'); | ||
var Mu = require('./lib/mu'); | ||
|
||
Mu.templateRoot = './examples'; | ||
|
||
var ctx = { | ||
name: "Chris", | ||
value: 10000, | ||
taxed_value: function() { | ||
return this.value - (this.value * 0.4); | ||
}, | ||
in_ca: true | ||
}; | ||
|
||
Mu.render('simple.html', ctx) | ||
.addCallback(function (output) { | ||
sys.puts(output); | ||
}) | ||
.addErrback(function (e) { | ||
sys.puts(e.stack); | ||
}); | ||
|
||
Which yields: | ||
|
||
Hello Chris | ||
You have just won $10000! | ||
Well, $6000, after taxes. | ||
|
||
|
||
Mustache Documentation | ||
---------------------- | ||
|
||
See **Tag Types** section at | ||
[http://github.com/defunkt/mustache/](http://github.com/defunkt/mustache/) | ||
for more information on supported tags. |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var sys = require('sys') | ||
posix = require('posix'), | ||
Path = require('path'); | ||
var Mu = require('../lib/mu'); | ||
|
||
Mu.templateRoot = ''; | ||
|
||
var name = Path.join(Path.dirname(__filename), "../examples/complex"); | ||
var js = posix.cat(name + '.js').wait(); | ||
|
||
js = eval('(' + js + ')'); | ||
|
||
sys.puts(name + '.html') | ||
|
||
var compiled = Mu.compile(name + '.html').wait(); | ||
|
||
sys.puts(compiled(js)); | ||
|
||
var d = new Date(); | ||
for (var i = 0; i < 1000000; i++) { | ||
compiled(js); | ||
} | ||
sys.puts("Time taken: " + ((new Date() - d) / 1000) + "secs"); |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h1>{{header}}</h1> | ||
{{#list}} | ||
<ul> | ||
{{#item}} | ||
{{#current}} | ||
<li><strong>{{name}}</strong></li> | ||
{{/current}} | ||
{{#link}} | ||
<li><a href="{{url}}">{{name}}</a></li> | ||
{{/link}} | ||
{{/item}} | ||
</ul> | ||
{{/list}} | ||
{{#empty}} | ||
<p>The list is empty.</p> | ||
{{/empty}} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib' | ||
require 'rubygems' | ||
require 'mustache' | ||
|
||
class ComplexView < Mustache | ||
self.path = File.dirname(__FILE__) | ||
|
||
def header | ||
"Colors" | ||
end | ||
|
||
def item | ||
items = [] | ||
items << { :name => 'red', :current => true, :url => '#Red' } | ||
items << { :name => 'green', :current => false, :url => '#Green' } | ||
items << { :name => 'blue', :current => false, :url => '#Blue' } | ||
items | ||
end | ||
|
||
def link | ||
not self[:current] | ||
end | ||
|
||
def list | ||
not item.empty? | ||
end | ||
|
||
def empty | ||
item.empty? | ||
end | ||
end | ||
|
||
if $0 == __FILE__ | ||
puts ComplexView.to_html | ||
|
||
d = Time.now | ||
1000000.times { | ||
ComplexView.to_html | ||
} | ||
diff = (Time.now - d) | ||
puts "Time taken: " + diff.to_s | ||
end |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var sys = require('sys'); | ||
var Mu = require('./lib/mu'); | ||
|
||
Mu.templateRoot = './examples'; | ||
|
||
var ctx = { | ||
name: "Chris", | ||
value: 10000, | ||
taxed_value: function() { | ||
return this.value - (this.value * 0.4); | ||
}, | ||
in_ca: true | ||
}; | ||
|
||
Mu.render('simple.html', ctx) | ||
.addCallback(function (output) { | ||
sys.puts(output); | ||
}) | ||
.addErrback(function (e) { | ||
sys.puts(e.stack); | ||
}); |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>{{title}}{{! just something interesting... or not... }}</h1> |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
title: function() { | ||
return "A Comedy of Errors"; | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>A Comedy of Errors</h1> |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h1>{{header}}</h1> | ||
{{#list}} | ||
<ul> | ||
{{#item}} | ||
{{#current}} | ||
<li><strong>{{name}}</strong></li> | ||
{{/current}} | ||
{{#link}} | ||
<li><a href="{{url}}">{{name}}</a></li> | ||
{{/link}} | ||
{{/item}} | ||
</ul> | ||
{{/list}} | ||
{{#empty}} | ||
<p>The list is empty.</p> | ||
{{/empty}} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
header: function() { | ||
return "Colors"; | ||
}, | ||
item: [ | ||
{name: "red", current: true, url: "#Red"}, | ||
{name: "green", current: false, url: "#Green"}, | ||
{name: "blue", current: false, url: "#Blue"} | ||
], | ||
link: function() { | ||
return this["current"] !== true; | ||
}, | ||
list: function() { | ||
return this.item.length !== 0; | ||
}, | ||
empty: function() { | ||
return this.item.length === 0; | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Colors</h1> | ||
<ul> | ||
<li><strong>red</strong></li> | ||
<li><a href="#Green">green</a></li> | ||
<li><a href="#Blue">blue</a></li> | ||
</ul> |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>First: {{title}}</h1> | ||
{{>partial.html}} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
title: "Welcome" | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1>First: Welcome</h1> | ||
<h1>Welcome</h1> | ||
Again, Welcome! |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{{=<% %>=}}* <% first %> | ||
* <% second %> | ||
<%=| |=%> | ||
* | third | | ||
|={{ }}=| | ||
* {{ fourth }} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
first: "It worked the first time.", | ||
second: "And it worked the second time.", | ||
third: "Then, surprisingly, it worked the third time.", | ||
fourth: "Fourth time also fine!." | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* It worked the first time. | ||
* And it worked the second time. | ||
|
||
* Then, surprisingly, it worked the third time. | ||
|
||
* Fourth time also fine!. |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{foo}} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{bar: 2} |
Empty file.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>{{title}}</h1> |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
title: function() { | ||
return "Bear > Shark"; | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Bear > Shark</h1> |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{#person}} | ||
Name: {{name}} | ||
{{/person}} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
person: { | ||
name: "Chris" | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
Name: Chris |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Again, {{title}}! |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>{{title}}</h1> | ||
{{>inner_partial.html}} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
title: "Welcome" | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Welcome</h1> | ||
Again, Welcome! |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{ name }} | ||
{{ description }} | ||
|
||
{{#terms}} | ||
{{name}} | ||
{{index}} | ||
{{/terms}} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
name: 'name', | ||
description: 'desc', | ||
terms: [ | ||
{name: 't1', index: 0}, | ||
{name: 't2', index: 1}, | ||
] | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name | ||
desc | ||
|
||
t1 | ||
0 | ||
t2 | ||
1 |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{#terms}} | ||
{{name}} | ||
{{index}} | ||
{{/terms}} | ||
{{#terms}} | ||
{{name}} | ||
{{index}} | ||
{{/terms}} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
terms: [ | ||
{name: 't1', index: 0}, | ||
{name: 't2', index: 1}, | ||
] | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
t1 | ||
0 | ||
t2 | ||
1 | ||
t1 | ||
0 | ||
t2 | ||
1 |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Hello {{name}} | ||
You have just won ${{value}}! | ||
{{#in_ca}} | ||
Well, ${{ taxed_value }}, after taxes. | ||
{{/in_ca}} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
name: "Chris", | ||
value: 10000, | ||
taxed_value: function() { | ||
return this.value - (this.value * 0.4); | ||
}, | ||
in_ca: true | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Hello Chris | ||
You have just won $10000! | ||
Well, $6000, after taxes. |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{greeting}}, {{name}}! |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
name: "Joe", | ||
greeting: "Welcome" | ||
} |
Oops, something went wrong.