mustache 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.md +13 -1
- data/README.md +7 -0
- data/Rakefile +4 -1
- data/benchmarks/complex.haml +10 -0
- data/benchmarks/speed.rb +29 -6
- data/contrib/mustache.vim +69 -0
- data/examples/comments.html +1 -1
- data/examples/double_section.html +7 -0
- data/examples/double_section.rb +14 -0
- data/lib/mustache/context.rb +2 -0
- data/lib/mustache/sinatra.rb +12 -0
- data/lib/mustache/template.rb +2 -2
- data/lib/mustache/version.rb +1 -1
- data/test/mustache_test.rb +17 -1
- metadata +7 -2
data/HISTORY.md
CHANGED
@@ -1,4 +1,16 @@
|
|
1
|
-
## 0.3.
|
1
|
+
## 0.3.2 (2009-10-19)
|
2
|
+
|
3
|
+
* Bugfix: Partials in Sinatra were using the wrong path.
|
4
|
+
|
5
|
+
## 0.3.1 (2009-10-19)
|
6
|
+
|
7
|
+
* Added mustache.vim to contrib/ (Thanks Juvenn Woo!)
|
8
|
+
* Support string keys in contexts (not just symbol keys).
|
9
|
+
* Bugfix: # and / were not permitted in tag names. Now they are.
|
10
|
+
* Bugfix: Partials in Sinatra needed to know their extension and path
|
11
|
+
* Bugfix: Using the same boolean section twice was failing
|
12
|
+
|
13
|
+
## 0.3.0 (2009-10-14)
|
2
14
|
|
3
15
|
* Set Delimiter tags are now supported. See the README
|
4
16
|
* Improved error message when an enumerable section did not return all
|
data/README.md
CHANGED
@@ -364,6 +364,13 @@ An example Sinatra application is also provided:
|
|
364
364
|
<http://github.com/defunkt/mustache-sinatra-example>
|
365
365
|
|
366
366
|
|
367
|
+
Vim
|
368
|
+
---
|
369
|
+
|
370
|
+
Thanks to [Juvenn Woo](http://github.com/juvenn) for mustache.vim. It
|
371
|
+
is included under the contrib/ directory.
|
372
|
+
|
373
|
+
|
367
374
|
Installation
|
368
375
|
------------
|
369
376
|
|
data/Rakefile
CHANGED
@@ -9,6 +9,9 @@ Rake::TestTask.new do |t|
|
|
9
9
|
t.verbose = false
|
10
10
|
end
|
11
11
|
|
12
|
+
desc "Build a gem"
|
13
|
+
task :gem => [ :gemspec, :build ]
|
14
|
+
|
12
15
|
desc "Launch Kicker (like autotest)"
|
13
16
|
task :kicker do
|
14
17
|
puts "Kicking... (ctrl+c to cancel)"
|
@@ -40,7 +43,7 @@ rescue LoadError
|
|
40
43
|
end
|
41
44
|
|
42
45
|
desc "Push a new version to Gemcutter"
|
43
|
-
task :publish => [ :gemspec, :build ] do
|
46
|
+
task :publish => [ :test, :gemspec, :build ] do
|
44
47
|
system "git tag v#{Mustache::Version}"
|
45
48
|
system "git push origin v#{Mustache::Version}"
|
46
49
|
system "gem push pkg/mustache-#{Mustache::Version}.gem"
|
data/benchmarks/speed.rb
CHANGED
@@ -11,17 +11,40 @@ template = File.read(File.dirname(__FILE__) + '/complex.erb')
|
|
11
11
|
|
12
12
|
unless ENV['NOERB']
|
13
13
|
erb = ERB.new(template)
|
14
|
-
|
15
|
-
|
14
|
+
scope = ComplexView.new.send(:binding)
|
15
|
+
bench 'ERB w/ caching' do
|
16
|
+
erb.result(scope)
|
16
17
|
end
|
17
18
|
|
18
19
|
unless ENV['CACHED']
|
19
|
-
|
20
|
-
|
20
|
+
scope = ComplexView.new.send(:binding)
|
21
|
+
bench 'ERB w/o caching' do
|
22
|
+
ERB.new(template).result(scope)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
27
|
+
|
28
|
+
## haml
|
29
|
+
require 'haml'
|
30
|
+
template = File.read(File.dirname(__FILE__) + '/complex.haml')
|
31
|
+
|
32
|
+
unless ENV['NOHAML']
|
33
|
+
haml = Haml::Engine.new(template)
|
34
|
+
scope = ComplexView.new.send(:binding)
|
35
|
+
bench 'HAML w/ caching' do
|
36
|
+
haml.render(scope)
|
37
|
+
end
|
38
|
+
|
39
|
+
unless ENV['CACHED']
|
40
|
+
scope = ComplexView.new.send(:binding)
|
41
|
+
bench 'HAML w/o caching' do
|
42
|
+
Haml::Engine.new(template).render(scope)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
25
48
|
## mustache
|
26
49
|
tpl = ComplexView.new
|
27
50
|
tpl.template
|
@@ -37,14 +60,14 @@ items << { :name => 'blue', :current => false, :url => '#Blue' }
|
|
37
60
|
|
38
61
|
tpl[:item] = items
|
39
62
|
|
40
|
-
bench '{ w/ caching' do
|
63
|
+
bench '{{ w/ caching' do
|
41
64
|
tpl.to_html
|
42
65
|
end
|
43
66
|
|
44
67
|
content = File.read(ComplexView.template_file)
|
45
68
|
|
46
69
|
unless ENV['CACHED']
|
47
|
-
bench '{ w/o caching' do
|
70
|
+
bench '{{ w/o caching' do
|
48
71
|
ctpl = ComplexView.new
|
49
72
|
ctpl.template = content
|
50
73
|
ctpl[:item] = items
|
@@ -0,0 +1,69 @@
|
|
1
|
+
" Vim syntax file
|
2
|
+
" Language: Mustache
|
3
|
+
" Maintainer: Juvenn Woo <machese@gmail.com>
|
4
|
+
" Screenshot: http://imgur.com/6F408
|
5
|
+
" Version: 1
|
6
|
+
" Last Change: 2009 Oct 15
|
7
|
+
" Remark:
|
8
|
+
" It lexically hilights embedded mustaches (exclusively) in html file.
|
9
|
+
" While it was written for Ruby-based Mustache template system, it should work for Google's C-based *ctemplate* as well as Erlang-based *et*. All of them are, AFAIK, based on the idea of ctemplate.
|
10
|
+
" References:
|
11
|
+
" [Mustache](http://github.com/defunkt/mustache)
|
12
|
+
" [ctemplate](http://code.google.com/p/google-ctemplate/)
|
13
|
+
" [ctemplate doc](http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html)
|
14
|
+
" [et](http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html)
|
15
|
+
" TODO: Feedback is welcomed.
|
16
|
+
|
17
|
+
|
18
|
+
" Read the HTML syntax to start with
|
19
|
+
if version < 600
|
20
|
+
so <sfile>:p:h/html.vim
|
21
|
+
else
|
22
|
+
runtime! syntax/html.vim
|
23
|
+
unlet b:current_syntax
|
24
|
+
endif
|
25
|
+
|
26
|
+
if version < 600
|
27
|
+
syntax clear
|
28
|
+
elseif exists("b:current_syntax")
|
29
|
+
finish
|
30
|
+
endif
|
31
|
+
|
32
|
+
" Standard HiLink will not work with included syntax files
|
33
|
+
if version < 508
|
34
|
+
command! -nargs=+ HtmlHiLink hi link <args>
|
35
|
+
else
|
36
|
+
command! -nargs=+ HtmlHiLink hi def link <args>
|
37
|
+
endif
|
38
|
+
|
39
|
+
syntax match mustacheError '}}}\?'
|
40
|
+
syntax match mustacheInsideError '{{[{#<>=!\/]\?' containedin=@mustacheInside
|
41
|
+
syntax region mustacheVariable matchgroup=mustacheMarker start=/{{/ end=/}}/ containedin=@htmlMustacheContainer
|
42
|
+
syntax region mustacheVariableUnescape matchgroup=mustacheMarker start=/{{{/ end=/}}}/ containedin=@htmlMustacheContainer
|
43
|
+
syntax region mustacheSection matchgroup=mustacheMarker start='{{[#/]' end=/}}/ containedin=@htmlMustacheContainer
|
44
|
+
syntax region mustachePartial matchgroup=mustacheMarker start=/{{[<>]/ end=/}}/
|
45
|
+
syntax region mustacheMarkerSet matchgroup=mustacheMarker start=/{{=/ end=/=}}/
|
46
|
+
syntax region mustacheComment start=/{{!/ end=/}}/ contains=Todo containedin=htmlHead
|
47
|
+
|
48
|
+
|
49
|
+
" Clustering
|
50
|
+
syntax cluster mustacheInside add=mustacheVariable,mustacheVariableUnescape,mustacheSection,mustachePartial,mustacheMarkerSet
|
51
|
+
syntax cluster htmlMustacheContainer add=htmlHead,htmlTitle,htmlString,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6
|
52
|
+
|
53
|
+
|
54
|
+
" Hilighting
|
55
|
+
" mustacheInside hilighted as Number, which is rarely used in html
|
56
|
+
" you might like change it to Function or Identifier
|
57
|
+
HtmlHiLink mustacheVariable Number
|
58
|
+
HtmlHiLink mustacheVariableUnescape Number
|
59
|
+
HtmlHiLink mustachePartial Number
|
60
|
+
HtmlHiLink mustacheSection Number
|
61
|
+
HtmlHiLink mustacheMarkerSet Number
|
62
|
+
|
63
|
+
HtmlHiLink mustacheComment Comment
|
64
|
+
HtmlHiLink mustacheMarker Identifier
|
65
|
+
HtmlHiLink mustacheError Error
|
66
|
+
HtmlHiLink mustacheInsideError Error
|
67
|
+
|
68
|
+
let b:current_syntax = "mustache"
|
69
|
+
delcommand HtmlHiLink
|
data/examples/comments.html
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<h1>{{title}}{{! just something interesting... or not... }}</h1>
|
1
|
+
<h1>{{title}}{{! just something interesting... #or not... }}</h1>
|
data/lib/mustache/context.rb
CHANGED
data/lib/mustache/sinatra.rb
CHANGED
@@ -76,6 +76,18 @@ class Mustache
|
|
76
76
|
|
77
77
|
end
|
78
78
|
|
79
|
+
# Tell the view class its extension and path so finding partials
|
80
|
+
# works as expected.
|
81
|
+
if klass.template_extension != 'mustache'
|
82
|
+
klass.template_extension = 'mustache'
|
83
|
+
end
|
84
|
+
|
85
|
+
# Confusingly Sinatra's `views` setting tells Mustache where the
|
86
|
+
# templates are found. It's fine, blame Chris.
|
87
|
+
if klass.template_path != options.views
|
88
|
+
klass.template_path = options.views
|
89
|
+
end
|
90
|
+
|
79
91
|
# Create a new instance for playing with
|
80
92
|
instance = klass.new
|
81
93
|
|
data/lib/mustache/template.rb
CHANGED
@@ -47,7 +47,7 @@ class Mustache
|
|
47
47
|
# If enumerable, the return value is iterated over (a `for` loop).
|
48
48
|
def compile_sections(src)
|
49
49
|
res = ""
|
50
|
-
while src =~ /#{otag}\#(
|
50
|
+
while src =~ /#{otag}\#([^\}]*)#{ctag}\s*(.+?)#{otag}\/\1#{ctag}\s*/m
|
51
51
|
# $` = The string to the left of the last successful match
|
52
52
|
res << compile_tags($`)
|
53
53
|
name = $1.strip.to_sym.inspect
|
@@ -85,7 +85,7 @@ class Mustache
|
|
85
85
|
# 4. Partial tags - {{< partial_name }}
|
86
86
|
def compile_tags(src)
|
87
87
|
res = ""
|
88
|
-
while src =~ /#{otag}(=|!|<|\{)?(
|
88
|
+
while src =~ /#{otag}(=|!|<|\{)?(.+?)\1?#{ctag}+/
|
89
89
|
res << str($`)
|
90
90
|
case $1
|
91
91
|
when '!'
|
data/lib/mustache/version.rb
CHANGED
data/test/mustache_test.rb
CHANGED
@@ -10,6 +10,7 @@ require 'unescaped'
|
|
10
10
|
require 'comments'
|
11
11
|
require 'passenger'
|
12
12
|
require 'delimiters'
|
13
|
+
require 'double_section'
|
13
14
|
|
14
15
|
class MustacheTest < Test::Unit::TestCase
|
15
16
|
def test_passenger
|
@@ -143,7 +144,6 @@ Welcome
|
|
143
144
|
end_partial
|
144
145
|
end
|
145
146
|
|
146
|
-
|
147
147
|
def test_delimiters
|
148
148
|
assert_equal <<-end_partial, Delimiters.render
|
149
149
|
|
@@ -155,6 +155,14 @@ end_partial
|
|
155
155
|
end_partial
|
156
156
|
end
|
157
157
|
|
158
|
+
def test_double_section
|
159
|
+
assert_equal <<-end_section.strip, DoubleSection.render.strip
|
160
|
+
* first
|
161
|
+
* second
|
162
|
+
* third
|
163
|
+
end_section
|
164
|
+
end
|
165
|
+
|
158
166
|
def test_comments
|
159
167
|
assert_equal "<h1>A Comedy of Errors</h1>\n", Comments.render
|
160
168
|
end
|
@@ -224,6 +232,14 @@ data
|
|
224
232
|
assert_equal '<li>1234</li>', instance.render.strip
|
225
233
|
end
|
226
234
|
|
235
|
+
def test_enumerable_sections_accept_a_string_keyed_hash_as_a_context
|
236
|
+
instance = Mustache.new
|
237
|
+
instance[:list] = { 'item' => 1234 }
|
238
|
+
instance.template = '{{#list}} <li>{{item}}</li> {{/list}}'
|
239
|
+
|
240
|
+
assert_equal '<li>1234</li>', instance.render.strip
|
241
|
+
end
|
242
|
+
|
227
243
|
def test_knows_when_its_been_compiled_when_set_with_string
|
228
244
|
klass = Class.new(Mustache)
|
229
245
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mustache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -31,15 +31,19 @@ files:
|
|
31
31
|
- README.md
|
32
32
|
- Rakefile
|
33
33
|
- benchmarks/complex.erb
|
34
|
+
- benchmarks/complex.haml
|
34
35
|
- benchmarks/helper.rb
|
35
36
|
- benchmarks/simple.erb
|
36
37
|
- benchmarks/speed.rb
|
38
|
+
- contrib/mustache.vim
|
37
39
|
- examples/comments.html
|
38
40
|
- examples/comments.rb
|
39
41
|
- examples/complex_view.html
|
40
42
|
- examples/complex_view.rb
|
41
43
|
- examples/delimiters.html
|
42
44
|
- examples/delimiters.rb
|
45
|
+
- examples/double_section.html
|
46
|
+
- examples/double_section.rb
|
43
47
|
- examples/escaped.html
|
44
48
|
- examples/escaped.rb
|
45
49
|
- examples/inner_partial.html
|
@@ -94,6 +98,7 @@ test_files:
|
|
94
98
|
- examples/comments.rb
|
95
99
|
- examples/complex_view.rb
|
96
100
|
- examples/delimiters.rb
|
101
|
+
- examples/double_section.rb
|
97
102
|
- examples/escaped.rb
|
98
103
|
- examples/passenger.rb
|
99
104
|
- examples/simple.rb
|