web_components_rails 2.1.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/web_components_rails/html_import_processor.rb +72 -18
- data/lib/web_components_rails/version.rb +1 -1
- data/lib/web_components_rails.rb +1 -1
- metadata +18 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 29026bd8a5c3ae2ade72b7978e60ea6a1905dd8ff66ab438b89faacd85f4a2a8
|
4
|
+
data.tar.gz: b05ab464110938ec3b1a70fe2bbca66b1d8f6e9c753800980e36fb4629e4e223
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb1d5a6107ebef9a5e74ca444bb50f652d1538f3b949a71c11463e6c5bae903a8baf135ea61cee43b548befdc59b07c41e67606385823057b051ec837b3825f1
|
7
|
+
data.tar.gz: f16c3b8a29a34774b232144bde31a5bae0665c658723475f8e606cb9d25e89485078cbb8354098fd912588b873322904eb38f0426c19472ab58f84578fceaccd
|
@@ -6,7 +6,56 @@ require 'securerandom'
|
|
6
6
|
# https://github.com/rails/sprockets/blob/3.x/lib/sprockets/directive_processor.rb
|
7
7
|
class WebComponentsRails::HTMLImportProcessor
|
8
8
|
|
9
|
-
VERSION = '
|
9
|
+
VERSION = '10'
|
10
|
+
XML_SAVE_OPTIONS = {
|
11
|
+
save_with: ::Nokogiri::XML::Node::SaveOptions::DEFAULT_XML | ::Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS
|
12
|
+
}
|
13
|
+
|
14
|
+
# URI attributes are determined by using the attributes list at https://html.spec.whatwg.org/#attributes-3
|
15
|
+
# and looking for attributes that specify "Valid URL" as their values
|
16
|
+
URI_ATTRIBUTES = %w(
|
17
|
+
action
|
18
|
+
cite
|
19
|
+
data
|
20
|
+
formaction
|
21
|
+
href
|
22
|
+
itemid
|
23
|
+
manifest
|
24
|
+
ping
|
25
|
+
poster
|
26
|
+
src
|
27
|
+
).freeze
|
28
|
+
|
29
|
+
# URI attributes are determined by using the attributes list at https://html.spec.whatwg.org/#attributes-3
|
30
|
+
# and looking for attributes that specify "Boolean attribute" as their values
|
31
|
+
BOOLEAN_ATTRIBUTES = %w(
|
32
|
+
allowfullscreen
|
33
|
+
allowpaymentrequest
|
34
|
+
allowusermedia
|
35
|
+
async
|
36
|
+
autofocus
|
37
|
+
autoplay
|
38
|
+
checked
|
39
|
+
controls
|
40
|
+
default
|
41
|
+
defer
|
42
|
+
disabled
|
43
|
+
formnovalidate
|
44
|
+
hidden
|
45
|
+
ismap
|
46
|
+
itemscope
|
47
|
+
loop
|
48
|
+
multiple
|
49
|
+
muted
|
50
|
+
nomodule
|
51
|
+
novalidate
|
52
|
+
open
|
53
|
+
playsinline
|
54
|
+
readonly
|
55
|
+
required
|
56
|
+
reversed
|
57
|
+
selected
|
58
|
+
).freeze
|
10
59
|
|
11
60
|
def self.instance
|
12
61
|
@instance ||= new
|
@@ -21,25 +70,30 @@ class WebComponentsRails::HTMLImportProcessor
|
|
21
70
|
end
|
22
71
|
|
23
72
|
def self.doc_to_html(doc)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
%
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
73
|
+
doc_html = doc.to_html(encoding: 'UTF-8')
|
74
|
+
|
75
|
+
uri_regex = Regexp.union(URI_ATTRIBUTES)
|
76
|
+
square_brackets_regex = Regexp.new("(#{uri_regex})=\"%5B%5B(.+?)%5D%5D\"", 'i')
|
77
|
+
curly_braces_regex = Regexp.new("(#{uri_regex})=\"%7B%7B(.+?)%7D%7D\"", 'i')
|
78
|
+
|
79
|
+
selectors = (URI_ATTRIBUTES + BOOLEAN_ATTRIBUTES).map { |attribute| "*[#{attribute}]"}
|
80
|
+
doc.css(selectors.join(',')).each do |node|
|
81
|
+
# Nokogiri only writes out valid HTML so this outputs some nodes that would not be valid HTML
|
82
|
+
# (e.g. nodes with boolean attributes that have values, or nodes that have unescaped URI attributes)
|
83
|
+
# as both HTML and XML, and uses swap out the HTML for XML in the complete document HTML.
|
84
|
+
pattern = node.to_html
|
85
|
+
replacement = node.to_xml(XML_SAVE_OPTIONS)
|
86
|
+
|
87
|
+
# Nokogiri/Nokogumbo are hard-coded to URI-escape certain attributes (src, href, action, and a[name]),
|
88
|
+
# so we have to put in placeholders, and fix the values in the HTML string output afterwards
|
89
|
+
# This doesn't work so well with framework-specific syntax (eg. <foo src="{{bar}}">)
|
90
|
+
replacement.gsub!(square_brackets_regex, '\1="[[\2]]"')
|
91
|
+
replacement.gsub!(curly_braces_regex, '\1="{{\2}}"')
|
92
|
+
|
93
|
+
doc_html.gsub!(pattern, replacement)
|
40
94
|
end
|
41
95
|
|
42
|
-
|
96
|
+
doc_html
|
43
97
|
end
|
44
98
|
|
45
99
|
|
data/lib/web_components_rails.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_components_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Botelho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: '1.12'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
29
|
+
version: '1.12'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rails
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
39
|
+
version: '6.0'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: '6.0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: sprockets-rails
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2
|
53
|
+
version: '3.2'
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2
|
60
|
+
version: '3.2'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: uglifier
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - ">="
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2
|
67
|
+
version: '3.2'
|
62
68
|
type: :runtime
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - ">="
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2
|
74
|
+
version: '3.2'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: rspec
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,8 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
124
|
- !ruby/object:Gem::Version
|
119
125
|
version: '0'
|
120
126
|
requirements: []
|
121
|
-
|
122
|
-
rubygems_version: 2.4.8
|
127
|
+
rubygems_version: 3.1.6
|
123
128
|
signing_key:
|
124
129
|
specification_version: 4
|
125
130
|
summary: Web components utils for rails
|