phlex 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of phlex might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d4cbcb774d4dca95d1cb9740c0a002fd394c6887dec1e1cabe543c87f94308b
4
- data.tar.gz: 1df41572816aefd255defc3ceace6e4c5eaeb5f462d26e2605fc751a4ea3d3d0
3
+ metadata.gz: 72f6baa9bd23ce981517a40897f2bb63a1cbd60fbc87bb127883e8eeb36cc302
4
+ data.tar.gz: 5abc8c59a81cdff51f5da9250a28d9cc42308b467aa662b155fb1d28eca4a1c2
5
5
  SHA512:
6
- metadata.gz: 589006a44bc566ce1e1dfc90f1e05e9b3f6c7871c9686ba3670fd36b68b1318449b05cc2268c865b89779126092065a7d69cde793d753ea8d7dcaf268d8e1e9e
7
- data.tar.gz: c7a960b66cd78bb9605cb37408bc6a044167ec912a249b40e46e58dd07e398e5a122737a28246e3eac2945a65156b72e57fb35096069719be3c4faa72b007ef7
6
+ metadata.gz: 8db8f9df3da1f218bd2029ea22414ea53a910de8b1810d71c70a0e9022a1353dd69557c91eb1ffee5355733c0d8d6878aae9379a75ee0eaa76d05c6ee20abb8e
7
+ data.tar.gz: 8027722c6fd1592c86f5fa6150814206a007c12a810985c72231195dcb0089aa34fd91a5addbeb9c14a8137a5a2f3fe984c07f554ee6504a4b4c25d6dd216046
data/Gemfile CHANGED
@@ -10,6 +10,7 @@ gem "sus"
10
10
  gem "syntax_suggest"
11
11
  gem "zeitwerk"
12
12
  gem "benchmark-ips"
13
+ gem "erb"
13
14
 
14
15
  group :test do
15
16
  gem "i18n"
data/lib/phlex/helpers.rb CHANGED
@@ -5,27 +5,38 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
5
5
  end
6
6
 
7
7
  module Phlex::Helpers
8
- private
9
-
10
8
  def tokens(*tokens, **conditional_tokens)
11
9
  conditional_tokens.each do |condition, token|
12
- case condition
13
- when Symbol then next unless send(condition)
14
- when Proc then next unless condition.call
15
- else raise ArgumentError,
16
- "The class condition must be a Symbol or a Proc."
10
+ truthy = case condition
11
+ when Symbol then send(condition)
12
+ when Proc then condition.call
13
+ else raise ArgumentError, "The class condition must be a Symbol or a Proc."
17
14
  end
18
15
 
19
- case token
20
- when Symbol then tokens << token.name
16
+ if truthy
17
+ case token
18
+ when Hash then _append_token(tokens, token[:then])
19
+ else _append_token(tokens, token)
20
+ end
21
+ else
22
+ case token
23
+ when Hash then _append_token(tokens, token[:else])
24
+ end
25
+ end
26
+ end
27
+
28
+ tokens.join(" ")
29
+ end
30
+
31
+ def _append_token(tokens, token)
32
+ case token
33
+ when nil then nil
21
34
  when String then tokens << token
35
+ when Symbol then tokens << token.name
22
36
  when Array then tokens.concat(token)
23
37
  else raise ArgumentError,
24
38
  "Conditional classes must be Symbols, Strings, or Arrays of Symbols or Strings."
25
- end
26
39
  end
27
-
28
- tokens.compact.join(" ")
29
40
  end
30
41
 
31
42
  def classes(*tokens, **conditional_tokens)
data/lib/phlex/html.rb CHANGED
@@ -183,14 +183,13 @@ module Phlex
183
183
  end
184
184
 
185
185
  def text(content)
186
- case content
187
- when String
188
- @_target << CGI.escape_html(content)
189
- when Symbol
190
- @_target << CGI.escape_html(content.name)
191
- when Integer, Float
192
- @_target << CGI.escape_html(content.to_s)
193
- end
186
+ @_target << ERB::Util.html_escape(
187
+ case content
188
+ when String then content
189
+ when Symbol then content.name
190
+ else content.to_s
191
+ end
192
+ )
194
193
 
195
194
  nil
196
195
  end
@@ -264,11 +263,11 @@ module Phlex
264
263
  if unchanged
265
264
  case content
266
265
  when String
267
- @_target << CGI.escape_html(content)
266
+ @_target << ERB::Util.html_escape(content)
268
267
  when Symbol
269
- @_target << CGI.escape_html(content.name)
268
+ @_target << ERB::Util.html_escape(content.name)
270
269
  when Integer, Float
271
- @_target << CGI.escape_html(content.to_s)
270
+ @_target << ERB::Util.html_escape(content.to_s)
272
271
  end
273
272
  end
274
273
 
@@ -309,13 +308,13 @@ module Phlex
309
308
  when true
310
309
  buffer << " " << name
311
310
  when String
312
- buffer << " " << name << '="' << CGI.escape_html(v) << '"'
311
+ buffer << " " << name << '="' << ERB::Util.html_escape(v) << '"'
313
312
  when Symbol
314
- buffer << " " << name << '="' << CGI.escape_html(v.name) << '"'
313
+ buffer << " " << name << '="' << ERB::Util.html_escape(v.name) << '"'
315
314
  when Hash
316
315
  _build_attributes(v.transform_keys { "#{k}-#{_1.name.tr('_', '-')}" }, buffer: buffer)
317
316
  else
318
- buffer << " " << name << '="' << CGI.escape_html(v.to_s) << '"'
317
+ buffer << " " << name << '="' << ERB::Util.html_escape(v.to_s) << '"'
319
318
  end
320
319
  end
321
320
 
data/lib/phlex/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex
4
- VERSION = "1.0.0.rc1"
4
+ VERSION = "1.0.0.rc2"
5
5
  end
data/lib/phlex.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "cgi"
3
+ require "erb"
4
4
  require "zeitwerk"
5
5
 
6
6
  module Phlex
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-25 00:00:00.000000000 Z
11
+ date: 2022-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk