mustache 0.5.0 → 0.5.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/CONTRIBUTORS +1 -0
- data/HISTORY.md +6 -0
- data/README.md +20 -2
- data/bin/mustache +17 -2
- data/contrib/tpl-mode.el +3 -3
- data/examples/complex_view.rb +1 -1
- data/lib/mustache/context.rb +1 -1
- data/lib/mustache/sinatra.rb +1 -1
- data/lib/mustache/template.rb +1 -1
- data/lib/mustache/version.rb +1 -1
- data/test/mustache_test.rb +6 -0
- metadata +2 -2
data/CONTRIBUTORS
CHANGED
data/HISTORY.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.5.1 (2009-12-15)
|
2
|
+
|
3
|
+
* Added "mail merge" functionality to `mustache` script.
|
4
|
+
* Support for multi-line tags (useful for comments)
|
5
|
+
* Sinatra Bugfix: Use Sinatra app's view path, not Sinatra base class'.
|
6
|
+
|
1
7
|
## 0.5.0 (2009-11-23)
|
2
8
|
|
3
9
|
* Partial classes are no longer supported. Use modules!
|
data/README.md
CHANGED
@@ -452,13 +452,31 @@ frontmatter. An example looks like this:
|
|
452
452
|
Hi {{name}}!
|
453
453
|
{{/names}}
|
454
454
|
|
455
|
-
$
|
455
|
+
$ mustache < complete.mustache
|
456
|
+
Hi chris!
|
457
|
+
Hi mark!
|
458
|
+
Hi scott!
|
459
|
+
|
460
|
+
You can include multiple documents in your YAML frontmatter if you
|
461
|
+
like. Then the template is evaluated once for each of them.
|
462
|
+
|
463
|
+
$ cat multiple.mustache
|
464
|
+
---
|
465
|
+
name: chris
|
466
|
+
---
|
467
|
+
name: mark
|
468
|
+
---
|
469
|
+
name: scott
|
470
|
+
---
|
471
|
+
Hi {{name}!
|
472
|
+
|
473
|
+
$ mustache < multiple.mustache
|
456
474
|
Hi chris!
|
457
475
|
Hi mark!
|
458
476
|
Hi scott!
|
459
477
|
|
460
478
|
It's probably more useful to keep the YAML and HTML in separate files,
|
461
|
-
though.
|
479
|
+
though. `cat` makes this easy:
|
462
480
|
|
463
481
|
$ cat data.yml
|
464
482
|
---
|
data/bin/mustache
CHANGED
@@ -6,8 +6,12 @@ require 'yaml'
|
|
6
6
|
if STDIN.stat.size > 0
|
7
7
|
doc = STDIN.read
|
8
8
|
if doc =~ /^(\s*---(.*)---\s*)/m
|
9
|
-
|
10
|
-
|
9
|
+
yaml = $2.strip
|
10
|
+
template = doc.sub($1, '')
|
11
|
+
|
12
|
+
YAML.each_document(yaml) do |data|
|
13
|
+
puts Mustache.render(template, data)
|
14
|
+
end
|
11
15
|
else
|
12
16
|
puts doc
|
13
17
|
end
|
@@ -30,5 +34,16 @@ The data.yml file should start with --- on a single line and end with
|
|
30
34
|
---
|
31
35
|
|
32
36
|
The converted document will be printed on STDOUT.
|
37
|
+
|
38
|
+
You can include multiple documents in your YAML frontmatter if you
|
39
|
+
like. Then the template is evaluated once for each of them.
|
40
|
+
|
41
|
+
---
|
42
|
+
name: chris
|
43
|
+
---
|
44
|
+
name: mark
|
45
|
+
---
|
46
|
+
name: scott
|
47
|
+
---
|
33
48
|
usage
|
34
49
|
end
|
data/contrib/tpl-mode.el
CHANGED
@@ -74,7 +74,7 @@
|
|
74
74
|
"The basic indentation offset.")
|
75
75
|
|
76
76
|
;; Constant regular expressions to identify template elements.
|
77
|
-
(defconst tpl-mode-tpl-token "[a-zA-
|
77
|
+
(defconst tpl-mode-tpl-token "[a-zA-Z_][a-zA-Z0-9_:=\?!-]*?")
|
78
78
|
(defconst tpl-mode-section (concat "\\({{[#/]\s*"
|
79
79
|
tpl-mode-tpl-token
|
80
80
|
"\s*}}\\)"))
|
@@ -86,7 +86,7 @@
|
|
86
86
|
"\s*\\)}}"))
|
87
87
|
;; TODO(tonyg) Figure out a way to support multiline comments.
|
88
88
|
(defconst tpl-mode-comment "\\({{!.*?}}\\)")
|
89
|
-
(defconst tpl-mode-include (concat "\\({{
|
89
|
+
(defconst tpl-mode-include (concat "\\({{[><]\s*"
|
90
90
|
tpl-mode-tpl-token
|
91
91
|
"\s*}}\\)"))
|
92
92
|
(defconst tpl-mode-variable (concat "\\({{\s*"
|
@@ -240,7 +240,7 @@
|
|
240
240
|
(list tpl-mode-comment
|
241
241
|
'(1 font-lock-comment-face))
|
242
242
|
(list tpl-mode-include
|
243
|
-
'(1 font-lock-
|
243
|
+
'(1 font-lock-function-name-face))
|
244
244
|
(list tpl-mode-builtins
|
245
245
|
'(1 font-lock-variable-name-face))
|
246
246
|
(list tpl-mode-variable
|
data/examples/complex_view.rb
CHANGED
data/lib/mustache/context.rb
CHANGED
@@ -4,7 +4,7 @@ class Mustache
|
|
4
4
|
# set to true.
|
5
5
|
#
|
6
6
|
# For example, if your View class does not respond to `music` but
|
7
|
-
# your template contains a `{{
|
7
|
+
# your template contains a `{{music}}` tag this exception will be raised.
|
8
8
|
#
|
9
9
|
# By default it is not raised. See Mustache.raise_on_context_miss.
|
10
10
|
class ContextMiss < RuntimeError; end
|
data/lib/mustache/sinatra.rb
CHANGED
data/lib/mustache/template.rb
CHANGED
@@ -106,7 +106,7 @@ class Mustache
|
|
106
106
|
# 4. Partial tags - {{> partial_name }}
|
107
107
|
def compile_tags(src)
|
108
108
|
res = ""
|
109
|
-
while src =~ /#{otag}(#|=|!|<|>|\{)?(.+?)\1?#{ctag}+/
|
109
|
+
while src =~ /#{otag}(#|=|!|<|>|\{)?(.+?)\1?#{ctag}+/m
|
110
110
|
res << str($`)
|
111
111
|
case $1
|
112
112
|
when '#'
|
data/lib/mustache/version.rb
CHANGED
data/test/mustache_test.rb
CHANGED
@@ -125,6 +125,12 @@ end_section
|
|
125
125
|
assert_equal "<h1>A Comedy of Errors</h1>\n", Comments.render
|
126
126
|
end
|
127
127
|
|
128
|
+
def test_multi_linecomments
|
129
|
+
view = Comments.new
|
130
|
+
view.template = "<h1>{{title}}{{! just something interesting... \n#or not... }}</h1>\n"
|
131
|
+
assert_equal "<h1>A Comedy of Errors</h1>\n", view.render
|
132
|
+
end
|
133
|
+
|
128
134
|
def test_escaped
|
129
135
|
assert_equal '<h1>Bear > Shark</h1>', Escaped.render
|
130
136
|
end
|
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.5.
|
4
|
+
version: 0.5.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-
|
12
|
+
date: 2009-12-15 00:00:00 -08:00
|
13
13
|
default_executable: mustache
|
14
14
|
dependencies: []
|
15
15
|
|