phlex 0.2.1 → 0.2.2

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: 2eefd3a74f2982d981f510fbf51664a489edc5ca40bbfddc3be564fd8150646b
4
- data.tar.gz: 8c5c168a439d41ab0c9020a6ebe6b43585cfdda7fc7135782b90df45ee3a5b56
3
+ metadata.gz: 7e96f6deb872d9da9c40cece7e93c195fc5f2f58dc1d61a2277318a290018d64
4
+ data.tar.gz: 759f185fc168d0d98647ad71c589ec8d1425b153382c37a070eb28ca8015c69b
5
5
  SHA512:
6
- metadata.gz: 3cf930ae8e3aa73ddb806de461d0bad1a80a747c38c52c1737631d78a6fe92054f2323d8d9b5f943bf5b028619096232880a3cce6c05ae3abbacfa17f9df31c7
7
- data.tar.gz: 477bfe4a00d3c304671730c2fb1be83804fc7452ce5cfd10f29e1883aa1b2c91e69fe3ca96fa08a9c0c06126292dafa248c1bc655f911ec7c5d8cf17a7395d49
6
+ metadata.gz: 96c765e8a02c0e79cef8d1ed44bac721844e0fd8ae3a7e921176be092775bb66a3cfd6e28a75b697eb8f1debd01c2738e55044fc49a834937c7c79c4220beebb
7
+ data.tar.gz: b5d99002d25e7a426102b6d935fefe0b18145eb780409745a0c63e6523db3668a12ea896e2155e6d8e2b40acb106d4298a8c8d93fa785c3f44472c4667ad67a4
data/README.md CHANGED
@@ -16,9 +16,9 @@ Everyone interacting in Phlex codebases, issue trackers, chat rooms and mailing
16
16
 
17
17
  ### Sponsorship 💖
18
18
 
19
- Maintaining a library like this is a lot of work. Phlex is being actively developed and maintained by **[Joel Drapper](https://github.com/sponsors/joeldrapper)**. If your company benefits from this work or is likely to benefit from it in the future, please consider sponsorship.
19
+ Maintaining a library is a lot of work. If your company benefits from this work or is likely to benefit from it in the future, please consider [sponsorship](https://github.com/sponsors/joeldrapper). Phlex is actively developed and maintained by **[Joel Drapper](https://github.com/sponsors/joeldrapper)**.
20
20
 
21
- ### Security 👮
21
+ ### Security 🚨
22
22
 
23
23
  If you’ve found a potential security issue, please email [joel+security@drapper.me](mailto:joel+security@drapper.me).
24
24
 
data/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ If you found a possible security vulnerability in Phlex, please email joel+security@drapper.me.
@@ -1,4 +1,7 @@
1
1
  <p>Before</p>
2
+
3
+ <%= render(Views::Heading.new) { "Hello World!" } %>
4
+
2
5
  <%= render Views::Card.new do |a| %>
3
6
  <p>Start Card A</p>
4
7
  <%= a.title "Hello from A" %>
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Views
4
+ class Heading < Phlex::Component
5
+ def template(&block)
6
+ h1(&block)
7
+ end
8
+ end
9
+ end
@@ -47,15 +47,20 @@ module Phlex
47
47
  return unless block_given?
48
48
 
49
49
  original_length = @_target.length
50
- output = yield(self) if block_given?
50
+ output = yield(self)
51
51
  unchanged = (original_length == @_target.length)
52
52
 
53
- text(output) if unchanged && output.is_a?(String)
53
+ text(output) if unchanged
54
54
  nil
55
55
  end
56
56
 
57
57
  def text(content)
58
- @_target << CGI.escape_html(content)
58
+ @_target << case content
59
+ when String then CGI.escape_html(content)
60
+ when Symbol then CGI.escape_html(content.name)
61
+ else CGI.escape_html(content.to_s)
62
+ end
63
+
59
64
  nil
60
65
  end
61
66
 
@@ -179,7 +184,7 @@ module Phlex
179
184
  when Symbol
180
185
  buffer << " " << name << '="' << CGI.escape_html(v.name) << '"'
181
186
  when Hash
182
- _build_attributes(v.transform_keys { "#{k}-#{_1}" }, buffer: buffer)
187
+ _build_attributes(v.transform_keys { "#{k}-#{_1.name.tr('_', '-')}" }, buffer: buffer)
183
188
  else
184
189
  buffer << " " << name << '="' << CGI.escape_html(v.to_s) << '"'
185
190
  end
data/lib/phlex/html.rb CHANGED
@@ -10,7 +10,7 @@ module Phlex
10
10
 
11
11
  STANDARD_ELEMENTS = %i[a abbr address article aside b bdi bdo blockquote body button caption cite code colgroup data datalist dd del details dfn dialog div dl dt em fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header html i iframe ins kbd label legend li main map mark menuitem meter nav noscript object ol optgroup option output p path picture pre progress q rp rt ruby s samp script section select slot small span strong style sub summary sup svg table tbody td textarea tfoot th thead time title tr u ul video wbr].freeze
12
12
 
13
- VOID_ELEMENTS = %i[area embed img input link meta param track col].freeze
13
+ VOID_ELEMENTS = %i[area embed img input link meta param source track col].freeze
14
14
 
15
15
  EVENT_ATTRIBUTES = %w[onabort onafterprint onbeforeprint onbeforeunload onblur oncanplay oncanplaythrough onchange onclick oncontextmenu oncopy oncuechange oncut ondblclick ondrag ondragend ondragenter ondragleave ondragover ondragstart ondrop ondurationchange onemptied onended onerror onerror onfocus onhashchange oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata onloadedmetadata onloadstart onmessage onmousedown onmousemove onmouseout onmouseover onmouseup onmousewheel onoffline ononline onpagehide onpageshow onpaste onpause onplay onplaying onpopstate onprogress onratechange onreset onresize onscroll onsearch onseeked onseeking onselect onstalled onstorage onsubmit onsuspend ontimeupdate ontoggle onunload onvolumechange onwaiting onwheel].to_h { [_1, true] }.freeze
16
16
 
@@ -31,7 +31,14 @@ module Phlex
31
31
  end
32
32
  else
33
33
  if content
34
- @_target << "<#{tag}>" << CGI.escape_html(content) << "</#{tag}>"
34
+ case content
35
+ when String
36
+ @_target << "<#{tag}>" << CGI.escape_html(content) << "</#{tag}>"
37
+ when Symbol
38
+ @_target << "<#{tag}>" << CGI.escape_html(content.name) << "</#{tag}>"
39
+ else
40
+ @_target << "<#{tag}>" << CGI.escape_html(content.to_s) << "</#{tag}>"
41
+ end
35
42
  elsif block_given?
36
43
  @_target << "<#{tag}>"
37
44
  content(&block)
@@ -21,7 +21,13 @@ module Phlex
21
21
  def render_in(view_context, &block)
22
22
  if block_given?
23
23
  call(view_context: view_context) do |*args, **kwargs|
24
- view_context.with_output_buffer(self) { yield(*args, **kwargs) }
24
+ view_context.with_output_buffer(self) do
25
+ original_length = @_target.length
26
+ output = yield(*args, **kwargs)
27
+ unchanged = (original_length == @_target.length)
28
+
29
+ text(output) if unchanged && output.is_a?(String)
30
+ end
25
31
  end.html_safe
26
32
  else
27
33
  call(view_context: view_context).html_safe
data/lib/phlex/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
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: 0.2.1
4
+ version: 0.2.2
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-09-16 00:00:00.000000000 Z
11
+ date: 2022-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -39,6 +39,7 @@ files:
39
39
  - LICENSE.txt
40
40
  - README.md
41
41
  - Rakefile
42
+ - SECURITY.md
42
43
  - bench.rb
43
44
  - config.ru
44
45
  - docs/assets/application.css
@@ -65,6 +66,7 @@ files:
65
66
  - fixtures/dummy/app/views/articles/index.html.erb
66
67
  - fixtures/dummy/app/views/articles/new.html.erb
67
68
  - fixtures/dummy/app/views/card.rb
69
+ - fixtures/dummy/app/views/heading.rb
68
70
  - fixtures/dummy/config/database.yml
69
71
  - fixtures/dummy/config/routes.rb
70
72
  - fixtures/dummy/config/storage.yml