sho 0.0.2 → 0.0.3
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 +5 -5
- data/Changelog.md +5 -0
- data/README.md +1 -1
- data/lib/sho/argument_validator.rb +2 -2
- data/lib/sho/configurator.rb +14 -5
- data/lib/sho/version.rb +1 -1
- data/lib/sho.rb +1 -1
- metadata +10 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 427749263f79f34fd5a984ba28c2a1aabce93e3fd46058d1cbbc35464f31a297
|
|
4
|
+
data.tar.gz: 579438830d604921733e4f8706a3e5f5c9276c10a2265154766d7c58409e7611
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 899d2e64aab70e4ff24fff5568a1c60f2f633c91a5a96e1f71d2e074fb984d7f1e70021f94b5b626589f621e82c58ed9563379186b81e5c8c6006dca22260338
|
|
7
|
+
data.tar.gz: 4846a578d8a630a7c091e450ffe686344df3dc757e3ab7e8ff1f26c244916bf12783a897a3dc07abdc585786ccf0ecb94a584112deaa7ae6673b62882c6192dd
|
data/Changelog.md
CHANGED
data/README.md
CHANGED
|
@@ -135,7 +135,7 @@ end
|
|
|
135
135
|
|
|
136
136
|
**Template caching**
|
|
137
137
|
|
|
138
|
-
Sho creates Tilt templates at a moment of the method definition. This seems to lead to most natural behavior: the templates are found and cached at a moment of code loading/reloading (whatever reloader you use).
|
|
138
|
+
Sho creates Tilt templates at a moment of the method definition. This seems to lead to most natural behavior: the templates are found and cached at a moment of code loading/reloading (whatever reloader you use). Though, you can use `sho.cache = false` to "hard-reload" templates on each method call.
|
|
139
139
|
|
|
140
140
|
## Library status
|
|
141
141
|
|
data/lib/sho/configurator.rb
CHANGED
|
@@ -27,9 +27,13 @@ module Sho
|
|
|
27
27
|
# meaning application's current folder (`Dir.pwd`).
|
|
28
28
|
attr_accessor :base_folder
|
|
29
29
|
|
|
30
|
+
# @return [true, false] cache templates upon initialization. `true` by default.
|
|
31
|
+
attr_accessor :cache
|
|
32
|
+
|
|
30
33
|
# @private
|
|
31
34
|
def initialize(host)
|
|
32
35
|
@host = host
|
|
36
|
+
@cache = true
|
|
33
37
|
end
|
|
34
38
|
|
|
35
39
|
# Generates instance method named `name` in a host module, which renders template from
|
|
@@ -53,7 +57,8 @@ module Sho
|
|
|
53
57
|
# @param mandatory [Array<Symbol>] list of mandatory params;
|
|
54
58
|
# @param optional [Hash{Symbol => Object}] list of optional params and their default values
|
|
55
59
|
def template(name, template, *mandatory, _layout: nil, **optional)
|
|
56
|
-
tpl = Tilt.new(File.expand_path(template, base_folder || Dir.pwd))
|
|
60
|
+
tpl = proc { Tilt.new(File.expand_path(template, base_folder || Dir.pwd)) }
|
|
61
|
+
|
|
57
62
|
define_template_method(name, tpl, mandatory, optional, _layout)
|
|
58
63
|
end
|
|
59
64
|
|
|
@@ -76,7 +81,7 @@ module Sho
|
|
|
76
81
|
# @param optional [Hash{Symbol => Object}] list of optional params and their default values
|
|
77
82
|
def template_relative(name, template, *mandatory, _layout: nil, **optional)
|
|
78
83
|
base = File.dirname(caller(1..1).first.split(':').first)
|
|
79
|
-
tpl = Tilt.new(File.expand_path(template, base))
|
|
84
|
+
tpl = proc { Tilt.new(File.expand_path(template, base)) }
|
|
80
85
|
|
|
81
86
|
define_template_method(name, tpl, mandatory, optional, _layout)
|
|
82
87
|
end
|
|
@@ -111,14 +116,18 @@ module Sho
|
|
|
111
116
|
|
|
112
117
|
private
|
|
113
118
|
|
|
114
|
-
def define_template_method(name, tilt, mandatory, optional, layout)
|
|
119
|
+
def define_template_method(name, tilt, mandatory, optional, layout) # rubocop:disable Metrics/MethodLength
|
|
115
120
|
arguments = ArgumentValidator.new(*mandatory, **optional)
|
|
121
|
+
tilt = tilt.call if cache && tilt.respond_to?(:call)
|
|
122
|
+
|
|
116
123
|
@host.__send__(:define_method, name) do |**locals, &block|
|
|
117
124
|
locals = arguments.call(**locals)
|
|
125
|
+
tpl = tilt.respond_to?(:call) ? tilt.call : tilt
|
|
126
|
+
|
|
118
127
|
if layout
|
|
119
|
-
__send__(layout) {
|
|
128
|
+
__send__(layout) { tpl.render(self, **locals) }
|
|
120
129
|
else
|
|
121
|
-
|
|
130
|
+
tpl.render(self, **locals, &block)
|
|
122
131
|
end
|
|
123
132
|
end
|
|
124
133
|
end
|
data/lib/sho/version.rb
CHANGED
data/lib/sho.rb
CHANGED
|
@@ -22,7 +22,7 @@ module Sho
|
|
|
22
22
|
# included into.
|
|
23
23
|
def self.included(mod)
|
|
24
24
|
mod.define_singleton_method(:sho) {
|
|
25
|
-
@__sho_configurator__ ||= Configurator.new(mod)
|
|
25
|
+
@__sho_configurator__ ||= Configurator.new(mod) # rubocop:disable Naming/MemoizedInstanceVariableName
|
|
26
26
|
}
|
|
27
27
|
end
|
|
28
28
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sho
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Victor Shepelev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-09-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: tilt
|
|
@@ -86,14 +86,14 @@ dependencies:
|
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 3.
|
|
89
|
+
version: 3.12.0
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 3.
|
|
96
|
+
version: 3.12.0
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: rspec-its
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -156,28 +156,28 @@ dependencies:
|
|
|
156
156
|
requirements:
|
|
157
157
|
- - "~>"
|
|
158
158
|
- !ruby/object:Gem::Version
|
|
159
|
-
version:
|
|
159
|
+
version: 1.56.0
|
|
160
160
|
type: :development
|
|
161
161
|
prerelease: false
|
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
|
163
163
|
requirements:
|
|
164
164
|
- - "~>"
|
|
165
165
|
- !ruby/object:Gem::Version
|
|
166
|
-
version:
|
|
166
|
+
version: 1.56.0
|
|
167
167
|
- !ruby/object:Gem::Dependency
|
|
168
168
|
name: rubocop-rspec
|
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
|
170
170
|
requirements:
|
|
171
171
|
- - "~>"
|
|
172
172
|
- !ruby/object:Gem::Version
|
|
173
|
-
version:
|
|
173
|
+
version: 2.24.0
|
|
174
174
|
type: :development
|
|
175
175
|
prerelease: false
|
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
|
177
177
|
requirements:
|
|
178
178
|
- - "~>"
|
|
179
179
|
- !ruby/object:Gem::Version
|
|
180
|
-
version:
|
|
180
|
+
version: 2.24.0
|
|
181
181
|
- !ruby/object:Gem::Dependency
|
|
182
182
|
name: rake
|
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -232,15 +232,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
232
232
|
requirements:
|
|
233
233
|
- - ">="
|
|
234
234
|
- !ruby/object:Gem::Version
|
|
235
|
-
version: 2.
|
|
235
|
+
version: 2.7.0
|
|
236
236
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
237
|
requirements:
|
|
238
238
|
- - ">="
|
|
239
239
|
- !ruby/object:Gem::Version
|
|
240
240
|
version: '0'
|
|
241
241
|
requirements: []
|
|
242
|
-
|
|
243
|
-
rubygems_version: 2.6.10
|
|
242
|
+
rubygems_version: 3.1.6
|
|
244
243
|
signing_key:
|
|
245
244
|
specification_version: 4
|
|
246
245
|
summary: Experimental post-framework view library
|