mustache 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/README.md +30 -197
  2. data/Rakefile +87 -46
  3. data/bin/mustache +5 -29
  4. data/lib/mustache/context.rb +54 -11
  5. data/lib/mustache/template.rb +2 -14
  6. data/lib/mustache/version.rb +1 -1
  7. data/man/mustache.1 +138 -0
  8. data/man/mustache.1.html +168 -0
  9. data/man/mustache.1.ron +94 -0
  10. data/man/mustache.5 +364 -0
  11. data/man/mustache.5.html +300 -0
  12. data/man/mustache.5.ron +220 -0
  13. data/test/helper.rb +1 -0
  14. data/test/mustache_test.rb +19 -16
  15. metadata +32 -65
  16. data/.gitignore +0 -1
  17. data/.kick +0 -26
  18. data/CONTRIBUTORS +0 -7
  19. data/HISTORY.md +0 -76
  20. data/benchmarks/complex.erb +0 -15
  21. data/benchmarks/complex.haml +0 -10
  22. data/benchmarks/helper.rb +0 -20
  23. data/benchmarks/simple.erb +0 -5
  24. data/benchmarks/speed.rb +0 -76
  25. data/contrib/mustache.vim +0 -69
  26. data/contrib/tpl-mode.el +0 -274
  27. data/examples/comments.mustache +0 -1
  28. data/examples/comments.rb +0 -14
  29. data/examples/complex_view.mustache +0 -16
  30. data/examples/complex_view.rb +0 -34
  31. data/examples/delimiters.mustache +0 -6
  32. data/examples/delimiters.rb +0 -22
  33. data/examples/double_section.mustache +0 -7
  34. data/examples/double_section.rb +0 -14
  35. data/examples/escaped.mustache +0 -1
  36. data/examples/escaped.rb +0 -14
  37. data/examples/inner_partial.mustache +0 -1
  38. data/examples/inner_partial.txt +0 -1
  39. data/examples/namespaced.mustache +0 -1
  40. data/examples/namespaced.rb +0 -25
  41. data/examples/partial_with_module.mustache +0 -3
  42. data/examples/partial_with_module.rb +0 -37
  43. data/examples/passenger.conf +0 -5
  44. data/examples/passenger.rb +0 -27
  45. data/examples/simple.mustache +0 -5
  46. data/examples/simple.rb +0 -26
  47. data/examples/template_partial.mustache +0 -2
  48. data/examples/template_partial.rb +0 -18
  49. data/examples/template_partial.txt +0 -4
  50. data/examples/unescaped.mustache +0 -1
  51. data/examples/unescaped.rb +0 -14
@@ -0,0 +1,220 @@
1
+ mustache(5) -- Logic-less templates.
2
+ ====================================
3
+
4
+ ## SYNOPSIS
5
+
6
+ A typical Mustache template:
7
+
8
+ Hello {{name}}
9
+ You have just won ${{value}}!
10
+ {{#in_ca}}
11
+ Well, ${{taxed_value}}, after taxes.
12
+ {{/in_ca}}
13
+
14
+ Given the following hash:
15
+
16
+ {
17
+ "name": "Chris",
18
+ "value": 10000,
19
+ "taxed_value": 10000 - (10000 * 0.4),
20
+ "in_ca": true
21
+ }
22
+
23
+ Will produce the following:
24
+
25
+ Hello Chris
26
+ You have just won $10000!
27
+ Well, $6000.0, after taxes.
28
+
29
+
30
+ ## DESCRIPTION
31
+
32
+ Mustache can be used for HTML, config files, source code -
33
+ anything. It works by expanding tags in a template using values
34
+ provided in a hash or object.
35
+
36
+ We call it "logic-less" because there are no if statements, else
37
+ clauses, or for loops. Instead there are only tags. Some tags are
38
+ replaced with a value, some nothing, and others a series of
39
+ values. This document explains the different types of Mustache tags.
40
+
41
+
42
+ ## TAG TYPES
43
+
44
+ Tags are indicated by the double mustaches. `{{name}}` is a tag. Let's
45
+ talk about the different types of tags.
46
+
47
+
48
+ ### Variables
49
+
50
+ The most basic tag is the variable. A `{{name}}` tag in a basic
51
+ template will try to call the `name` method on your view. If there is
52
+ no `name` method, an exception will be raised.
53
+
54
+ All variables are HTML escaped by default. If you want to return
55
+ unescaped HTML, use the triple mustache: `{{{name}}}`.
56
+
57
+ By default a variable "miss" returns an empty string. This can usually
58
+ be configured in your Mustache library.
59
+
60
+ Template:
61
+
62
+ * {{name}}
63
+ * {{age}}
64
+ * {{company}}
65
+ * {{{company}}}
66
+
67
+ Hash:
68
+
69
+ {
70
+ "name": "Chris",
71
+ "company": "<b>GitHub</b>"
72
+ }
73
+
74
+ Output:
75
+
76
+ * Chris
77
+ *
78
+ * &lt;b&gt;GitHub&lt;/b&gt;
79
+ * <b>GitHub</b>
80
+
81
+ ### Boolean Sections
82
+
83
+ A section begins with a pound and ends with a slash. That is,
84
+ `{{#person}}` begins a "person" section while `{{/person}}` ends it.
85
+
86
+ If the `person` key exists and calling it returns false, the HTML
87
+ between the pound and slash will not be displayed.
88
+
89
+ If the `person` method exists and calling it returns true, the HTML
90
+ between the pound and slash will be rendered and displayed.
91
+
92
+ Template:
93
+
94
+ {{#person}}
95
+ Shown!
96
+ {{/person}}
97
+ {{#anything_else}}
98
+ Never shown!
99
+ {{/anything_else}}
100
+
101
+ Hash:
102
+
103
+ {
104
+ "person": true
105
+ }
106
+
107
+ Output:
108
+
109
+ Shown!
110
+
111
+ ### Enumerable Sections
112
+
113
+ Enumerable sections are syntactically identical to boolean sections in
114
+ that they begin with a pound and end with a slash. The difference,
115
+ however, is in the view: if the method called returns an enumerable,
116
+ the section is repeated as the enumerable is iterated over.
117
+
118
+ Each item in the enumerable is expected to be a hash which will then
119
+ become the context of the corresponding iteration. In this way we can
120
+ construct loops.
121
+
122
+ Template:
123
+
124
+ {{#repo}}
125
+ <b>{{name}}</b>
126
+ {{/repo}}
127
+
128
+ Hash:
129
+
130
+ {
131
+ "repo": [
132
+ { "name": "resque" },
133
+ { "name": "hub" },
134
+ { "name": "rip" },
135
+ ]
136
+ }
137
+
138
+ Output:
139
+
140
+ <b>resque</b>
141
+ <b>hub</b>
142
+ <b>rip</b>
143
+
144
+
145
+ ### Comments
146
+
147
+ Comments begin with a bang and are ignored. The following template:
148
+
149
+ <h1>Today{{! ignore me }}.</h1>
150
+
151
+ Will render as follows:
152
+
153
+ <h1>Today.</h1>
154
+
155
+
156
+ ### Partials
157
+
158
+ Partials begin with a greater than sign, like `{{> box}}`.
159
+
160
+ It is useful to think of partials as a "template expansion" - that is,
161
+ the actual partial tag will be replaced with the content of the
162
+ partial. Therefor partials share the current context.
163
+
164
+ For example, this template and partial:
165
+
166
+ base.mustache:
167
+ <h2>Names</h2>
168
+ {{# names }}
169
+ {{> user }}
170
+ {{/ names }}
171
+
172
+ user.mustache:
173
+ <strong>{{ name }}</strong>
174
+
175
+ Can be thought of as a single, expanded template:
176
+
177
+ <h2>Names</h2>
178
+ {{# names }}
179
+ <strong>{{ name }}</strong>
180
+ {{/ names }}
181
+
182
+
183
+ ### Set Delimiter
184
+
185
+ Set Delimiter tags start with an equal sign and change the tag
186
+ delimiters from {{ and }} to custom strings.
187
+
188
+ Consider the following contrived example:
189
+
190
+ * {{ default_tags }}
191
+ {{=<% %>=}}
192
+ * <% erb_style_tags %>
193
+ <%={{ }}=%>
194
+ * {{ default_tags_again }}
195
+
196
+ Here we have a list with three items. The first item uses the default
197
+ tag style, the second uses erb style as defined by the Set Delimiter
198
+ tag, and the third returns to the default style after yet another Set
199
+ Delimiter declaration.
200
+
201
+ According to [ctemplates][ct], this "is useful for languages like TeX, where
202
+ double-braces may occur in the text and are awkward to use for
203
+ markup."
204
+
205
+ Custom delimiters may not contain whitespace or the equals sign.
206
+
207
+ [ct]: http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html
208
+
209
+
210
+ ## COPYRIGHT
211
+
212
+ Mustache is Copyright (C) 2009 Chris Wanstrath
213
+
214
+ Original CTemplate by Google
215
+
216
+
217
+ ## SEE ALSO
218
+
219
+ mustache(1), mustache(7), gem(1),
220
+ <http://defunkt.github.com/mustache/>
@@ -11,3 +11,4 @@ require 'comments'
11
11
  require 'passenger'
12
12
  require 'delimiters'
13
13
  require 'double_section'
14
+ require 'nested_objects'
@@ -21,17 +21,17 @@ end_passenger
21
21
  <li><a href="#Blue">blue</a></li>
22
22
  </ul>
23
23
  end_complex
24
+ end
24
25
 
25
- # TODO: Preserve indentation
26
- # http://github.com/defunkt/mustache/issues#issue/2
27
- # assert_equal <<-end_complex, ComplexView.render
28
- # <h1>Colors</h1>
29
- # <ul>
30
- # <li><strong>red</strong></li>
31
- # <li><a href="#Green">green</a></li>
32
- # <li><a href="#Blue">blue</a></li>
33
- # </ul>
34
- # end_complex
26
+ def test_nested_objects
27
+ assert_equal <<-end_complex, NestedObjects.render
28
+ <h1>Colors</h1>
29
+ <ul>
30
+ <li><strong>red</strong></li>
31
+ <li><a href="#Green">green</a></li>
32
+ <li><a href="#Blue">blue</a></li>
33
+ </ul>
34
+ end_complex
35
35
  end
36
36
 
37
37
  def test_single_line_sections
@@ -178,14 +178,17 @@ data
178
178
  :deploy_to => '/var/www/example.com' )
179
179
  end
180
180
 
181
- def test_reports_type_errors_in_sections
181
+ def test_doesnt_execute_what_it_doesnt_need_to
182
182
  instance = Mustache.new
183
- instance[:list] = [ :item, 1234 ]
184
- instance.template = '{{#list}} <li>{{item}}</li> {{/list}}'
185
-
186
- assert_raise TypeError do
187
- instance.render
183
+ instance[:show] = false
184
+ instance.instance_eval do
185
+ def die
186
+ raise "bummer"
187
+ end
188
188
  end
189
+ instance.template = '{{#show}} <li>{{die}}</li> {{/show}} yay'
190
+
191
+ assert_equal "yay", instance.render
189
192
  end
190
193
 
191
194
  def test_reports_unclosed_sections
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.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -9,68 +9,49 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-15 00:00:00 -08:00
13
- default_executable: mustache
12
+ date: 2010-03-08 00:00:00 -08:00
13
+ default_executable:
14
14
  dependencies: []
15
15
 
16
- description: Mustache is a framework-agnostic way to render logic-free views.
16
+ description: |
17
+ Inspired by ctemplate, Mustache is a framework-agnostic way to render
18
+ logic-free views.
19
+
20
+ As ctemplates says, "It emphasizes separating logic from presentation:
21
+ it is impossible to embed application logic in this template
22
+ language.
23
+
24
+ Think of Mustache as a replacement for your views. Instead of views
25
+ consisting of ERB or HAML with random helpers and arbitrary logic,
26
+ your views are broken into two parts: a Ruby class and an HTML
27
+ template.
28
+
17
29
  email: chris@ozmm.org
18
30
  executables:
19
31
  - mustache
20
32
  extensions: []
21
33
 
22
- extra_rdoc_files:
23
- - LICENSE
24
- - README.md
34
+ extra_rdoc_files: []
35
+
25
36
  files:
26
- - .gitignore
27
- - .kick
28
- - CONTRIBUTORS
29
- - HISTORY.md
30
- - LICENSE
31
37
  - README.md
32
38
  - Rakefile
33
- - benchmarks/complex.erb
34
- - benchmarks/complex.haml
35
- - benchmarks/helper.rb
36
- - benchmarks/simple.erb
37
- - benchmarks/speed.rb
38
- - bin/mustache
39
- - contrib/mustache.vim
40
- - contrib/tpl-mode.el
41
- - examples/comments.mustache
42
- - examples/comments.rb
43
- - examples/complex_view.mustache
44
- - examples/complex_view.rb
45
- - examples/delimiters.mustache
46
- - examples/delimiters.rb
47
- - examples/double_section.mustache
48
- - examples/double_section.rb
49
- - examples/escaped.mustache
50
- - examples/escaped.rb
51
- - examples/inner_partial.mustache
52
- - examples/inner_partial.txt
53
- - examples/namespaced.mustache
54
- - examples/namespaced.rb
55
- - examples/partial_with_module.mustache
56
- - examples/partial_with_module.rb
57
- - examples/passenger.conf
58
- - examples/passenger.rb
59
- - examples/simple.mustache
60
- - examples/simple.rb
61
- - examples/template_partial.mustache
62
- - examples/template_partial.rb
63
- - examples/template_partial.txt
64
- - examples/unescaped.mustache
65
- - examples/unescaped.rb
66
- - lib/mustache.rb
39
+ - LICENSE
67
40
  - lib/mustache/context.rb
68
41
  - lib/mustache/sinatra.rb
69
42
  - lib/mustache/template.rb
70
43
  - lib/mustache/version.rb
71
- - lib/rack/bug/panels/mustache_panel.rb
44
+ - lib/mustache.rb
72
45
  - lib/rack/bug/panels/mustache_panel/mustache_extension.rb
73
46
  - lib/rack/bug/panels/mustache_panel/view.mustache
47
+ - lib/rack/bug/panels/mustache_panel.rb
48
+ - bin/mustache
49
+ - man/mustache.1
50
+ - man/mustache.1.html
51
+ - man/mustache.1.ron
52
+ - man/mustache.5
53
+ - man/mustache.5.html
54
+ - man/mustache.5.ron
74
55
  - test/autoloading_test.rb
75
56
  - test/helper.rb
76
57
  - test/mustache_test.rb
@@ -80,8 +61,8 @@ homepage: http://github.com/defunkt/mustache
80
61
  licenses: []
81
62
 
82
63
  post_install_message:
83
- rdoc_options:
84
- - --charset=UTF-8
64
+ rdoc_options: []
65
+
85
66
  require_paths:
86
67
  - lib
87
68
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -103,19 +84,5 @@ rubygems_version: 1.3.5
103
84
  signing_key:
104
85
  specification_version: 3
105
86
  summary: Mustache is a framework-agnostic way to render logic-free views.
106
- test_files:
107
- - test/autoloading_test.rb
108
- - test/helper.rb
109
- - test/mustache_test.rb
110
- - test/partial_test.rb
111
- - examples/comments.rb
112
- - examples/complex_view.rb
113
- - examples/delimiters.rb
114
- - examples/double_section.rb
115
- - examples/escaped.rb
116
- - examples/namespaced.rb
117
- - examples/partial_with_module.rb
118
- - examples/passenger.rb
119
- - examples/simple.rb
120
- - examples/template_partial.rb
121
- - examples/unescaped.rb
87
+ test_files: []
88
+
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- docs
data/.kick DELETED
@@ -1,26 +0,0 @@
1
- # take control of the growl notifications
2
- module GrowlHacks
3
- def growl(type, subject, body, *args, &block)
4
- case type
5
- when Kicker::GROWL_NOTIFICATIONS[:succeeded]
6
- puts subject = "Success"
7
- body = body.split("\n").last
8
- when Kicker::GROWL_NOTIFICATIONS[:failed]
9
- subject = "Failure"
10
- puts body
11
- body = body.split("\n").last
12
- else
13
- return nil
14
- end
15
- super(type, subject, body, *args, &block)
16
- end
17
- end
18
-
19
- Kicker.send :extend, GrowlHacks
20
-
21
- # no logging
22
- Kicker::Utils.module_eval do
23
- def log(message)
24
- nil
25
- end
26
- end
@@ -1,7 +0,0 @@
1
- * Chris Wanstrath
2
- * Francesc Esplugas
3
- * Magnus Holm
4
- * Nicolas Sanguinetti
5
- * Jan-Erik Rediger
6
- * Michael Daines
7
- * Aaron Patterson