sho 0.0.1 → 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 +15 -0
- data/README.md +3 -3
- data/lib/sho/argument_validator.rb +2 -2
- data/lib/sho/configurator.rb +15 -6
- data/lib/sho/version.rb +1 -1
- data/lib/sho.rb +1 -1
- metadata +15 -15
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
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Sho versions
|
2
|
+
|
3
|
+
## 0.0.3 - 2023-09-10
|
4
|
+
|
5
|
+
* Ruby 3+ compatiblity - [@uanka](https://github.com/uanka)
|
6
|
+
|
7
|
+
|
8
|
+
## 0.0.2 - 2018-06-27
|
9
|
+
|
10
|
+
* `yield` in inline templates work (for small inline layouts) -- [@adam12](https://github.com/adam12).
|
11
|
+
|
12
|
+
## 0.0.1 - 2018-06-10
|
13
|
+
|
14
|
+
Initial!
|
15
|
+
|
data/README.md
CHANGED
@@ -48,8 +48,8 @@ You can think about the template as a _method body_, which immediately answers a
|
|
48
48
|
* **How do I test it? How do I set all the context for testing?** Just as with regular method: just create an instance, and call the method, and test the result.
|
49
49
|
* **But where do I put this method?** Wherever you wish! Sho does NOT insist on any particular architecture or code layout, which means you can experiment and evaluate several options, like:
|
50
50
|
* embed rendering in controller/Sinatra app (or even model, if you want to be really naughty today!) for the very first 30-lines-long prototype, then move it elsewhere (like "Extract Method" refactoring pattern, you know?)
|
51
|
-
* embed rendering in your service (operation) objects, so
|
52
|
-
* make Users::List class with `#html`, `#atom` and `#json` methods and use it like `Users::List.new(scope).send(request.format)` or `User::List.send(request.format, scope)`
|
51
|
+
* embed rendering in your service (operation) objects, so corresponding forms and buttons would be nested in the operation, and reused in other places like `Product::Create.new(current_user).button`
|
52
|
+
* make `Users::List` class with `#html`, `#atom` and `#json` methods and use it like `Users::List.new(scope).send(request.format)` or `User::List.send(request.format, scope)`
|
53
53
|
* make `Trailblazer::Cells`-like one-class-per-template objects to call them like `Users::HtmlList.new(scope).()`
|
54
54
|
* ...switch between several of the approaches, or even combine them in the same app!
|
55
55
|
|
@@ -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)
|
116
|
-
|
121
|
+
tilt = tilt.call if cache && tilt.respond_to?(:call)
|
122
|
+
|
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
|
@@ -154,30 +154,30 @@ dependencies:
|
|
154
154
|
name: rubocop
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
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
|
@@ -214,6 +214,7 @@ executables: []
|
|
214
214
|
extensions: []
|
215
215
|
extra_rdoc_files: []
|
216
216
|
files:
|
217
|
+
- Changelog.md
|
217
218
|
- README.md
|
218
219
|
- lib/sho.rb
|
219
220
|
- lib/sho/argument_validator.rb
|
@@ -231,15 +232,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
232
|
requirements:
|
232
233
|
- - ">="
|
233
234
|
- !ruby/object:Gem::Version
|
234
|
-
version: 2.
|
235
|
+
version: 2.7.0
|
235
236
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
237
|
requirements:
|
237
238
|
- - ">="
|
238
239
|
- !ruby/object:Gem::Version
|
239
240
|
version: '0'
|
240
241
|
requirements: []
|
241
|
-
|
242
|
-
rubygems_version: 2.6.14
|
242
|
+
rubygems_version: 3.1.6
|
243
243
|
signing_key:
|
244
244
|
specification_version: 4
|
245
245
|
summary: Experimental post-framework view library
|