phlexing 0.4.0 → 0.6.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: d34ed0b663f26b7d410f46ce70243f2898a3f4264839a295657fe9b8fea0496b
4
+ data.tar.gz: dc48ee5ac2f76c30b36b7c56981b42b7b8118cf031673dafdd5f3779b305504d
5
5
  SHA512:
6
- metadata.gz: b9ad394751b8749495198b624ee0b0df792225d62664ef760b98f29ec18f1bc09aeb02b9cd3727e386bcf75fd11409658679e2a69b12709644cfeefc7aea3b3c
7
- data.tar.gz: '009f8d61b78789d5f78641c85ef37307661bdcdc5bcf3591032766d3de63a9bb8c6fb4b63c74500b94b8084ebccd6e977f1d7abb883a0e5417e2a915edcad9d3'
6
+ metadata.gz: 369ba96c793c148a50cbc94e030d9ae1e25d0666064ca58e6551994972869d7ba308c45a0a18394538f31e3252db1f004805ac5f3129d70e9518a97c72b1b12e
7
+ data.tar.gz: 81d4ea798067dbf461c9742684e5b4a09b7613dcad388f1f55915ff8914a703d7081c935d344a19357d7afac0fc5cc999b064646a9afbe780b22eb9d213c4c33
data/Gemfile.lock CHANGED
@@ -17,211 +17,162 @@ GIT
17
17
  PATH
18
18
  remote: .
19
19
  specs:
20
- phlexing (0.4.0)
20
+ phlexing (0.6.0)
21
21
  deface (~> 1.9)
22
22
  html_press (~> 0.8.2)
23
23
  nokogiri (~> 1.0)
24
24
  phlex (~> 1.6)
25
- phlex-rails (~> 0.9)
25
+ phlex-rails (>= 0.9, < 2.0)
26
26
  syntax_tree (~> 6.0)
27
27
 
28
28
  GEM
29
29
  remote: https://rubygems.org/
30
30
  specs:
31
- actioncable (7.0.4.3)
32
- actionpack (= 7.0.4.3)
33
- activesupport (= 7.0.4.3)
34
- nio4r (~> 2.0)
35
- websocket-driver (>= 0.6.1)
36
- actionmailbox (7.0.4.3)
37
- actionpack (= 7.0.4.3)
38
- activejob (= 7.0.4.3)
39
- activerecord (= 7.0.4.3)
40
- activestorage (= 7.0.4.3)
41
- activesupport (= 7.0.4.3)
42
- mail (>= 2.7.1)
43
- net-imap
44
- net-pop
45
- net-smtp
46
- actionmailer (7.0.4.3)
47
- actionpack (= 7.0.4.3)
48
- actionview (= 7.0.4.3)
49
- activejob (= 7.0.4.3)
50
- activesupport (= 7.0.4.3)
51
- mail (~> 2.5, >= 2.5.4)
52
- net-imap
53
- net-pop
54
- net-smtp
55
- rails-dom-testing (~> 2.0)
56
- actionpack (7.0.4.3)
57
- actionview (= 7.0.4.3)
58
- activesupport (= 7.0.4.3)
59
- rack (~> 2.0, >= 2.2.0)
60
- rack-test (>= 0.6.3)
61
- rails-dom-testing (~> 2.0)
62
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
63
- actiontext (7.0.4.3)
64
- actionpack (= 7.0.4.3)
65
- activerecord (= 7.0.4.3)
66
- activestorage (= 7.0.4.3)
67
- activesupport (= 7.0.4.3)
68
- globalid (>= 0.6.0)
31
+ actionpack (7.1.3.2)
32
+ actionview (= 7.1.3.2)
33
+ activesupport (= 7.1.3.2)
69
34
  nokogiri (>= 1.8.5)
70
- actionview (7.0.4.3)
71
- activesupport (= 7.0.4.3)
35
+ racc
36
+ rack (>= 2.2.4)
37
+ rack-session (>= 1.0.1)
38
+ rack-test (>= 0.6.3)
39
+ rails-dom-testing (~> 2.2)
40
+ rails-html-sanitizer (~> 1.6)
41
+ actionview (7.1.3.2)
42
+ activesupport (= 7.1.3.2)
72
43
  builder (~> 3.1)
73
- erubi (~> 1.4)
74
- rails-dom-testing (~> 2.0)
75
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
76
- activejob (7.0.4.3)
77
- activesupport (= 7.0.4.3)
78
- globalid (>= 0.3.6)
79
- activemodel (7.0.4.3)
80
- activesupport (= 7.0.4.3)
81
- activerecord (7.0.4.3)
82
- activemodel (= 7.0.4.3)
83
- activesupport (= 7.0.4.3)
84
- activestorage (7.0.4.3)
85
- actionpack (= 7.0.4.3)
86
- activejob (= 7.0.4.3)
87
- activerecord (= 7.0.4.3)
88
- activesupport (= 7.0.4.3)
89
- marcel (~> 1.0)
90
- mini_mime (>= 1.1.0)
91
- activesupport (7.0.4.3)
44
+ erubi (~> 1.11)
45
+ rails-dom-testing (~> 2.2)
46
+ rails-html-sanitizer (~> 1.6)
47
+ activesupport (7.1.3.2)
48
+ base64
49
+ bigdecimal
92
50
  concurrent-ruby (~> 1.0, >= 1.0.2)
51
+ connection_pool (>= 2.2.5)
52
+ drb
93
53
  i18n (>= 1.6, < 2)
94
54
  minitest (>= 5.1)
55
+ mutex_m
95
56
  tzinfo (~> 2.0)
96
57
  ast (2.4.2)
58
+ base64 (0.2.0)
59
+ bigdecimal (3.1.6)
97
60
  builder (3.2.4)
98
- cgi (0.3.6)
99
- concurrent-ruby (1.2.2)
61
+ cgi (0.4.1)
62
+ concurrent-ruby (1.2.3)
63
+ connection_pool (2.4.1)
100
64
  crass (1.0.6)
101
65
  css_press (0.3.2)
102
66
  csspool-st (= 3.1.2)
103
67
  json
104
68
  csspool-st (3.1.2)
105
- date (3.3.3)
106
69
  deface (1.9.0)
107
70
  actionview (>= 5.2)
108
71
  nokogiri (>= 1.6)
109
72
  polyglot
110
73
  railties (>= 5.2)
111
74
  rainbow (>= 2.1.0)
112
- erb (4.0.2)
75
+ drb (2.2.0)
76
+ ruby2_keywords
77
+ erb (4.0.4)
113
78
  cgi (>= 0.3.3)
114
79
  erubi (1.12.0)
115
80
  execjs (2.8.1)
116
- globalid (1.1.0)
117
- activesupport (>= 5.0)
118
81
  html_press (0.8.2)
119
82
  htmlentities
120
83
  multi_css (>= 0.1.0)
121
84
  multi_js (>= 0.1.0)
122
85
  htmlentities (4.3.4)
123
- i18n (1.12.0)
86
+ i18n (1.14.1)
124
87
  concurrent-ruby (~> 1.0)
88
+ io-console (0.7.2)
89
+ irb (1.11.2)
90
+ rdoc
91
+ reline (>= 0.4.2)
125
92
  json (2.6.2)
126
- loofah (2.19.1)
93
+ loofah (2.22.0)
127
94
  crass (~> 1.0.2)
128
- nokogiri (>= 1.5.9)
129
- mail (2.8.1)
130
- mini_mime (>= 0.1.1)
131
- net-imap
132
- net-pop
133
- net-smtp
134
- marcel (1.0.2)
95
+ nokogiri (>= 1.12.0)
135
96
  maxitest (4.4.0)
136
97
  minitest (>= 5.0.0, < 5.18.0)
137
- method_source (1.0.0)
138
- mini_mime (1.1.2)
139
98
  minitest (5.17.0)
140
99
  multi_css (0.1.0)
141
100
  css_press
142
101
  multi_js (0.1.0)
143
102
  uglifier (~> 2)
144
- net-imap (0.3.4)
145
- date
146
- net-protocol
147
- net-pop (0.1.2)
148
- net-protocol
149
- net-protocol (0.2.1)
150
- timeout
151
- net-smtp (0.3.3)
152
- net-protocol
153
- nio4r (2.5.8)
154
- nokogiri (1.14.2-x86_64-darwin)
103
+ mutex_m (0.2.0)
104
+ nokogiri (1.16.2-x86_64-darwin)
155
105
  racc (~> 1.4)
156
- nokogiri (1.14.2-x86_64-linux)
106
+ nokogiri (1.16.2-x86_64-linux)
157
107
  racc (~> 1.4)
158
108
  parallel (1.22.1)
159
109
  parser (3.2.0.0)
160
110
  ast (~> 2.4.1)
161
- phlex (1.6.1)
111
+ phlex (1.9.1)
162
112
  concurrent-ruby (~> 1.2)
163
113
  erb (>= 4)
164
114
  zeitwerk (~> 2.6)
165
- phlex-rails (0.9.0)
166
- phlex (~> 1.6)
167
- rails (>= 6.1, < 8)
115
+ phlex-rails (1.1.1)
116
+ phlex (~> 1.9)
117
+ railties (>= 6.1, < 8)
168
118
  zeitwerk (~> 2.6)
169
119
  polyglot (0.3.5)
170
120
  prettier_print (1.2.1)
171
- racc (1.6.2)
172
- rack (2.2.6.4)
121
+ psych (5.1.2)
122
+ stringio
123
+ racc (1.7.3)
124
+ rack (3.0.9.1)
125
+ rack-session (2.0.0)
126
+ rack (>= 3.0.0)
173
127
  rack-test (2.1.0)
174
128
  rack (>= 1.3)
175
- rails (7.0.4.3)
176
- actioncable (= 7.0.4.3)
177
- actionmailbox (= 7.0.4.3)
178
- actionmailer (= 7.0.4.3)
179
- actionpack (= 7.0.4.3)
180
- actiontext (= 7.0.4.3)
181
- actionview (= 7.0.4.3)
182
- activejob (= 7.0.4.3)
183
- activemodel (= 7.0.4.3)
184
- activerecord (= 7.0.4.3)
185
- activestorage (= 7.0.4.3)
186
- activesupport (= 7.0.4.3)
187
- bundler (>= 1.15.0)
188
- railties (= 7.0.4.3)
189
- rails-dom-testing (2.0.3)
190
- activesupport (>= 4.2.0)
129
+ rackup (2.1.0)
130
+ rack (>= 3)
131
+ webrick (~> 1.8)
132
+ rails-dom-testing (2.2.0)
133
+ activesupport (>= 5.0.0)
134
+ minitest
191
135
  nokogiri (>= 1.6)
192
- rails-html-sanitizer (1.5.0)
193
- loofah (~> 2.19, >= 2.19.1)
194
- railties (7.0.4.3)
195
- actionpack (= 7.0.4.3)
196
- activesupport (= 7.0.4.3)
197
- method_source
136
+ rails-html-sanitizer (1.6.0)
137
+ loofah (~> 2.21)
138
+ nokogiri (~> 1.14)
139
+ railties (7.1.3.2)
140
+ actionpack (= 7.1.3.2)
141
+ activesupport (= 7.1.3.2)
142
+ irb
143
+ rackup (>= 1.0.0)
198
144
  rake (>= 12.2)
199
- thor (~> 1.0)
200
- zeitwerk (~> 2.5)
145
+ thor (~> 1.0, >= 1.2.2)
146
+ zeitwerk (~> 2.6)
201
147
  rainbow (3.1.1)
202
148
  rake (13.0.6)
149
+ rdoc (6.6.3.1)
150
+ psych (>= 4.0.0)
203
151
  regexp_parser (2.6.2)
152
+ reline (0.4.3)
153
+ io-console (~> 0.5)
204
154
  rexml (3.2.5)
205
155
  rubocop-ast (1.24.1)
206
156
  parser (>= 3.1.1.0)
207
157
  ruby-progressbar (1.11.0)
158
+ ruby2_keywords (0.0.5)
159
+ stringio (3.1.0)
208
160
  syntax_tree (6.1.1)
209
161
  prettier_print (>= 1.2.0)
210
- thor (1.2.1)
211
- timeout (0.3.2)
162
+ thor (1.3.1)
212
163
  tzinfo (2.0.6)
213
164
  concurrent-ruby (~> 1.0)
214
165
  uglifier (2.7.2)
215
166
  execjs (>= 0.3.0)
216
167
  json (>= 1.8.0)
217
168
  unicode-display_width (2.4.2)
218
- websocket-driver (0.7.5)
219
- websocket-extensions (>= 0.1.0)
220
- websocket-extensions (0.1.5)
221
- zeitwerk (2.6.7)
169
+ webrick (1.8.1)
170
+ zeitwerk (2.6.13)
222
171
 
223
172
  PLATFORMS
224
173
  x86_64-darwin-19
174
+ x86_64-darwin-22
175
+ x86_64-darwin-23
225
176
  x86_64-linux
226
177
 
227
178
  DEPENDENCIES
@@ -232,4 +183,4 @@ DEPENDENCIES
232
183
  rubocop!
233
184
 
234
185
  BUNDLED WITH
235
- 2.3.22
186
+ 2.5.5
@@ -63,7 +63,7 @@ module Phlexing
63
63
  out << newline
64
64
  end
65
65
 
66
- out << "def template"
66
+ out << "def #{options.template_name}"
67
67
  out << newline
68
68
  out << converter.template_code
69
69
  out << newline
@@ -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,18 @@
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, :template_name
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", template_name: "view_template")
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
16
+ @template_name = template_name
15
17
  end
16
18
 
17
19
  def safe_constant_name(name)
@@ -30,7 +30,7 @@ module Phlexing
30
30
  end
31
31
 
32
32
  def handle_text_output(text)
33
- output("text", text)
33
+ output("plain", text)
34
34
  end
35
35
 
36
36
  def handle_html_comment_output(text)
@@ -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.6.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.6.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: 2024-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -70,16 +70,22 @@ dependencies:
70
70
  name: phlex-rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.9'
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '2.0'
76
79
  type: :runtime
77
80
  prerelease: false
78
81
  version_requirements: !ruby/object:Gem::Requirement
79
82
  requirements:
80
- - - "~>"
83
+ - - ">="
81
84
  - !ruby/object:Gem::Version
82
85
  version: '0.9'
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.0'
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: syntax_tree
85
91
  requirement: !ruby/object:Gem::Requirement
@@ -141,14 +147,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
147
  requirements:
142
148
  - - ">="
143
149
  - !ruby/object:Gem::Version
144
- version: 2.7.0
150
+ version: 3.0.0
145
151
  required_rubygems_version: !ruby/object:Gem::Requirement
146
152
  requirements:
147
153
  - - ">="
148
154
  - !ruby/object:Gem::Version
149
155
  version: '0'
150
156
  requirements: []
151
- rubygems_version: 3.3.7
157
+ rubygems_version: 3.5.5
152
158
  signing_key:
153
159
  specification_version: 4
154
160
  summary: Simple ERB to Phlex converter