rendry 0.2.0 → 0.2.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rendry/version.rb +1 -1
  3. data/lib/rendry.rb +15 -26
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fda28c5a0d8a7165d77da8ad9eac00950005d67a91905ced6f2db63dceca246
4
- data.tar.gz: 56072ac6f66932de96031dfea4168313db30f48a708397201463821f08122e0e
3
+ metadata.gz: 043bde156ddb2a1af19b6c8507e676330b4ad40a079cc8850ced810396559dfa
4
+ data.tar.gz: bf349c54a7025081672066beb879e8ca8fa4d5e2eecf81c80c4f23f2cec85d50
5
5
  SHA512:
6
- metadata.gz: 29490b541d776a03fdab7b7feedf00c5033d8c1e985f01c2c69c7735e4acefa769b6e522c4a3de13289a81bcecc901a053c89f62140393ceedb7546fb3fdc73f
7
- data.tar.gz: 620c4bb000dfc5b6ce4834bf2156b8b790c3a9480b98f3d6f8866d3a8acbdda87e30652625473ee4c475c4f81c86dac51198e149ad3b04c68947f07dec690d98
6
+ metadata.gz: 8912d9c980908d713576dc50307c2ef7b9bd09a9f0be7a3072ea8507b6d491c6af0236f84a428f9adc384702195fdfb6a966322a9f5422f709462699a9ad910b
7
+ data.tar.gz: 1dd76f09af3eccbf79b653abcbc0c1371b27a4f281699a35157264244e637799ac1124d50dfb8343fde8866225a2401d13de16dae7c39502ddb5a87780067e6d
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rendry
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/rendry.rb CHANGED
@@ -69,15 +69,8 @@ module Rendry
69
69
  if block
70
70
  children = Builder.new(enabled: @enabled)
71
71
  result = Rendry.evaluate(children, &block)
72
- output = children.render
73
- if Rendry.appendable_result?(result) && !result.is_a?(SafeHTML)
74
- output = output.dup if output.frozen?
75
- output << CGI.escapeHTML(result.to_s)
76
- elsif result.is_a?(SafeHTML)
77
- output = output.dup if output.frozen?
78
- output << result
79
- end
80
- content = SafeHTML.new(output)
72
+ children.append_result(result)
73
+ content = SafeHTML.new(children.render)
81
74
  end
82
75
 
83
76
  output = +"<#{name}#{format_attributes(attributes)}>"
@@ -153,15 +146,13 @@ module Rendry
153
146
  helper = context && context.respond_to?(name) ? context.method(name) : nil
154
147
  has_arguments = !(content.nil? && attributes.empty? && !block)
155
148
  if helper && !(helper.arity == 0 && has_arguments)
156
- result = if content.nil? && attributes.empty? && !block
149
+ if content.nil? && attributes.empty? && !block
157
150
  context.public_send(name)
158
151
  elsif content.nil?
159
152
  context.public_send(name, **attributes, &block)
160
153
  else
161
154
  context.public_send(name, content, **attributes, &block)
162
155
  end
163
- write_escaped_result(result)
164
- self
165
156
  else
166
157
  tag(name.to_s.tr("_", "-"), content, **attributes, &block)
167
158
  end
@@ -174,18 +165,19 @@ module Rendry
174
165
  name.to_s.match?(/\A[a-z][a-z0-9_]*\z/) || super
175
166
  end
176
167
 
177
- private
178
-
179
- def write(string)
180
- @output << string if @enabled
181
- end
182
-
183
- def write_escaped_result(result)
168
+ def append_result(result)
184
169
  if result.is_a?(SafeHTML)
185
170
  write result
186
171
  elsif Rendry.appendable_result?(result)
187
172
  write CGI.escapeHTML(result.to_s)
188
173
  end
174
+ self
175
+ end
176
+
177
+ private
178
+
179
+ def write(string)
180
+ @output << string if @enabled
189
181
  end
190
182
 
191
183
  def refresh_wrapper(html, config)
@@ -255,11 +247,7 @@ module Rendry
255
247
 
256
248
  builder = Builder.new
257
249
  result = Rendry.evaluate(builder, self, context: view_context, &block)
258
- if result.is_a?(SafeHTML)
259
- builder.output << result
260
- elsif Rendry.appendable_result?(result)
261
- builder.output << CGI.escapeHTML(result.to_s)
262
- end
250
+ builder.append_result(result)
263
251
  SafeHTML.new(builder.render)
264
252
  end
265
253
  end
@@ -467,14 +455,15 @@ module Rendry
467
455
  Thread.current[:rendry_current_fragments] = fragments.map(&:to_s)
468
456
  Thread.current[:rendry_root_builder] = builder
469
457
  begin
470
- evaluate(builder, &block)
458
+ result = evaluate(builder, &block)
471
459
  ensure
472
460
  Thread.current[:rendry_current_fragments] = previous_fragments
473
461
  Thread.current[:rendry_root_builder] = previous_root
474
462
  end
475
463
  else
476
- evaluate(builder, &block)
464
+ result = evaluate(builder, &block)
477
465
  end
466
+ builder.append_result(result)
478
467
  SafeHTML.new(builder.render)
479
468
  end
480
469
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rendry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - NICE-DEV226