mustache 1.1.0 → 1.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e67a05eb517f6f5186b678d0ffe92a167d2e7908c7b738ad2d99d0c835c230a1
4
- data.tar.gz: f011440519762ec422c3724be76ed103153d52144ec24b9eb45c133c1c74dc92
3
+ metadata.gz: 1e598c073f543841b69a2384f922a006d8f30ea469b59ffb7400ce6a16970a58
4
+ data.tar.gz: 824baa455f2eeaab4952424cbf84e88eb983ef4559d1a78e27caf2f249d0200d
5
5
  SHA512:
6
- metadata.gz: c207b7321fb06b82c814dddc0c7857bf5aa3f2a3ab7058f269f15bf0545aa2b684f5624800d5779f05f4c98a7bed69ca26bb7e1f1e3a955c397adeac3d7ba6bf
7
- data.tar.gz: 140774643b249d068b45f2d7a00af1b30faa651300ee8b26534e76f6da267dc63c3251bded724bd0c5fbe0506705b26322e6a99bde7375c40492b27ba8ac58f8
6
+ metadata.gz: '02199b9d2d753dad273b70dc41019b10732a904002273f5f7677929574a2301bc235ad4028bf6c4157aaeb127b9766e79e9e43afd7ec4a0f625a9c4273223ad6'
7
+ data.tar.gz: e643d2c2f06222d751bdd6f6b26a3f1d88bd8bca9be050895a8057b3d36e2d43338bd28f31ead374c9c918a0e409d70b9cb1664771552c13b7b9c159dd6042da
data/Rakefile CHANGED
@@ -35,7 +35,7 @@ if command? :ronn
35
35
 
36
36
  desc "Build the manual"
37
37
  task "man:build" do
38
- sh "ronn -br5 --organization=DEFUNKT --manual='Mustache Manual' man/*.ronn"
38
+ sh "ronn -br5 --organization=DEFUNKT --manual='Mustache Manual' man/*.ron"
39
39
  end
40
40
  end
41
41
 
@@ -88,7 +88,7 @@ class Mustache
88
88
  def compile!(exp)
89
89
  case exp.first
90
90
  when :multi
91
- exp[1..-1].reduce("") { |sum, e| sum << compile!(e) }
91
+ exp[1..-1].reduce("".dup) { |sum, e| sum << compile!(e) }
92
92
  when :static
93
93
  str(exp[1])
94
94
  when :mustache
@@ -2,6 +2,30 @@
2
2
  # view class, or a single Mustache instance.
3
3
  class Mustache
4
4
 
5
+ def initialize_settings
6
+ @template = nil
7
+ @template_path = nil
8
+ @template_extension = nil
9
+ @template_name = nil
10
+ @template_file = nil
11
+ @raise_on_context_miss = nil
12
+ end
13
+
14
+ def self.initialize_settings
15
+ @template = nil
16
+ @template_path = nil
17
+ @template_extension = nil
18
+ @template_name = nil
19
+ @template_file = nil
20
+ @raise_on_context_miss = nil
21
+ end
22
+
23
+ initialize_settings
24
+
25
+ def self.inherited(subclass)
26
+ subclass.initialize_settings
27
+ end
28
+
5
29
  #
6
30
  # Template Path
7
31
  #
@@ -22,7 +22,7 @@ class Mustache
22
22
  .split('::')
23
23
  .map do |part|
24
24
  part[0] = part[0].downcase
25
- part.gsub(/[A-Z]/) { |s| "_" << s.downcase }
25
+ part.gsub(/[A-Z]/) { |s| '_'.dup << s.downcase }
26
26
  end
27
27
  .join('/')
28
28
  end
@@ -1,3 +1,3 @@
1
1
  class Mustache
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.2'
3
3
  end
data/lib/mustache.rb CHANGED
@@ -74,10 +74,19 @@ require 'mustache/utils'
74
74
  #
75
75
  class Mustache
76
76
 
77
- # Initialize a new mustache instance.
77
+ # Initialize a new Mustache instance.
78
+ #
78
79
  # @param [Hash] options An options hash
80
+ # @option options [String] template_path
81
+ # @option options [String] template_extension
82
+ # @option options [String] template_file
83
+ # @option options [String] template
84
+ # @option options [String] view_namespace
85
+ # @option options [String] view_path
79
86
  def initialize(options = {})
80
87
  @options = options
88
+
89
+ initialize_settings
81
90
  end
82
91
 
83
92
  # Instantiates an instance of this class and calls `render` with
@@ -91,19 +100,18 @@ class Mustache
91
100
  # Parses our fancy pants template file and returns normal file with
92
101
  # all special {{tags}} and {{#sections}}replaced{{/sections}}.
93
102
  #
94
- # Examples
95
- #
96
- # @view.render("Hi {{thing}}!", :thing => :world)
103
+ # @example Render view
104
+ # @view.render("Hi {{thing}}!", :thing => :world)
97
105
  #
98
- # View.template = "Hi {{thing}}!"
99
- # @view = View.new
100
- # @view.render(:thing => :world)
106
+ # @example Set view template and then render
107
+ # View.template = "Hi {{thing}}!"
108
+ # @view = View.new
109
+ # @view.render(:thing => :world)
101
110
  #
102
111
  # @param [String,Hash] data A String template or a Hash context.
103
112
  # If a Hash is given, we'll try to figure
104
113
  # out the template from the class.
105
114
  # @param [Hash] ctx A Hash context if `data` is a String template.
106
- #
107
115
  # @return [String] Returns a rendered version of a template.
108
116
  def render(data = template, ctx = {})
109
117
  case data
@@ -134,11 +142,11 @@ class Mustache
134
142
 
135
143
  # Context accessors.
136
144
  #
137
- # Example:
138
- # view = Mustache.new
139
- # view[:name] = "Jon"
140
- # view.template = "Hi, {{name}}!"
141
- # view.render # => "Hi, Jon!"
145
+ # @example Context accessors
146
+ # view = Mustache.new
147
+ # view[:name] = "Jon"
148
+ # view.template = "Hi, {{name}}!"
149
+ # view.render # => "Hi, Jon!"
142
150
  def [](key)
143
151
  context[key.to_sym]
144
152
  end
@@ -206,8 +214,8 @@ class Mustache
206
214
  end
207
215
 
208
216
  # Override this to provide custom escaping.
209
- # Example:
210
217
  #
218
+ # @example Overriding #escapeHTML
211
219
  # class PersonView < Mustache
212
220
  # def escapeHTML(str)
213
221
  # my_html_escape_method(str)
@@ -220,7 +228,6 @@ class Mustache
220
228
  # If your override logic is expecting a string, you will
221
229
  # have to call to_s on it yourself.
222
230
  # @param [String] str String to escape.
223
- #
224
231
  # @return [String] Escaped HTML.
225
232
  def escapeHTML(str)
226
233
  CGI.escapeHTML(str)
@@ -237,7 +244,8 @@ class Mustache
237
244
 
238
245
  # When given a symbol or string representing a class, will try to produce an
239
246
  # appropriate view class.
240
- # e.g.
247
+ #
248
+ # @example
241
249
  # Mustache.view_namespace = Hurl::Views
242
250
  # Mustache.view_class(:Partial) # => Hurl::Views::Partial
243
251
  def self.view_class(name)
@@ -283,7 +291,7 @@ class Mustache
283
291
  Mustache::Utils::String.new(underscored).classify
284
292
  end
285
293
 
286
- # TemplatePartial => template_partial
294
+ # TemplatePartial => template_partial
287
295
  # Template::Partial => template/partial
288
296
  # Takes a string but defaults to using the current class' name.
289
297
  def self.underscore(classified = name)