phlexing 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a1f00bbf43b734cd75f369ace78ec7a8e782192fc65b9729c345b16dfb25dd6
4
- data.tar.gz: 10985bfa447d6e052b2bfe932ff796bc2465458ca5a7b8f0e77bb089f0372371
3
+ metadata.gz: 32473f2d62d2af3b3a05ae264b34ed586914fad139c2fa75e92d09560f1d7a12
4
+ data.tar.gz: 7175a9dc57029272641b7b025304ff87510e459623a77881703d4f55ea981e40
5
5
  SHA512:
6
- metadata.gz: b9ad394751b8749495198b624ee0b0df792225d62664ef760b98f29ec18f1bc09aeb02b9cd3727e386bcf75fd11409658679e2a69b12709644cfeefc7aea3b3c
7
- data.tar.gz: '009f8d61b78789d5f78641c85ef37307661bdcdc5bcf3591032766d3de63a9bb8c6fb4b63c74500b94b8084ebccd6e977f1d7abb883a0e5417e2a915edcad9d3'
6
+ metadata.gz: ec5c1a3b6cc6d5061b555e328b8bcf4a2e0ea179e2ace84e6fb63ccb97a3a78ba58c2f822646cd94d884eb2b87c90762e05a7afff79cf3086c4b75c3bb052b11
7
+ data.tar.gz: ce270b4f89019cc589b0823cc3500b36eb25040fe3f19a737dc8676852019598dcd32489437cb1cd19bbf3d02053ef3cacf9156c260563a82e5e06d138769255
data/Gemfile.lock CHANGED
@@ -17,7 +17,7 @@ GIT
17
17
  PATH
18
18
  remote: .
19
19
  specs:
20
- phlexing (0.4.0)
20
+ phlexing (0.5.0)
21
21
  deface (~> 1.9)
22
22
  html_press (~> 0.8.2)
23
23
  nokogiri (~> 1.0)
@@ -123,7 +123,7 @@ GEM
123
123
  i18n (1.12.0)
124
124
  concurrent-ruby (~> 1.0)
125
125
  json (2.6.2)
126
- loofah (2.19.1)
126
+ loofah (2.20.0)
127
127
  crass (~> 1.0.2)
128
128
  nokogiri (>= 1.5.9)
129
129
  mail (2.8.1)
@@ -150,15 +150,15 @@ GEM
150
150
  timeout
151
151
  net-smtp (0.3.3)
152
152
  net-protocol
153
- nio4r (2.5.8)
154
- nokogiri (1.14.2-x86_64-darwin)
153
+ nio4r (2.5.9)
154
+ nokogiri (1.14.3-x86_64-darwin)
155
155
  racc (~> 1.4)
156
- nokogiri (1.14.2-x86_64-linux)
156
+ nokogiri (1.14.3-x86_64-linux)
157
157
  racc (~> 1.4)
158
158
  parallel (1.22.1)
159
159
  parser (3.2.0.0)
160
160
  ast (~> 2.4.1)
161
- phlex (1.6.1)
161
+ phlex (1.8.1)
162
162
  concurrent-ruby (~> 1.2)
163
163
  erb (>= 4)
164
164
  zeitwerk (~> 2.6)
@@ -9,6 +9,8 @@ module Phlexing
9
9
  Phlex::HTML::VoidElements.registered_elements.values +
10
10
  Phlex::HTML::StandardElements.registered_elements.values
11
11
 
12
+ SVG_ELEMENTS = Phlex::SVG::StandardElements.registered_elements.values.to_h { |element| [element.downcase, element] }
13
+
12
14
  def whitespace
13
15
  options.whitespace? ? "whitespace\n" : ""
14
16
  end
@@ -59,17 +61,27 @@ module Phlexing
59
61
  end
60
62
 
61
63
  def tag_name(node)
62
- return "template_tag" if node.name == "template-tag"
63
-
64
64
  name = node.name.tr("-", "_")
65
65
 
66
- @converter.custom_elements << name unless KNOWN_ELEMENTS.include?(name)
66
+ return name if name == "template_tag"
67
+ return name if name.start_with?("s.")
68
+ return name if KNOWN_ELEMENTS.include?(name)
69
+
70
+ @converter.custom_elements << name
67
71
 
68
72
  name
69
73
  end
70
74
 
71
- def block
75
+ def block(params = nil)
72
76
  out << " {"
77
+
78
+ if params
79
+ out << " "
80
+ out << "|"
81
+ out << params
82
+ out << "|"
83
+ end
84
+
73
85
  yield
74
86
  out << " }"
75
87
  end
@@ -2,16 +2,17 @@
2
2
 
3
3
  module Phlexing
4
4
  class Options
5
- attr_accessor :component, :component_name, :parent_component, :whitespace
5
+ attr_accessor :component, :component_name, :parent_component, :whitespace, :svg_param
6
6
 
7
7
  alias_method :whitespace?, :whitespace
8
8
  alias_method :component?, :component
9
9
 
10
- def initialize(component: false, component_name: "Component", parent_component: "Phlex::HTML", whitespace: true)
10
+ def initialize(component: false, component_name: "Component", parent_component: "Phlex::HTML", whitespace: true, svg_param: "s")
11
11
  @component = component
12
12
  @component_name = safe_constant_name(component_name)
13
13
  @parent_component = safe_constant_name(parent_component)
14
14
  @whitespace = whitespace
15
+ @svg_param = svg_param
15
16
  end
16
17
 
17
18
  def safe_constant_name(name)
@@ -54,7 +54,7 @@ module Phlexing
54
54
 
55
55
  attributes = []
56
56
 
57
- node.attributes.each_value do |attribute|
57
+ node.attribute_nodes.each do |attribute|
58
58
  attributes << handle_attribute(attribute)
59
59
  end
60
60
 
@@ -74,7 +74,13 @@ module Phlexing
74
74
  def handle_html_attribute_output(attribute)
75
75
  String.new.tap { |s|
76
76
  s << arg(attribute.name.underscore)
77
- s << quote(attribute.value)
77
+ if attribute.value.blank? && !attribute.to_html.include?("=")
78
+ # handling boolean attributes
79
+ # eg. <input required> => input(required: true)
80
+ s << "true"
81
+ else
82
+ s << quote(attribute.value)
83
+ end
78
84
  }
79
85
  end
80
86
 
@@ -141,8 +147,10 @@ module Phlexing
141
147
  out << tag_name(node)
142
148
  out << handle_attributes(node)
143
149
 
150
+ params = node.name == "svg" ? options.svg_param : nil
151
+
144
152
  if node.children.any?
145
- block { handle_children(node, level) }
153
+ block(params) { handle_children(node, level) }
146
154
  end
147
155
 
148
156
  out << newline
@@ -183,6 +191,22 @@ module Phlexing
183
191
  out << newline if level == 1
184
192
  end
185
193
 
194
+ def handle_svg_node(node, level)
195
+ node.children.each do |child|
196
+ child.traverse do |subchild|
197
+ subchild.name = SVG_ELEMENTS[subchild.name] if SVG_ELEMENTS.key?(subchild.name)
198
+ subchild.name = subchild.name.prepend("#{options.svg_param}.") # rubocop:disable Style/RedundantSelfAssignment
199
+ end
200
+ end
201
+
202
+ whitespace_before = options.whitespace
203
+ options.whitespace = false
204
+
205
+ handle_element_node(node, level)
206
+
207
+ options.whitespace = whitespace_before
208
+ end
209
+
186
210
  def handle_document_node(node, level)
187
211
  handle_children(node, level)
188
212
  end
@@ -198,7 +222,11 @@ module Phlexing
198
222
  in Nokogiri::XML::Text
199
223
  handle_text_node(node)
200
224
  in Nokogiri::XML::Element
201
- handle_element_node(node, level)
225
+ if node.name == "svg"
226
+ handle_svg_node(node, level)
227
+ else
228
+ handle_element_node(node, level)
229
+ end
202
230
  in Nokogiri::HTML4::Document | Nokogiri::HTML4::DocumentFragment | Nokogiri::XML::DTD
203
231
  handle_document_node(node, level)
204
232
  in Nokogiri::XML::Comment
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlexing
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlexing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-28 00:00:00.000000000 Z
11
+ date: 2023-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface