mustache 1.1.0 → 1.1.1
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 +4 -4
- data/lib/mustache.rb +25 -17
- data/lib/mustache/settings.rb +24 -0
- data/lib/mustache/version.rb +1 -1
- data/test/mustache_test.rb +1 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfcec948b9e5fbd73d9c72e3ade21724d3fd73a1d2ee2ea58ab26bf7e1a341ba
|
4
|
+
data.tar.gz: 1a5d4d062ad29d4a4057a6489f6779d3e61bb7132ecf56fc1ab97a48bfcb926d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afd9888e324611b31fb9a6ac809393b2c42261befce363ab691d68719edb2687dda2129ba64a12367bd0f39d31b1fda861b209345f2abfc06debf67aa0e3ab99
|
7
|
+
data.tar.gz: c225773518109b0eeeecaf89d39faaec30b951361b10c16944f4e016aec6597fc41e75237920dc8c44e00956a00edfcf1b72f2e914ea4dc3f8b296f2436977dc
|
data/lib/mustache.rb
CHANGED
@@ -74,10 +74,19 @@ require 'mustache/utils'
|
|
74
74
|
#
|
75
75
|
class Mustache
|
76
76
|
|
77
|
-
# Initialize a new
|
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
|
-
#
|
95
|
-
#
|
96
|
-
# @view.render("Hi {{thing}}!", :thing => :world)
|
103
|
+
# @example Render view
|
104
|
+
# @view.render("Hi {{thing}}!", :thing => :world)
|
97
105
|
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
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
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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)
|
data/lib/mustache/settings.rb
CHANGED
@@ -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
|
#
|
data/lib/mustache/version.rb
CHANGED
data/test/mustache_test.rb
CHANGED
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: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2019-12-03 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -219,8 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
219
|
- !ruby/object:Gem::Version
|
220
220
|
version: '0'
|
221
221
|
requirements: []
|
222
|
-
|
223
|
-
rubygems_version: 2.7.7
|
222
|
+
rubygems_version: 3.0.3
|
224
223
|
signing_key:
|
225
224
|
specification_version: 4
|
226
225
|
summary: Mustache is a framework-agnostic way to render logic-free views.
|