angry_mob_common_targets 0.1.0
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/LICENSE +21 -0
- data/README.md +38 -0
- data/lib/common_mob.rb +9 -0
- data/lib/common_mob/digest.rb +43 -0
- data/lib/common_mob/erb.rb +72 -0
- data/lib/common_mob/file.rb +55 -0
- data/lib/common_mob/patch.rb +51 -0
- data/lib/common_mob/resource_locator.rb +9 -0
- data/lib/common_mob/shell.rb +323 -0
- data/lib/common_mob/template.rb +23 -0
- data/lib/common_mob/version.rb +3 -0
- data/targets/crontab_patch.rb +37 -0
- data/targets/extract.rb +40 -0
- data/targets/fetch.rb +40 -0
- data/targets/files.rb +244 -0
- data/targets/git.rb +84 -0
- data/targets/group.rb +33 -0
- data/targets/packages.rb +94 -0
- data/targets/ruby.rb +13 -0
- data/targets/services.rb +184 -0
- data/targets/shell.rb +43 -0
- data/targets/user.rb +108 -0
- data/vendor/mustache/CONTRIBUTORS +9 -0
- data/vendor/mustache/HISTORY.md +135 -0
- data/vendor/mustache/LICENSE +20 -0
- data/vendor/mustache/README.md +405 -0
- data/vendor/mustache/Rakefile +103 -0
- data/vendor/mustache/benchmarks/complex.erb +15 -0
- data/vendor/mustache/benchmarks/complex.haml +12 -0
- data/vendor/mustache/benchmarks/helper.rb +20 -0
- data/vendor/mustache/benchmarks/simple.erb +5 -0
- data/vendor/mustache/benchmarks/speed.rb +78 -0
- data/vendor/mustache/bin/mustache +90 -0
- data/vendor/mustache/contrib/mustache-mode.el +278 -0
- data/vendor/mustache/contrib/mustache.vim +69 -0
- data/vendor/mustache/examples/hash.rb +16 -0
- data/vendor/mustache/examples/hash.yml +5 -0
- data/vendor/mustache/examples/projects.mustache +26 -0
- data/vendor/mustache/examples/projects.yml +28 -0
- data/vendor/mustache/examples/self.mustache +4 -0
- data/vendor/mustache/examples/self.yml +3 -0
- data/vendor/mustache/examples/simple.mustache +10 -0
- data/vendor/mustache/examples/simple.rb +24 -0
- data/vendor/mustache/lib/mustache.rb +358 -0
- data/vendor/mustache/lib/mustache/context.rb +108 -0
- data/vendor/mustache/lib/mustache/generator.rb +160 -0
- data/vendor/mustache/lib/mustache/parser.rb +230 -0
- data/vendor/mustache/lib/mustache/sinatra.rb +180 -0
- data/vendor/mustache/lib/mustache/template.rb +59 -0
- data/vendor/mustache/lib/mustache/version.rb +3 -0
- data/vendor/mustache/lib/rack/bug/panels/mustache_panel.rb +81 -0
- data/vendor/mustache/lib/rack/bug/panels/mustache_panel/mustache_extension.rb +27 -0
- data/vendor/mustache/lib/rack/bug/panels/mustache_panel/view.mustache +46 -0
- data/vendor/mustache/man/mustache.1 +180 -0
- data/vendor/mustache/man/mustache.1.html +204 -0
- data/vendor/mustache/man/mustache.1.ron +127 -0
- data/vendor/mustache/man/mustache.5 +576 -0
- data/vendor/mustache/man/mustache.5.html +415 -0
- data/vendor/mustache/man/mustache.5.ron +324 -0
- data/vendor/mustache/mustache.gemspec +32 -0
- data/vendor/mustache/test/autoloading_test.rb +52 -0
- data/vendor/mustache/test/fixtures/comments.mustache +1 -0
- data/vendor/mustache/test/fixtures/comments.rb +14 -0
- data/vendor/mustache/test/fixtures/complex_view.mustache +17 -0
- data/vendor/mustache/test/fixtures/complex_view.rb +34 -0
- data/vendor/mustache/test/fixtures/crazy_recursive.mustache +9 -0
- data/vendor/mustache/test/fixtures/crazy_recursive.rb +31 -0
- data/vendor/mustache/test/fixtures/delimiters.mustache +8 -0
- data/vendor/mustache/test/fixtures/delimiters.rb +23 -0
- data/vendor/mustache/test/fixtures/double_section.mustache +7 -0
- data/vendor/mustache/test/fixtures/double_section.rb +14 -0
- data/vendor/mustache/test/fixtures/escaped.mustache +1 -0
- data/vendor/mustache/test/fixtures/escaped.rb +14 -0
- data/vendor/mustache/test/fixtures/inner_partial.mustache +1 -0
- data/vendor/mustache/test/fixtures/inner_partial.txt +1 -0
- data/vendor/mustache/test/fixtures/inverted_section.mustache +7 -0
- data/vendor/mustache/test/fixtures/inverted_section.rb +14 -0
- data/vendor/mustache/test/fixtures/lambda.mustache +7 -0
- data/vendor/mustache/test/fixtures/lambda.rb +31 -0
- data/vendor/mustache/test/fixtures/namespaced.mustache +1 -0
- data/vendor/mustache/test/fixtures/namespaced.rb +25 -0
- data/vendor/mustache/test/fixtures/nested_objects.mustache +17 -0
- data/vendor/mustache/test/fixtures/nested_objects.rb +35 -0
- data/vendor/mustache/test/fixtures/node.mustache +8 -0
- data/vendor/mustache/test/fixtures/partial_with_module.mustache +3 -0
- data/vendor/mustache/test/fixtures/partial_with_module.rb +37 -0
- data/vendor/mustache/test/fixtures/passenger.conf +5 -0
- data/vendor/mustache/test/fixtures/passenger.rb +27 -0
- data/vendor/mustache/test/fixtures/recursive.mustache +4 -0
- data/vendor/mustache/test/fixtures/recursive.rb +14 -0
- data/vendor/mustache/test/fixtures/simple.mustache +5 -0
- data/vendor/mustache/test/fixtures/simple.rb +26 -0
- data/vendor/mustache/test/fixtures/template_partial.mustache +2 -0
- data/vendor/mustache/test/fixtures/template_partial.rb +18 -0
- data/vendor/mustache/test/fixtures/template_partial.txt +4 -0
- data/vendor/mustache/test/fixtures/unescaped.mustache +1 -0
- data/vendor/mustache/test/fixtures/unescaped.rb +14 -0
- data/vendor/mustache/test/fixtures/utf8.mustache +3 -0
- data/vendor/mustache/test/fixtures/utf8_partial.mustache +1 -0
- data/vendor/mustache/test/helper.rb +7 -0
- data/vendor/mustache/test/mustache_test.rb +536 -0
- data/vendor/mustache/test/parser_test.rb +54 -0
- data/vendor/mustache/test/partial_test.rb +168 -0
- metadata +167 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
## 0.11.2 (2010-05-13)
|
|
2
|
+
|
|
3
|
+
* Sinatra bugfix: `mustache :"TEMPLATE.atom"`
|
|
4
|
+
|
|
5
|
+
## 0.11.1 (2010-05-12)
|
|
6
|
+
|
|
7
|
+
* mustache(1) bugfix: Render even without data.
|
|
8
|
+
|
|
9
|
+
## 0.11.0 (2010-04-18)
|
|
10
|
+
|
|
11
|
+
* Higher Order Sections. See mustache(5) for details.
|
|
12
|
+
* Add inheritable class ivars on Mustache for @options.
|
|
13
|
+
|
|
14
|
+
## 0.10.0 (2010-04-02)
|
|
15
|
+
|
|
16
|
+
* Added Inverted Sections (^). See mustache(5) for details.
|
|
17
|
+
* Added Template#source for accessing the template's string source.
|
|
18
|
+
* Bugfix: 1.9 encoding fix
|
|
19
|
+
* Sinatra Bugfix: 1.9 compat
|
|
20
|
+
|
|
21
|
+
## 0.9.2 (2010-03-29)
|
|
22
|
+
|
|
23
|
+
* Sinatra: Bugfix for `mustache :view, :layout => true`
|
|
24
|
+
* Mustache class now implements `partial` so you can call `super`
|
|
25
|
+
when providing a custom `partial` method.
|
|
26
|
+
* Bugfix: Allow slashes in tags, especially partials.
|
|
27
|
+
|
|
28
|
+
## 0.9.1 (2010-03-27)
|
|
29
|
+
|
|
30
|
+
* Bugfix: Partials use the nearest context when being rendered.
|
|
31
|
+
* Bugfix: Partials returned by the partial method are now rendered.
|
|
32
|
+
|
|
33
|
+
## 0.9.0 (2010-03-26)
|
|
34
|
+
|
|
35
|
+
* New, cleaner parser by Magnus Holm!
|
|
36
|
+
* Improved error messages!
|
|
37
|
+
* Bugfixes!
|
|
38
|
+
* Faster runtime!
|
|
39
|
+
* Sinatra 1.0 compatibility with layout tag overriding!
|
|
40
|
+
|
|
41
|
+
## 0.7.0 (2010-03-25)
|
|
42
|
+
|
|
43
|
+
* `Mustache.compile` for compiling a template into Ruby.
|
|
44
|
+
* `mustache -c FILE` to see a template's compiled Ruby.
|
|
45
|
+
* Recursive partial support.
|
|
46
|
+
* Added `&` as an alias for the triple mustache (unescaped HTML).
|
|
47
|
+
* Simpler examples. Old examples are now test fixtures.
|
|
48
|
+
|
|
49
|
+
## 0.6.0 (2010-03-08)
|
|
50
|
+
|
|
51
|
+
* Ruby objects can be used in sections, not just hashes. See
|
|
52
|
+
http://github.com/defunkt/mustache/commit/9477619638
|
|
53
|
+
* As a result, `TypeError` is no longer thrown when hashes are not
|
|
54
|
+
passed.
|
|
55
|
+
* mustache(1) man page is now included
|
|
56
|
+
* mustache(5) man page is now included
|
|
57
|
+
* tpl-mode.el has been renamed mustache-mode.el
|
|
58
|
+
* Improved README
|
|
59
|
+
|
|
60
|
+
## 0.5.1 (2009-12-15)
|
|
61
|
+
|
|
62
|
+
* Added "mail merge" functionality to `mustache` script.
|
|
63
|
+
* Support for multi-line tags (useful for comments)
|
|
64
|
+
* Sinatra Bugfix: Use Sinatra app's view path, not Sinatra base class'.
|
|
65
|
+
|
|
66
|
+
## 0.5.0 (2009-11-23)
|
|
67
|
+
|
|
68
|
+
* Partial classes are no longer supported. Use modules!
|
|
69
|
+
* Added `mustache` script for rendering templates on the command line.
|
|
70
|
+
* ctemplate compat: Partials are indicated by >, not <
|
|
71
|
+
* Bugfix: Context miss should return nil, not empty string. Fixes 1.9.x
|
|
72
|
+
|
|
73
|
+
## 0.4.2 (2009-10-28)
|
|
74
|
+
|
|
75
|
+
* Bugfix: Ignore bad constant names when autoloading
|
|
76
|
+
|
|
77
|
+
## 0.4.1 (2009-10-27)
|
|
78
|
+
|
|
79
|
+
* Partials now respect the `view_namespace` setting.
|
|
80
|
+
* Added tpl-mode.el to contrib/ for us Emacs users.
|
|
81
|
+
* Rack::Bug bugfix: ensure benchmark is required before using it
|
|
82
|
+
* Rack::Bug: truncate too-large variables (click expands them)
|
|
83
|
+
|
|
84
|
+
## 0.4.0 (2009-10-27)
|
|
85
|
+
|
|
86
|
+
* Stopped raising context miss exceptions by default
|
|
87
|
+
* Added `Mustache.raise_on_context_miss` setting (defaults to false)
|
|
88
|
+
* Throw Mustache::ContextMiss when raise_on_context_miss is true and
|
|
89
|
+
we encounter a miss.
|
|
90
|
+
* The default template extension is now "mustache" (instead of "html").
|
|
91
|
+
* Added the `view_namespace` and `view_path` settings to `Mustache`
|
|
92
|
+
* Added `Mustache.view_class` method which autoloads a class using the
|
|
93
|
+
new `view_namespace` and `view_path` settings. Should be used by
|
|
94
|
+
plugin developers.
|
|
95
|
+
* Updated the Sinatra extension to use the new `view_class` method
|
|
96
|
+
* Unclosed sections now throw a helpful error message
|
|
97
|
+
* Report line numbers on unclosed section errors
|
|
98
|
+
* Added Rack::Bug panel
|
|
99
|
+
|
|
100
|
+
## 0.3.2 (2009-10-19)
|
|
101
|
+
|
|
102
|
+
* Bugfix: Partials in Sinatra were using the wrong path.
|
|
103
|
+
|
|
104
|
+
## 0.3.1 (2009-10-19)
|
|
105
|
+
|
|
106
|
+
* Added mustache.vim to contrib/ (Thanks Juvenn Woo!)
|
|
107
|
+
* Support string keys in contexts (not just symbol keys).
|
|
108
|
+
* Bugfix: # and / were not permitted in tag names. Now they are.
|
|
109
|
+
* Bugfix: Partials in Sinatra needed to know their extension and path
|
|
110
|
+
* Bugfix: Using the same boolean section twice was failing
|
|
111
|
+
|
|
112
|
+
## 0.3.0 (2009-10-14)
|
|
113
|
+
|
|
114
|
+
* Set Delimiter tags are now supported. See the README
|
|
115
|
+
* Improved error message when an enumerable section did not return all
|
|
116
|
+
hashes.
|
|
117
|
+
* Added a shortcut: if a section's value is a single hash, treat is as
|
|
118
|
+
a one element array whose value is the hash.
|
|
119
|
+
* Bugfix: String templates set at the class level were not compiled
|
|
120
|
+
* Added a class-level `compiled?` method for checking if a template
|
|
121
|
+
has been compiled.
|
|
122
|
+
* Added an instance-level `compiled?` method.
|
|
123
|
+
* Cache template compilation in Sinatra
|
|
124
|
+
|
|
125
|
+
## 0.2.2 (2009-10-11)
|
|
126
|
+
|
|
127
|
+
* Improved documentation
|
|
128
|
+
* Fixed single line sections
|
|
129
|
+
* Broke preserved indentation (issue #2)
|
|
130
|
+
|
|
131
|
+
## 0.2.1 (2009-10-11)
|
|
132
|
+
|
|
133
|
+
* Mustache.underscore can now be called without an argument
|
|
134
|
+
* Settings now mostly live at the class level, excepting `template`
|
|
135
|
+
* Any setting changes causes the template to be recompiled
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Chris Wanstrath
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
Mustache
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
Inspired by [ctemplate][1] and [et][2], Mustache is a
|
|
5
|
+
framework-agnostic way to render logic-free views.
|
|
6
|
+
|
|
7
|
+
As ctemplates says, "It emphasizes separating logic from presentation:
|
|
8
|
+
it is impossible to embed application logic in this template language."
|
|
9
|
+
|
|
10
|
+
For a list of implementations (other than Ruby) and tips, see
|
|
11
|
+
<http://mustache.github.com/>.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Overview
|
|
15
|
+
--------
|
|
16
|
+
|
|
17
|
+
Think of Mustache as a replacement for your views. Instead of views
|
|
18
|
+
consisting of ERB or HAML with random helpers and arbitrary logic,
|
|
19
|
+
your views are broken into two parts: a Ruby class and an HTML
|
|
20
|
+
template.
|
|
21
|
+
|
|
22
|
+
We call the Ruby class the "view" and the HTML template the
|
|
23
|
+
"template."
|
|
24
|
+
|
|
25
|
+
All your logic, decisions, and code is contained in your view. All
|
|
26
|
+
your markup is contained in your template. The template does nothing
|
|
27
|
+
but reference methods in your view.
|
|
28
|
+
|
|
29
|
+
This strict separation makes it easier to write clean templates,
|
|
30
|
+
easier to test your views, and more fun to work on your app's front end.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
Why?
|
|
34
|
+
----
|
|
35
|
+
|
|
36
|
+
I like writing Ruby. I like writing HTML. I like writing JavaScript.
|
|
37
|
+
|
|
38
|
+
I don't like writing ERB, Haml, Liquid, Django Templates, putting Ruby
|
|
39
|
+
in my HTML, or putting JavaScript in my HTML.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
Usage
|
|
43
|
+
-----
|
|
44
|
+
|
|
45
|
+
Quick example:
|
|
46
|
+
|
|
47
|
+
>> require 'mustache'
|
|
48
|
+
=> true
|
|
49
|
+
>> Mustache.render("Hello {{planet}}", :planet => "World!")
|
|
50
|
+
=> "Hello World!"
|
|
51
|
+
|
|
52
|
+
We've got an `examples` folder but here's the canonical one:
|
|
53
|
+
|
|
54
|
+
class Simple < Mustache
|
|
55
|
+
def name
|
|
56
|
+
"Chris"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def value
|
|
60
|
+
10_000
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def taxed_value
|
|
64
|
+
value - (value * 0.4)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def in_ca
|
|
68
|
+
true
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
We simply create a normal Ruby class and define methods. Some methods
|
|
73
|
+
reference others, some return values, some return only booleans.
|
|
74
|
+
|
|
75
|
+
Now let's write the template:
|
|
76
|
+
|
|
77
|
+
Hello {{name}}
|
|
78
|
+
You have just won {{value}} dollars!
|
|
79
|
+
{{#in_ca}}
|
|
80
|
+
Well, {{taxed_value}} dollars, after taxes.
|
|
81
|
+
{{/in_ca}}
|
|
82
|
+
|
|
83
|
+
This template references our view methods. To bring it all together,
|
|
84
|
+
here's the code to render actual HTML;
|
|
85
|
+
|
|
86
|
+
Simple.render
|
|
87
|
+
|
|
88
|
+
Which returns the following:
|
|
89
|
+
|
|
90
|
+
Hello Chris
|
|
91
|
+
You have just won 10000 dollars!
|
|
92
|
+
Well, 6000.0 dollars, after taxes.
|
|
93
|
+
|
|
94
|
+
Simple.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
Tag Types
|
|
98
|
+
---------
|
|
99
|
+
|
|
100
|
+
For a language-agnostic overview of Mustache's template syntax, see
|
|
101
|
+
the `mustache(5)` manpage or
|
|
102
|
+
<http://mustache.github.com/mustache.5.html>.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
Escaping
|
|
106
|
+
--------
|
|
107
|
+
|
|
108
|
+
Mustache does escape all values when using the standard double
|
|
109
|
+
Mustache syntax. Characters which will be escaped: `& \ " < >`. To
|
|
110
|
+
disable escaping, simply use tripple mustaches like
|
|
111
|
+
`{{{unescaped_variable}}}`.
|
|
112
|
+
|
|
113
|
+
Example: Using `{{variable}}` inside a template for `5 > 2` will
|
|
114
|
+
result in `5 > 2`, where as the usage of `{{{variable}}}` will
|
|
115
|
+
result in `5 > 2`.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
Dict-Style Views
|
|
119
|
+
----------------
|
|
120
|
+
|
|
121
|
+
ctemplate and friends want you to hand a dictionary to the template
|
|
122
|
+
processor. Mustache supports a similar concept. Feel free to mix the
|
|
123
|
+
class-based and this more procedural style at your leisure.
|
|
124
|
+
|
|
125
|
+
Given this template (winner.mustache):
|
|
126
|
+
|
|
127
|
+
Hello {{name}}
|
|
128
|
+
You have just won {{value}} bucks!
|
|
129
|
+
|
|
130
|
+
We can fill in the values at will:
|
|
131
|
+
|
|
132
|
+
view = Winner.new
|
|
133
|
+
view[:name] = 'George'
|
|
134
|
+
view[:value] = 100
|
|
135
|
+
view.render
|
|
136
|
+
|
|
137
|
+
Which returns:
|
|
138
|
+
|
|
139
|
+
Hello George
|
|
140
|
+
You have just won 100 bucks!
|
|
141
|
+
|
|
142
|
+
We can re-use the same object, too:
|
|
143
|
+
|
|
144
|
+
view[:name] = 'Tony'
|
|
145
|
+
view.render
|
|
146
|
+
Hello Tony
|
|
147
|
+
You have just won 100 bucks!
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
Templates
|
|
151
|
+
---------
|
|
152
|
+
|
|
153
|
+
A word on templates. By default, a view will try to find its template
|
|
154
|
+
on disk by searching for an HTML file in the current directory that
|
|
155
|
+
follows the classic Ruby naming convention.
|
|
156
|
+
|
|
157
|
+
TemplatePartial => ./template_partial.mustache
|
|
158
|
+
|
|
159
|
+
You can set the search path using `Mustache.template_path`. It can be set on a
|
|
160
|
+
class by class basis:
|
|
161
|
+
|
|
162
|
+
class Simple < Mustache
|
|
163
|
+
self.template_path = File.dirname(__FILE__)
|
|
164
|
+
... etc ...
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
Now `Simple` will look for `simple.mustache` in the directory it resides
|
|
168
|
+
in, no matter the cwd.
|
|
169
|
+
|
|
170
|
+
If you want to just change what template is used you can set
|
|
171
|
+
`Mustache.template_file` directly:
|
|
172
|
+
|
|
173
|
+
Simple.template_file = './blah.mustache'
|
|
174
|
+
|
|
175
|
+
Mustache also allows you to define the extension it'll use.
|
|
176
|
+
|
|
177
|
+
Simple.template_extension = 'xml'
|
|
178
|
+
|
|
179
|
+
Given all other defaults, the above line will cause Mustache to look
|
|
180
|
+
for './blah.xml'
|
|
181
|
+
|
|
182
|
+
Feel free to set the template directly:
|
|
183
|
+
|
|
184
|
+
Simple.template = 'Hi {{person}}!'
|
|
185
|
+
|
|
186
|
+
Or set a different template for a single instance:
|
|
187
|
+
|
|
188
|
+
Simple.new.template = 'Hi {{person}}!'
|
|
189
|
+
|
|
190
|
+
Whatever works.
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
Views
|
|
194
|
+
-----
|
|
195
|
+
|
|
196
|
+
Mustache supports a bit of magic when it comes to views. If you're
|
|
197
|
+
authoring a plugin or extension for a web framework (Sinatra, Rails,
|
|
198
|
+
etc), check out the `view_namespace` and `view_path` settings on the
|
|
199
|
+
`Mustache` class. They will surely provide needed assistance.
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
Helpers
|
|
203
|
+
-------
|
|
204
|
+
|
|
205
|
+
What about global helpers? Maybe you have a nifty `gravatar` function
|
|
206
|
+
you want to use in all your views? No problem.
|
|
207
|
+
|
|
208
|
+
This is just Ruby, after all.
|
|
209
|
+
|
|
210
|
+
module ViewHelpers
|
|
211
|
+
def gravatar(email, size = 30)
|
|
212
|
+
gravatar_id = Digest::MD5.hexdigest(email.to_s.strip.downcase)
|
|
213
|
+
gravatar_for_id(gravatar_id, size)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def gravatar_for_id(gid, size = 30)
|
|
217
|
+
"#{gravatar_host}/avatar/#{gid}?s=#{size}"
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def gravatar_host
|
|
221
|
+
@ssl ? 'https://secure.gravatar.com' : 'http://www.gravatar.com'
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
Then just include it:
|
|
226
|
+
|
|
227
|
+
class Simple < Mustache
|
|
228
|
+
include ViewHelpers
|
|
229
|
+
|
|
230
|
+
def name
|
|
231
|
+
"Chris"
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def value
|
|
235
|
+
10_000
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def taxed_value
|
|
239
|
+
value - (value * 0.4)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def in_ca
|
|
243
|
+
true
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
Great, but what about that `@ssl` ivar in `gravatar_host`? There are
|
|
248
|
+
many ways we can go about setting it.
|
|
249
|
+
|
|
250
|
+
Here's on example which illustrates a key feature of Mustache: you
|
|
251
|
+
are free to use the `initialize` method just as you would in any
|
|
252
|
+
normal class.
|
|
253
|
+
|
|
254
|
+
class Simple < Mustache
|
|
255
|
+
include ViewHelpers
|
|
256
|
+
|
|
257
|
+
def initialize(ssl = false)
|
|
258
|
+
@ssl = ssl
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
... etc ...
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
Now:
|
|
265
|
+
|
|
266
|
+
Simple.new(request.ssl?).render
|
|
267
|
+
|
|
268
|
+
Convoluted but you get the idea.
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
Sinatra
|
|
272
|
+
-------
|
|
273
|
+
|
|
274
|
+
Mustache ships with Sinatra integration. Please see
|
|
275
|
+
`lib/mustache/sinatra.rb` or
|
|
276
|
+
<http://github.com/defunkt/mustache/blob/master/lib/mustache/sinatra.rb>
|
|
277
|
+
for complete documentation.
|
|
278
|
+
|
|
279
|
+
An example Sinatra application is also provided:
|
|
280
|
+
<http://github.com/defunkt/mustache-sinatra-example>
|
|
281
|
+
|
|
282
|
+
If you are upgrading to Sinatra 1.0 and Mustache 0.9.0+ from Mustache
|
|
283
|
+
0.7.0 or lower, the settings have changed. But not that much.
|
|
284
|
+
|
|
285
|
+
See [this diff](http://gist.github.com/345490) for what you need to
|
|
286
|
+
do. Basically, things are named properly now and all should be
|
|
287
|
+
contained in a hash set using `set :mustache, hash`.
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
[Rack::Bug][4]
|
|
291
|
+
--------------
|
|
292
|
+
|
|
293
|
+
Mustache also ships with a `Rack::Bug` panel. In your `config.ru` add
|
|
294
|
+
the following code:
|
|
295
|
+
|
|
296
|
+
require 'rack/bug/panels/mustache_panel'
|
|
297
|
+
use Rack::Bug::MustachePanel
|
|
298
|
+
|
|
299
|
+
Using Rails? Add this to your initializer or environment file:
|
|
300
|
+
|
|
301
|
+
require 'rack/bug/panels/mustache_panel'
|
|
302
|
+
config.middleware.use "Rack::Bug::MustachePanel"
|
|
303
|
+
|
|
304
|
+
[][5]
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
Vim
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
Thanks to [Juvenn Woo](http://github.com/juvenn) for mustache.vim. It
|
|
311
|
+
is included under the contrib/ directory.
|
|
312
|
+
|
|
313
|
+
See <http://gist.github.com/323622> for installation instructions.
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
Emacs
|
|
317
|
+
-----
|
|
318
|
+
|
|
319
|
+
mustache-mode.el is included under the contrib/ directory for any
|
|
320
|
+
Emacs users. Based on Google's tpl-mode for ctemplates, it adds
|
|
321
|
+
support for Mustache's more lenient tag values and includes a few
|
|
322
|
+
commands for your editing pleasure.
|
|
323
|
+
|
|
324
|
+
See <http://gist.github.com/323619> for installation instructions.
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
TextMate
|
|
328
|
+
--------
|
|
329
|
+
|
|
330
|
+
[Mustache.tmbundle](http://github.com/defunkt/Mustache.tmbundle)
|
|
331
|
+
|
|
332
|
+
See <http://gist.github.com/323624> for installation instructions.
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
Command Line
|
|
336
|
+
------------
|
|
337
|
+
|
|
338
|
+
See `mustache(1)` man page or
|
|
339
|
+
<http://mustache.github.com/mustache.1.html>
|
|
340
|
+
for command line docs.
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
Installation
|
|
344
|
+
------------
|
|
345
|
+
|
|
346
|
+
### [RubyGems](http://rubygems.org/)
|
|
347
|
+
|
|
348
|
+
$ gem install mustache
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
Acknowledgements
|
|
352
|
+
----------------
|
|
353
|
+
|
|
354
|
+
Thanks to [Tom Preston-Werner](http://github.com/mojombo) for showing
|
|
355
|
+
me ctemplate and [Leah Culver](http://github.com/leah) for the name "Mustache."
|
|
356
|
+
|
|
357
|
+
Special thanks to [Magnus Holm](http://judofyr.net/) for all his
|
|
358
|
+
awesome work on Mustache's parser.
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
Contributing
|
|
362
|
+
------------
|
|
363
|
+
|
|
364
|
+
Once you've made your great commits:
|
|
365
|
+
|
|
366
|
+
1. [Fork][fk] Mustache
|
|
367
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
|
368
|
+
3. Push to your branch - `git push origin my_branch`
|
|
369
|
+
4. Create an [Issue][is] with a link to your branch
|
|
370
|
+
5. That's it!
|
|
371
|
+
|
|
372
|
+
You might want to checkout Resque's [Contributing][cb] wiki page for information
|
|
373
|
+
on coding standards, new features, etc.
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
Mailing List
|
|
377
|
+
------------
|
|
378
|
+
|
|
379
|
+
To join the list simply send an email to <mustache@librelist.com>. This
|
|
380
|
+
will subscribe you and send you information about your subscription,
|
|
381
|
+
including unsubscribe information.
|
|
382
|
+
|
|
383
|
+
The archive can be found at <http://librelist.com/browser/>.
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
Meta
|
|
387
|
+
----
|
|
388
|
+
|
|
389
|
+
* Code: `git clone git://github.com/defunkt/mustache.git`
|
|
390
|
+
* Home: <http://mustache.github.com>
|
|
391
|
+
* Bugs: <http://github.com/defunkt/mustache/issues>
|
|
392
|
+
* List: <mustache@librelist.com>
|
|
393
|
+
* Test: <http://runcoderun.com/defunkt/mustache>
|
|
394
|
+
* Gems: <http://rubygems.org/gems/mustache>
|
|
395
|
+
|
|
396
|
+
You can also find us in `#{` on irc.freenode.net.
|
|
397
|
+
|
|
398
|
+
[1]: http://code.google.com/p/google-ctemplate/
|
|
399
|
+
[2]: http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html
|
|
400
|
+
[3]: http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html
|
|
401
|
+
[4]: http://github.com/brynary/rack-bug/
|
|
402
|
+
[5]: http://img.skitch.com/20091027-n8pxwwx8r61tc318a15q1n6m14.png
|
|
403
|
+
[cb]: http://wiki.github.com/defunkt/resque/contributing
|
|
404
|
+
[fk]: http://help.github.com/forking/
|
|
405
|
+
[is]: http://github.com/defunkt/mustache/issues
|