floatable-rails 0.1.3 → 0.1.5
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4c125142ad80b216bb4877b12f84b9cbed92d61225c13486ea3468aca4247f72
|
|
4
|
+
data.tar.gz: 8693d60951dc3bb1631a1399f3bab47d9a2758d989cdf950542f738a9fe46053
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4a76a6b78be41abf4f1ac7cf5d889aea041486560bfe0ae394197c2c3761b439239c01ddf4a3350a8952586d41fcde1739c23dd5732a22b4a4e789cc6502c56
|
|
7
|
+
data.tar.gz: 7058a3f4efa223046b51057393ae68c5ed0f69fed2070fff360b7ed266cfd74fd4ebf57a1df2df3322bb9b7cb517f343209ebfdf1aa35f95c1565fa3571aaf60
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.5
|
|
4
|
+
|
|
5
|
+
- Preserve Vue-style directive/event attributes by using the HTML5 parser when available.
|
|
6
|
+
|
|
7
|
+
## 0.1.4
|
|
8
|
+
|
|
9
|
+
- Fix Slim marker insertion to avoid interfering with block rendering.
|
|
10
|
+
|
|
3
11
|
## 0.1.3
|
|
4
12
|
|
|
5
13
|
- Add `instrumentation_enabled` config to toggle HTML instrumentation separately from script injection.
|
|
@@ -69,7 +69,7 @@ module Floatable
|
|
|
69
69
|
return html if html.strip.empty?
|
|
70
70
|
|
|
71
71
|
doctype = html[/\A\s*<!DOCTYPE[^>]*>/i]
|
|
72
|
-
doc =
|
|
72
|
+
doc = parse_html(html)
|
|
73
73
|
|
|
74
74
|
doc.css("*").each do |node|
|
|
75
75
|
name = node.name.to_s.downcase
|
|
@@ -132,6 +132,14 @@ module Floatable
|
|
|
132
132
|
::Rails.logger.debug("[Floatable::Rails] apply_view_markers_and_assign_ids failed: #{e.class} - #{e.message}")
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
+
def parse_html(html)
|
|
136
|
+
if defined?(Nokogiri::HTML5)
|
|
137
|
+
Nokogiri::HTML5.parse(html)
|
|
138
|
+
else
|
|
139
|
+
Nokogiri::HTML.parse(html)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
135
143
|
def app_views_path?(path)
|
|
136
144
|
str = path.to_s
|
|
137
145
|
str.include?("/app/views/") || str.start_with?("app/views/")
|
|
@@ -10,42 +10,39 @@ module Floatable
|
|
|
10
10
|
|
|
11
11
|
first_non_empty = lines.index { |l| !l.strip.empty? } || 0
|
|
12
12
|
|
|
13
|
-
# Keep optional Slim headers (doctype
|
|
14
|
-
doctype_idx =
|
|
15
|
-
first_non_empty
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
html_idx = nil
|
|
19
|
-
if doctype_idx
|
|
20
|
-
rel = lines[(doctype_idx + 1)..].to_a.index { |l| !l.strip.empty? && l.lstrip.match?(/\Ahtml\b/) }
|
|
21
|
-
html_idx = rel ? (doctype_idx + 1 + rel) : nil
|
|
22
|
-
end
|
|
13
|
+
# Keep optional Slim headers (doctype) at the very top if present.
|
|
14
|
+
doctype_idx =
|
|
15
|
+
if lines[first_non_empty]&.lstrip&.match?(/\A(doctype\b|!!!\b)/)
|
|
16
|
+
first_non_empty
|
|
17
|
+
end
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
# Insert before the first real line to avoid nesting inside blocks.
|
|
20
|
+
insert_at = doctype_idx ? (doctype_idx + 1) : first_non_empty
|
|
21
|
+
insert_at = [ insert_at, lines.length ].min
|
|
26
22
|
|
|
27
|
-
# Choose indentation that won't break Slim parsing.
|
|
28
23
|
marker_indent =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
else
|
|
34
|
-
base_line = lines[insert_after] || ""
|
|
35
|
-
(base_line[/\A[ \t]*/] || "") + " "
|
|
36
|
-
end
|
|
24
|
+
if insert_at < lines.length
|
|
25
|
+
lines[insert_at].to_s[/\A[ \t]*/] || ""
|
|
26
|
+
else
|
|
27
|
+
lines[first_non_empty].to_s[/\A[ \t]*/] || ""
|
|
37
28
|
end
|
|
38
29
|
|
|
39
|
-
begin_marker =
|
|
40
|
-
|
|
30
|
+
begin_marker = [
|
|
31
|
+
"#{marker_indent}- (@output_buffer.safe_concat('<!-- #{::Floatable::Rails::VIEW_COMMENT_BEGIN} #{view_path} -->') if Thread.current[:floatable_enabled] && defined?(@output_buffer)); nil"
|
|
32
|
+
]
|
|
33
|
+
end_marker = [
|
|
34
|
+
"#{marker_indent}- (@output_buffer.safe_concat('<!-- #{::Floatable::Rails::VIEW_COMMENT_END} #{view_path} -->') if Thread.current[:floatable_enabled] && defined?(@output_buffer)); nil"
|
|
35
|
+
]
|
|
41
36
|
|
|
42
37
|
out = []
|
|
43
38
|
lines.each_with_index do |line, idx|
|
|
39
|
+
out.concat(begin_marker) if idx == insert_at
|
|
44
40
|
out << line
|
|
45
|
-
out << begin_marker if idx == insert_after
|
|
46
41
|
end
|
|
47
42
|
|
|
48
|
-
out
|
|
43
|
+
out.concat(begin_marker) if insert_at == lines.length
|
|
44
|
+
|
|
45
|
+
out.concat(end_marker)
|
|
49
46
|
out.join("\n")
|
|
50
47
|
end
|
|
51
48
|
end
|