mustache 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,4 +3,5 @@
3
3
  * Magnus Holm
4
4
  * Nicolas Sanguinetti
5
5
  * Jan-Erik Rediger
6
+ * Michael Daines
6
7
  * Aaron Patterson
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
- $ cat complete.mustache | mustache
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. Luckily `cat` works great for this, too:
479
+ though. `cat` makes this easy:
462
480
 
463
481
  $ cat data.yml
464
482
  ---
@@ -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
- data = YAML.load($2.strip)
10
- puts Mustache.render(doc.sub($1, ''), data)
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
@@ -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-Z][a-zA-Z0-9_:=\?!-]*?")
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 "\\({{>\s*"
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-builtin-face))
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
@@ -17,7 +17,7 @@ class ComplexView < Mustache
17
17
  end
18
18
 
19
19
  def link
20
- not context[:current]
20
+ not self[:current]
21
21
  end
22
22
 
23
23
  def list
@@ -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 `{{template}}` tag this exception will be raised.
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
@@ -92,7 +92,7 @@ class Mustache
92
92
 
93
93
  def self.registered(app)
94
94
  app.helpers Mustache::Sinatra::Helpers
95
- app.set :mustaches, ::Sinatra::Base.views
95
+ app.set :mustaches, app.views
96
96
  app.set :namespace, app
97
97
  end
98
98
  end
@@ -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 '#'
@@ -1,3 +1,3 @@
1
1
  class Mustache
2
- Version = '0.5.0'
2
+ Version = '0.5.1'
3
3
  end
@@ -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 &gt; 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.0
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-11-23 00:00:00 -08:00
12
+ date: 2009-12-15 00:00:00 -08:00
13
13
  default_executable: mustache
14
14
  dependencies: []
15
15