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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6824fa2e826773658bce36e4f33d23715d62651b
4
- data.tar.gz: fbe63cdf11cc334f60d87558c0996e6e55614113
2
+ SHA256:
3
+ metadata.gz: 427749263f79f34fd5a984ba28c2a1aabce93e3fd46058d1cbbc35464f31a297
4
+ data.tar.gz: 579438830d604921733e4f8706a3e5f5c9276c10a2265154766d7c58409e7611
5
5
  SHA512:
6
- metadata.gz: ac5a8af9cf6047cbcfdbada0732738fa4802b1c3defd84a25fb352bfa2f49ed269a459f80571bbb54cb3811eb6f08ea2865e9051322069ac9d6e25b1979f7c9c
7
- data.tar.gz: 2049bebaa82fcef22b3ac50c82aeafe86b1cb72b201c9b8a6a5c3f4f38dc2101738e20932bc0e2b89e4c149070def8d89734f1af0f62205532cd856efd3fae2b
6
+ metadata.gz: 899d2e64aab70e4ff24fff5568a1c60f2f633c91a5a96e1f71d2e074fb984d7f1e70021f94b5b626589f621e82c58ed9563379186b81e5c8c6006dca22260338
7
+ data.tar.gz: 4846a578d8a630a7c091e450ffe686344df3dc757e3ab7e8ff1f26c244916bf12783a897a3dc07abdc585786ccf0ecb94a584112deaa7ae6673b62882c6192dd
data/Changelog.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Sho versions
2
2
 
3
+ ## 0.0.3 - 2023-09-10
4
+
5
+ * Ruby 3+ compatiblity - [@uanka](https://github.com/uanka)
6
+
7
+
3
8
  ## 0.0.2 - 2018-06-27
4
9
 
5
10
  * `yield` in inline templates work (for small inline layouts) -- [@adam12](https://github.com/adam12).
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
 
@@ -11,8 +11,8 @@ module Sho
11
11
  end
12
12
 
13
13
  def call(**params)
14
- guard_missing!(params)
15
- guard_unknown!(params)
14
+ guard_missing!(**params)
15
+ guard_unknown!(**params)
16
16
  params.merge(@optional.reject { |key,| params.key?(key) })
17
17
  end
18
18
 
@@ -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) { tilt.render(self, **locals) }
128
+ __send__(layout) { tpl.render(self, **locals) }
120
129
  else
121
- tilt.render(self, **locals, &block)
130
+ tpl.render(self, **locals, &block)
122
131
  end
123
132
  end
124
133
  end
data/lib/sho/version.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Sho
4
4
  MAJOR = 0
5
5
  MINOR = 0
6
- PATCH = 2
6
+ PATCH = 3
7
7
  PRE = nil
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
9
9
  end
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.2
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: 2018-06-27 00:00:00.000000000 Z
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.7.0
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.7.0
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: 0.57.2
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: 0.57.2
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: 1.27.0
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: 1.27.0
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.1.0
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
- rubyforge_project:
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