phlexing 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -2
- data/README.md +0 -8
- data/lib/phlexing/converter.rb +31 -6
- data/lib/phlexing/helpers.rb +15 -0
- data/lib/phlexing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffc28265f871c2d98adcd231e5c97677d186261c1f7770fa809b26bfc72490de
|
4
|
+
data.tar.gz: 9a1aad812fab3bd2c355a5a768a68feae857b38af09075225ee0be4da5764c35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd78f6266b1fc40d5d61631b261867141b3cdfbc876f20ec0b78605f583e8969aff2d540010842c76e9376531daa6cd51ed7b35990aabd78209001104368cf6b
|
7
|
+
data.tar.gz: f2dbaddeab5395082db642e60e8d95983af5e5a39f0687aeb2d9e1ec07761a7a4a6edac6d86fff18e206f9fe68c5bb6bb999428371b5a7e4a856501640fc6bee
|
data/Gemfile.lock
CHANGED
@@ -45,13 +45,15 @@ GEM
|
|
45
45
|
css_press
|
46
46
|
multi_js (0.1.0)
|
47
47
|
uglifier (~> 2)
|
48
|
-
nokogiri (1.13.
|
48
|
+
nokogiri (1.13.10-x86_64-darwin)
|
49
|
+
racc (~> 1.4)
|
50
|
+
nokogiri (1.13.10-x86_64-linux)
|
49
51
|
racc (~> 1.4)
|
50
52
|
parallel (1.22.1)
|
51
53
|
parser (3.1.2.1)
|
52
54
|
ast (~> 2.4.1)
|
53
55
|
polyglot (0.3.5)
|
54
|
-
racc (1.6.
|
56
|
+
racc (1.6.2)
|
55
57
|
rainbow (3.1.1)
|
56
58
|
rake (13.0.6)
|
57
59
|
regexp_parser (2.6.0)
|
@@ -69,6 +71,7 @@ GEM
|
|
69
71
|
|
70
72
|
PLATFORMS
|
71
73
|
x86_64-darwin-19
|
74
|
+
x86_64-linux
|
72
75
|
|
73
76
|
DEPENDENCIES
|
74
77
|
minitest (~> 5.0)
|
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# Phlexing
|
2
2
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/phlexing`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
3
|
## Installation
|
8
4
|
|
9
5
|
Install the gem and add to the application's Gemfile by executing:
|
@@ -14,10 +10,6 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
14
10
|
|
15
11
|
$ gem install phlexing
|
16
12
|
|
17
|
-
## Usage
|
18
|
-
|
19
|
-
TODO: Write usage instructions here
|
20
|
-
|
21
13
|
## Development
|
22
14
|
|
23
15
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/phlexing/converter.rb
CHANGED
@@ -14,14 +14,15 @@ module Phlexing
|
|
14
14
|
|
15
15
|
attr_accessor :html, :custom_elements
|
16
16
|
|
17
|
-
def self.convert(html)
|
18
|
-
new(html).
|
17
|
+
def self.convert(html, **options)
|
18
|
+
new(html, **options).output
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize(html)
|
21
|
+
def initialize(html, **options)
|
22
22
|
@html = html
|
23
23
|
@buffer = StringIO.new
|
24
24
|
@custom_elements = Set.new
|
25
|
+
@options = options
|
25
26
|
handle_node
|
26
27
|
end
|
27
28
|
|
@@ -30,7 +31,7 @@ module Phlexing
|
|
30
31
|
|
31
32
|
if text.squish.empty? && text.length.positive?
|
32
33
|
@buffer << indent(level)
|
33
|
-
@buffer <<
|
34
|
+
@buffer << whitespace(@options)
|
34
35
|
|
35
36
|
text.strip!
|
36
37
|
end
|
@@ -42,7 +43,7 @@ module Phlexing
|
|
42
43
|
@buffer << "text "
|
43
44
|
end
|
44
45
|
|
45
|
-
@buffer <<
|
46
|
+
@buffer << quote(text)
|
46
47
|
@buffer << "\n" if newline
|
47
48
|
end
|
48
49
|
end
|
@@ -99,7 +100,7 @@ module Phlexing
|
|
99
100
|
def handle_comment_node(node, level)
|
100
101
|
@buffer << indent(level)
|
101
102
|
@buffer << "comment "
|
102
|
-
@buffer <<
|
103
|
+
@buffer << quote(node.text.strip)
|
103
104
|
@buffer << "\n"
|
104
105
|
end
|
105
106
|
|
@@ -161,6 +162,30 @@ module Phlexing
|
|
161
162
|
@buffer.string.strip
|
162
163
|
end
|
163
164
|
|
165
|
+
def output
|
166
|
+
buffer = StringIO.new
|
167
|
+
|
168
|
+
if @options.fetch(:phlex_class, false)
|
169
|
+
buffer << "class #{@options.fetch(:component_name, 'MyComponent')}"
|
170
|
+
buffer << "< #{@options.fetch(:parent_component, 'Phlex::HTML')}\n"
|
171
|
+
|
172
|
+
@custom_elements.each do |element|
|
173
|
+
buffer << (indent(1) + "register_element :#{element}\n")
|
174
|
+
end
|
175
|
+
|
176
|
+
buffer << ("#{indent(1)}def template\n")
|
177
|
+
buffer << (indent(2) + @buffer.string)
|
178
|
+
buffer << ("#{indent(1)}end\n")
|
179
|
+
buffer << "end\n"
|
180
|
+
else
|
181
|
+
buffer << @buffer.string
|
182
|
+
end
|
183
|
+
|
184
|
+
Rufo::Formatter.format(buffer.string.strip)
|
185
|
+
rescue Rufo::SyntaxError
|
186
|
+
buffer.string.strip
|
187
|
+
end
|
188
|
+
|
164
189
|
def converted_erb
|
165
190
|
ErbParser.transform_xml(html).gsub("\n", "").gsub("\r", "")
|
166
191
|
rescue StandardError
|
data/lib/phlexing/helpers.rb
CHANGED
@@ -8,6 +8,10 @@ module Phlexing
|
|
8
8
|
" " * level
|
9
9
|
end
|
10
10
|
|
11
|
+
def whitespace(options)
|
12
|
+
options.fetch(:whitespace, true) ? "whitespace\n" : ""
|
13
|
+
end
|
14
|
+
|
11
15
|
def double_quote(string)
|
12
16
|
"\"#{string}\""
|
13
17
|
end
|
@@ -16,6 +20,17 @@ module Phlexing
|
|
16
20
|
"'#{string}'"
|
17
21
|
end
|
18
22
|
|
23
|
+
def percent_literal_string(string)
|
24
|
+
"%(#{string})"
|
25
|
+
end
|
26
|
+
|
27
|
+
def quote(string)
|
28
|
+
return double_quote(string) unless string.include?('"')
|
29
|
+
return single_quote(string) unless string.include?("'")
|
30
|
+
|
31
|
+
percent_literal_string(string)
|
32
|
+
end
|
33
|
+
|
19
34
|
def node_name(node)
|
20
35
|
return "template_tag" if node.name == "template"
|
21
36
|
return node.name unless node.name.include?("-")
|
data/lib/phlexing/version.rb
CHANGED
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
|
+
version: 0.2.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:
|
11
|
+
date: 2023-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erb_parser
|