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.
Files changed (104) hide show
  1. data/LICENSE +21 -0
  2. data/README.md +38 -0
  3. data/lib/common_mob.rb +9 -0
  4. data/lib/common_mob/digest.rb +43 -0
  5. data/lib/common_mob/erb.rb +72 -0
  6. data/lib/common_mob/file.rb +55 -0
  7. data/lib/common_mob/patch.rb +51 -0
  8. data/lib/common_mob/resource_locator.rb +9 -0
  9. data/lib/common_mob/shell.rb +323 -0
  10. data/lib/common_mob/template.rb +23 -0
  11. data/lib/common_mob/version.rb +3 -0
  12. data/targets/crontab_patch.rb +37 -0
  13. data/targets/extract.rb +40 -0
  14. data/targets/fetch.rb +40 -0
  15. data/targets/files.rb +244 -0
  16. data/targets/git.rb +84 -0
  17. data/targets/group.rb +33 -0
  18. data/targets/packages.rb +94 -0
  19. data/targets/ruby.rb +13 -0
  20. data/targets/services.rb +184 -0
  21. data/targets/shell.rb +43 -0
  22. data/targets/user.rb +108 -0
  23. data/vendor/mustache/CONTRIBUTORS +9 -0
  24. data/vendor/mustache/HISTORY.md +135 -0
  25. data/vendor/mustache/LICENSE +20 -0
  26. data/vendor/mustache/README.md +405 -0
  27. data/vendor/mustache/Rakefile +103 -0
  28. data/vendor/mustache/benchmarks/complex.erb +15 -0
  29. data/vendor/mustache/benchmarks/complex.haml +12 -0
  30. data/vendor/mustache/benchmarks/helper.rb +20 -0
  31. data/vendor/mustache/benchmarks/simple.erb +5 -0
  32. data/vendor/mustache/benchmarks/speed.rb +78 -0
  33. data/vendor/mustache/bin/mustache +90 -0
  34. data/vendor/mustache/contrib/mustache-mode.el +278 -0
  35. data/vendor/mustache/contrib/mustache.vim +69 -0
  36. data/vendor/mustache/examples/hash.rb +16 -0
  37. data/vendor/mustache/examples/hash.yml +5 -0
  38. data/vendor/mustache/examples/projects.mustache +26 -0
  39. data/vendor/mustache/examples/projects.yml +28 -0
  40. data/vendor/mustache/examples/self.mustache +4 -0
  41. data/vendor/mustache/examples/self.yml +3 -0
  42. data/vendor/mustache/examples/simple.mustache +10 -0
  43. data/vendor/mustache/examples/simple.rb +24 -0
  44. data/vendor/mustache/lib/mustache.rb +358 -0
  45. data/vendor/mustache/lib/mustache/context.rb +108 -0
  46. data/vendor/mustache/lib/mustache/generator.rb +160 -0
  47. data/vendor/mustache/lib/mustache/parser.rb +230 -0
  48. data/vendor/mustache/lib/mustache/sinatra.rb +180 -0
  49. data/vendor/mustache/lib/mustache/template.rb +59 -0
  50. data/vendor/mustache/lib/mustache/version.rb +3 -0
  51. data/vendor/mustache/lib/rack/bug/panels/mustache_panel.rb +81 -0
  52. data/vendor/mustache/lib/rack/bug/panels/mustache_panel/mustache_extension.rb +27 -0
  53. data/vendor/mustache/lib/rack/bug/panels/mustache_panel/view.mustache +46 -0
  54. data/vendor/mustache/man/mustache.1 +180 -0
  55. data/vendor/mustache/man/mustache.1.html +204 -0
  56. data/vendor/mustache/man/mustache.1.ron +127 -0
  57. data/vendor/mustache/man/mustache.5 +576 -0
  58. data/vendor/mustache/man/mustache.5.html +415 -0
  59. data/vendor/mustache/man/mustache.5.ron +324 -0
  60. data/vendor/mustache/mustache.gemspec +32 -0
  61. data/vendor/mustache/test/autoloading_test.rb +52 -0
  62. data/vendor/mustache/test/fixtures/comments.mustache +1 -0
  63. data/vendor/mustache/test/fixtures/comments.rb +14 -0
  64. data/vendor/mustache/test/fixtures/complex_view.mustache +17 -0
  65. data/vendor/mustache/test/fixtures/complex_view.rb +34 -0
  66. data/vendor/mustache/test/fixtures/crazy_recursive.mustache +9 -0
  67. data/vendor/mustache/test/fixtures/crazy_recursive.rb +31 -0
  68. data/vendor/mustache/test/fixtures/delimiters.mustache +8 -0
  69. data/vendor/mustache/test/fixtures/delimiters.rb +23 -0
  70. data/vendor/mustache/test/fixtures/double_section.mustache +7 -0
  71. data/vendor/mustache/test/fixtures/double_section.rb +14 -0
  72. data/vendor/mustache/test/fixtures/escaped.mustache +1 -0
  73. data/vendor/mustache/test/fixtures/escaped.rb +14 -0
  74. data/vendor/mustache/test/fixtures/inner_partial.mustache +1 -0
  75. data/vendor/mustache/test/fixtures/inner_partial.txt +1 -0
  76. data/vendor/mustache/test/fixtures/inverted_section.mustache +7 -0
  77. data/vendor/mustache/test/fixtures/inverted_section.rb +14 -0
  78. data/vendor/mustache/test/fixtures/lambda.mustache +7 -0
  79. data/vendor/mustache/test/fixtures/lambda.rb +31 -0
  80. data/vendor/mustache/test/fixtures/namespaced.mustache +1 -0
  81. data/vendor/mustache/test/fixtures/namespaced.rb +25 -0
  82. data/vendor/mustache/test/fixtures/nested_objects.mustache +17 -0
  83. data/vendor/mustache/test/fixtures/nested_objects.rb +35 -0
  84. data/vendor/mustache/test/fixtures/node.mustache +8 -0
  85. data/vendor/mustache/test/fixtures/partial_with_module.mustache +3 -0
  86. data/vendor/mustache/test/fixtures/partial_with_module.rb +37 -0
  87. data/vendor/mustache/test/fixtures/passenger.conf +5 -0
  88. data/vendor/mustache/test/fixtures/passenger.rb +27 -0
  89. data/vendor/mustache/test/fixtures/recursive.mustache +4 -0
  90. data/vendor/mustache/test/fixtures/recursive.rb +14 -0
  91. data/vendor/mustache/test/fixtures/simple.mustache +5 -0
  92. data/vendor/mustache/test/fixtures/simple.rb +26 -0
  93. data/vendor/mustache/test/fixtures/template_partial.mustache +2 -0
  94. data/vendor/mustache/test/fixtures/template_partial.rb +18 -0
  95. data/vendor/mustache/test/fixtures/template_partial.txt +4 -0
  96. data/vendor/mustache/test/fixtures/unescaped.mustache +1 -0
  97. data/vendor/mustache/test/fixtures/unescaped.rb +14 -0
  98. data/vendor/mustache/test/fixtures/utf8.mustache +3 -0
  99. data/vendor/mustache/test/fixtures/utf8_partial.mustache +1 -0
  100. data/vendor/mustache/test/helper.rb +7 -0
  101. data/vendor/mustache/test/mustache_test.rb +536 -0
  102. data/vendor/mustache/test/parser_test.rb +54 -0
  103. data/vendor/mustache/test/partial_test.rb +168 -0
  104. metadata +167 -0
@@ -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
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ Mustache.template_file = File.dirname(__FILE__) + '/simple.mustache'
5
+ view = Mustache.new
6
+
7
+ print "Your name: "
8
+ view[:name] = gets
9
+ view[:value] = value = rand(10_000)
10
+ print "Are you in CA? [y/n] "
11
+
12
+ if view[:in_ca] = gets.to_s.downcase[0].chr == 'y'
13
+ view[:taxed_value] = value - (value * 0.4)
14
+ end
15
+
16
+ puts view.render
@@ -0,0 +1,5 @@
1
+ ---
2
+ name: Chris
3
+ value: 10,000
4
+ in_ca: no
5
+ ---
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE HTML>
2
+ <html>
3
+ <head>
4
+ <title> projects </title>
5
+ <style>.row { width: {{width}}px; }</style>
6
+ </head>
7
+
8
+ <body>
9
+ <h1> projects </h1>
10
+
11
+ <div class="row">
12
+ {{#projects}}
13
+ <a href="{{url}}" class="block">
14
+ <h2> {{name}} </h2>
15
+ <p> {{description}} </p>
16
+ </a>
17
+ {{/projects}}
18
+ </div>
19
+
20
+ <div class="back">
21
+ <a href="/">
22
+ &#8617;
23
+ </a>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,28 @@
1
+ ---
2
+ projects:
3
+ - name: resque
4
+ url: http://github.com/defunkt/resque
5
+ description: A Redis-backed Ruby library for queueing and working.
6
+ - name: mustache
7
+ url: http://defunkt.github.com/mustache
8
+ description: Logic-less templates.
9
+ - name: pystache
10
+ url: http://github.com/defunkt/pystache
11
+ description: Mustache in Python
12
+ - name: hub
13
+ url: http://github.com/defunkt/hub
14
+ description: hub introduces git to GitHub
15
+ - name: repl
16
+ url: http://github.com/defunkt/repl
17
+ description: sometimes you need a repl
18
+ - name: gist
19
+ url: http://github.com/defunkt/gist
20
+ description: Absolutely the best command line gister.
21
+ - name: gem-man
22
+ url: http://defunkt.github.com/gem-man/
23
+ description: "View a RubyGem's man page"
24
+ - name: hurl
25
+ url: http://hurl.it/
26
+ description: Hurl makes HTTP requests
27
+ width: 4968
28
+ ---
@@ -0,0 +1,4 @@
1
+ The Beatles were:
2
+ {{#names}}
3
+ * {{to_s}}
4
+ {{/names}}
@@ -0,0 +1,3 @@
1
+ ---
2
+ names: [ John, Paul, George, Ringo ]
3
+ ---
@@ -0,0 +1,10 @@
1
+ Hello {{name}}
2
+ You have just won ${{value}}!
3
+
4
+ {{#in_ca}}
5
+ Well, ${{taxed_value}}, after taxes.
6
+ {{/in_ca}}
7
+
8
+ {{^in_ca}}
9
+ You're lucky - in CA you'd be taxed like crazy!
10
+ {{/in_ca}}
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class Simple < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+
7
+ def name
8
+ "Chris"
9
+ end
10
+
11
+ def value
12
+ 10_000
13
+ end
14
+
15
+ def taxed_value
16
+ value - (value * 0.4)
17
+ end
18
+
19
+ def in_ca
20
+ true
21
+ end
22
+ end
23
+
24
+ puts Simple.render if $0 == __FILE__
@@ -0,0 +1,358 @@
1
+ require 'mustache/template'
2
+ require 'mustache/context'
3
+
4
+ # Mustache is the base class from which your Mustache subclasses
5
+ # should inherit (though it can be used on its own).
6
+ #
7
+ # The typical Mustache workflow is as follows:
8
+ #
9
+ # * Create a Mustache subclass: class Stats < Mustache
10
+ # * Create a template: stats.mustache
11
+ # * Instantiate an instance: view = Stats.new
12
+ # * Render that instance: view.render
13
+ #
14
+ # You can skip the instantiation by calling `Stats.render` directly.
15
+ #
16
+ # While Mustache will do its best to load and render a template for
17
+ # you, this process is completely customizable using a few options.
18
+ #
19
+ # All settings can be overriden at the class level.
20
+ #
21
+ # For example, going with the above example, we can use
22
+ # `Stats.template_path = "/usr/local/templates"` to specify the path
23
+ # Mustache uses to find templates.
24
+ #
25
+ # Here are the available options:
26
+ #
27
+ # * template_path
28
+ #
29
+ # The `template_path` setting determines the path Mustache uses when
30
+ # looking for a template. By default it is "."
31
+ # Setting it to /usr/local/templates, for example, means (given all
32
+ # other settings are default) a Mustache subclass `Stats` will try to
33
+ # load /usr/local/templates/stats.mustache
34
+ #
35
+ # * template_extension
36
+ #
37
+ # The `template_extension` is the extension Mustache uses when looking
38
+ # for template files. By default it is "mustache"
39
+ #
40
+ # * template_file
41
+ #
42
+ # You can tell Mustache exactly which template to us with this
43
+ # setting. It can be a relative or absolute path.
44
+ #
45
+ # * template
46
+ #
47
+ # Sometimes you want Mustache to render a string, not a file. In those
48
+ # cases you may set the `template` setting. For example:
49
+ #
50
+ # >> Mustache.render("Hello {{planet}}", :planet => "World!")
51
+ # => "Hello World!"
52
+ #
53
+ # The `template` setting is also available on instances.
54
+ #
55
+ # view = Mustache.new
56
+ # view.template = "Hi, {{person}}!"
57
+ # view[:person] = 'Mom'
58
+ # view.render # => Hi, mom!
59
+ #
60
+ # * view_namespace
61
+ #
62
+ # To make life easy on those developing Mustache plugins for web frameworks or
63
+ # other libraries, Mustache will attempt to load view classes (i.e. Mustache
64
+ # subclasses) using the `view_class` class method. The `view_namespace` tells
65
+ # Mustache under which constant view classes live. By default it is `Object`.
66
+ #
67
+ # * view_path
68
+ #
69
+ # Similar to `template_path`, the `view_path` option tells Mustache where to look
70
+ # for files containing view classes when using the `view_class` method.
71
+ #
72
+ class Mustache
73
+ # Helper method for quickly instantiating and rendering a view.
74
+ def self.render(*args)
75
+ new.render(*args)
76
+ end
77
+
78
+ # Alias for `render`
79
+ def self.to_html(*args)
80
+ render(*args)
81
+ end
82
+
83
+ # Alias for `render`
84
+ def self.to_text(*args)
85
+ render(*args)
86
+ end
87
+
88
+ # Given a file name and an optional context, attempts to load and
89
+ # render the file as a template.
90
+ def self.render_file(name, context = {})
91
+ render(partial(name), context)
92
+ end
93
+
94
+ # Given a file name and an optional context, attempts to load and
95
+ # render the file as a template.
96
+ def render_file(name, context = {})
97
+ self.class.render_file(name, context)
98
+ end
99
+
100
+ # Given a name, attempts to read a file and return the contents as a
101
+ # string. The file is not rendered, so it might contain
102
+ # {{mustaches}}.
103
+ #
104
+ # Call `render` if you need to process it.
105
+ def self.partial(name)
106
+ File.read("#{template_path}/#{name}.#{template_extension}")
107
+ end
108
+
109
+ # Override this in your subclass if you want to do fun things like
110
+ # reading templates from a database. It will be rendered by the
111
+ # context, so all you need to do is return a string.
112
+ def partial(name)
113
+ self.class.partial(name)
114
+ end
115
+
116
+ # The template path informs your Mustache subclass where to look for its
117
+ # corresponding template. By default it's the current directory (".")
118
+ def self.template_path
119
+ @template_path ||= inheritable_config_for :template_path, '.'
120
+ end
121
+
122
+ def self.template_path=(path)
123
+ @template_path = File.expand_path(path)
124
+ @template = nil
125
+ end
126
+
127
+ # Alias for `template_path`
128
+ def self.path
129
+ template_path
130
+ end
131
+
132
+ # Alias for `template_path`
133
+ def self.path=(path)
134
+ self.template_path = path
135
+ end
136
+
137
+ # A Mustache template's default extension is 'mustache'
138
+ def self.template_extension
139
+ @template_extension ||= inheritable_config_for :template_extension, 'mustache'
140
+ end
141
+
142
+ def self.template_extension=(template_extension)
143
+ @template_extension = template_extension
144
+ @template = nil
145
+ end
146
+
147
+ # The template name is the Mustache template file without any
148
+ # extension or other information. Defaults to `class_name`.
149
+ def self.template_name
150
+ @template_name || underscore
151
+ end
152
+
153
+ def self.template_name=(template_name)
154
+ @template_name = template_name
155
+ @template = nil
156
+ end
157
+
158
+ # The template file is the absolute path of the file Mustache will
159
+ # use as its template. By default it's ./class_name.mustache
160
+ def self.template_file
161
+ @template_file || "#{path}/#{template_name}.#{template_extension}"
162
+ end
163
+
164
+ def self.template_file=(template_file)
165
+ @template_file = template_file
166
+ @template = nil
167
+ end
168
+
169
+ # The template is the actual string Mustache uses as its template.
170
+ # There is a bit of magic here: what we get back is actually a
171
+ # Mustache::Template object here, but you can still safely use
172
+ # `template=` with a string.
173
+ def self.template
174
+ @template ||= templateify(File.read(template_file))
175
+ end
176
+
177
+ def self.template=(template)
178
+ @template = templateify(template)
179
+ end
180
+
181
+ # The constant under which Mustache will look for views. By default it's
182
+ # `Object`, but it might be nice to set it to something like `Hurl::Views` if
183
+ # your app's main namespace is `Hurl`.
184
+ def self.view_namespace
185
+ @view_namespace ||= inheritable_config_for(:view_namespace, Object)
186
+ end
187
+
188
+ def self.view_namespace=(namespace)
189
+ @view_namespace = namespace
190
+ end
191
+
192
+ # Mustache searches the view path for .rb files to require when asked to find a
193
+ # view class. Defaults to "."
194
+ def self.view_path
195
+ @view_path ||= inheritable_config_for(:view_path, '.')
196
+ end
197
+
198
+ def self.view_path=(path)
199
+ @view_path = path
200
+ end
201
+
202
+ # When given a symbol or string representing a class, will try to produce an
203
+ # appropriate view class.
204
+ # e.g.
205
+ # Mustache.view_namespace = Hurl::Views
206
+ # Mustache.view_class(:Partial) # => Hurl::Views::Partial
207
+ def self.view_class(name)
208
+ if name != classify(name.to_s)
209
+ name = classify(name.to_s)
210
+ end
211
+
212
+ # Emptiness begets emptiness.
213
+ if name.to_s == ''
214
+ return Mustache
215
+ end
216
+
217
+ file_name = underscore(name)
218
+ namespace = view_namespace
219
+
220
+ if namespace.const_defined?(:Views) && namespace::Views.const_defined?(name)
221
+ namespace::Views.const_get(name)
222
+ elsif namespace.const_defined?(name)
223
+ namespace.const_get(name)
224
+ elsif File.exists?(file = "#{view_path}/#{file_name}.rb")
225
+ require "#{file}".chomp('.rb')
226
+ if namespace.const_defined?(:Views)
227
+ namespace::Views.const_get(name)
228
+ else
229
+ namespace.const_get(name)
230
+ end
231
+ else
232
+ Mustache
233
+ end
234
+ rescue NameError
235
+ Mustache
236
+ end
237
+
238
+ # Should an exception be raised when we cannot find a corresponding method
239
+ # or key in the current context? By default this is false to emulate ctemplate's
240
+ # behavior, but it may be useful to enable when debugging or developing.
241
+ #
242
+ # If set to true and there is a context miss, `Mustache::ContextMiss` will
243
+ # be raised.
244
+ def self.raise_on_context_miss?
245
+ @raise_on_context_miss
246
+ end
247
+
248
+ def self.raise_on_context_miss=(boolean)
249
+ @raise_on_context_miss = boolean
250
+ end
251
+
252
+ # Has this template already been compiled? Compilation is somewhat
253
+ # expensive so it may be useful to check this before attempting it.
254
+ def self.compiled?
255
+ @template.is_a? Template
256
+ end
257
+
258
+ # Has this instance or its class already compiled a template?
259
+ def compiled?
260
+ (@template && @template.is_a?(Template)) || self.class.compiled?
261
+ end
262
+
263
+ # template_partial => TemplatePartial
264
+ def self.classify(underscored)
265
+ underscored.split(/[-_]/).map do |part|
266
+ part[0] = part[0].chr.upcase; part
267
+ end.join
268
+ end
269
+
270
+ # TemplatePartial => template_partial
271
+ # Takes a string but defaults to using the current class' name.
272
+ def self.underscore(classified = name)
273
+ classified = name if classified.to_s.empty?
274
+ classified = superclass.name if classified.to_s.empty?
275
+
276
+ string = classified.dup.split('::').last
277
+ string[0] = string[0].chr.downcase
278
+ string.gsub(/[A-Z]/) { |s| "_#{s.downcase}"}
279
+ end
280
+
281
+ # Turns a string into a Mustache::Template. If passed a Template,
282
+ # returns it.
283
+ def self.templateify(obj)
284
+ if obj.is_a?(Template)
285
+ obj
286
+ else
287
+ Template.new(obj.to_s)
288
+ end
289
+ end
290
+
291
+ # Return the value of the configuration setting on the superclass, or return
292
+ # the default.
293
+ #
294
+ # attr_name - Symbol name of the attribute. It should match the instance variable.
295
+ # default - Default value to use if the superclass does not respond.
296
+ #
297
+ # Returns the inherited or default configuration setting.
298
+ def self.inheritable_config_for(attr_name, default)
299
+ superclass.respond_to?(attr_name) ? superclass.send(attr_name) : default
300
+ end
301
+
302
+ def templateify(obj)
303
+ self.class.templateify(obj)
304
+ end
305
+
306
+ # The template can be set at the instance level.
307
+ def template
308
+ @template ||= self.class.template
309
+ end
310
+
311
+ def template=(template)
312
+ @template = templateify(template)
313
+ end
314
+
315
+ # Instance level version of `Mustache.raise_on_context_miss?`
316
+ def raise_on_context_miss?
317
+ self.class.raise_on_context_miss? || @raise_on_context_miss
318
+ end
319
+ attr_writer :raise_on_context_miss
320
+
321
+ # A helper method which gives access to the context at a given time.
322
+ # Kind of a hack for now, but useful when you're in an iterating section
323
+ # and want access to the hash currently being iterated over.
324
+ def context
325
+ @context ||= Context.new(self)
326
+ end
327
+
328
+ # Context accessors.
329
+ #
330
+ # view = Mustache.new
331
+ # view[:name] = "Jon"
332
+ # view.template = "Hi, {{name}}!"
333
+ # view.render # => "Hi, Jon!"
334
+ def [](key)
335
+ context[key.to_sym]
336
+ end
337
+
338
+ def []=(key, value)
339
+ context[key.to_sym] = value
340
+ end
341
+
342
+ # Parses our fancy pants template file and returns normal file with
343
+ # all special {{tags}} and {{#sections}}replaced{{/sections}}.
344
+ def render(data = template, ctx = {})
345
+ tpl = templateify(data)
346
+
347
+ return tpl.render(context) if ctx == {}
348
+
349
+ begin
350
+ context.push(ctx)
351
+ tpl.render(context)
352
+ ensure
353
+ context.pop
354
+ end
355
+ end
356
+ alias_method :to_html, :render
357
+ alias_method :to_text, :render
358
+ end