floatable-rails 0.1.0 → 0.1.2
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: 7d7ba3f4dd67001b178b9cc2ce798c344f93f1f6048835797d50ab30e3b8b233
|
|
4
|
+
data.tar.gz: 6ac0062262bb636e6e53db639f9cf5ae4efa3abeace90203c93691ccf205b6cc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0f446eb455149fd63b77525932f3d61e978f898c687e373218b538e06f307fce16e289073616c4e41b75de9ba55f60b718a1928506399f1793c77d4df0408c97
|
|
7
|
+
data.tar.gz: 0cfa54163524653e4f0624c17f6677c0ba686e1ef904d168dd7868076ab21a2913d0c3974c9be6801767acaaab2dc83586dfba309128755122b0b1fb071fc298
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
- Fix Slim instrumentation for doctype/header structure, filters, and control-flow continuations.
|
|
6
|
+
|
|
7
|
+
## 0.1.1
|
|
8
|
+
|
|
9
|
+
- Relax Rails dependency to allow earlier versions.
|
|
10
|
+
- Guard against missing ActionView filename annotation setting.
|
|
11
|
+
|
|
3
12
|
## 0.1.0
|
|
4
13
|
|
|
5
14
|
- Initial release.
|
|
@@ -25,7 +25,9 @@ module Floatable
|
|
|
25
25
|
filename: template.identifier
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
if ActionView::Base.annotate_rendered_view_with_filenames &&
|
|
28
|
+
if ActionView::Base.respond_to?(:annotate_rendered_view_with_filenames) &&
|
|
29
|
+
ActionView::Base.annotate_rendered_view_with_filenames &&
|
|
30
|
+
template.format == :html
|
|
29
31
|
options[:preamble] = "@output_buffer.safe_append='<!-- BEGIN #{template.short_identifier}\n-->';"
|
|
30
32
|
options[:postamble] = "@output_buffer.safe_append='<!-- END #{template.short_identifier} -->';@output_buffer"
|
|
31
33
|
end
|
|
@@ -35,6 +35,9 @@ module Floatable
|
|
|
35
35
|
[ status, headers, [ final_html ] ]
|
|
36
36
|
rescue => e
|
|
37
37
|
::Rails.logger.error("[Floatable::Rails::ResponseMiddleware] failed: #{e.class} - #{e.message}")
|
|
38
|
+
status ||= 500
|
|
39
|
+
headers ||= {}
|
|
40
|
+
body ||= []
|
|
38
41
|
[ status, headers, body ]
|
|
39
42
|
end
|
|
40
43
|
|
|
@@ -5,16 +5,70 @@ module Floatable
|
|
|
5
5
|
module SlimLineInstrumenter
|
|
6
6
|
def self.instrument(source, view_path)
|
|
7
7
|
lines = source.to_s.split("\n", -1)
|
|
8
|
+
first_non_empty = lines.index { |line| !line.strip.empty? }
|
|
9
|
+
doctype_index = if first_non_empty && lines[first_non_empty].lstrip.match?(/\A(doctype\b|!!!\b)/)
|
|
10
|
+
first_non_empty
|
|
11
|
+
end
|
|
12
|
+
html_index = nil
|
|
13
|
+
if doctype_index
|
|
14
|
+
html_index = lines[(doctype_index + 1)..].to_a.index { |line| !line.strip.empty? && line.lstrip.match?(/\Ahtml\b/) }
|
|
15
|
+
html_index = html_index ? html_index + doctype_index + 1 : nil
|
|
16
|
+
end
|
|
17
|
+
header_index = html_index || doctype_index
|
|
18
|
+
marker_indent = ""
|
|
19
|
+
if header_index
|
|
20
|
+
next_non_empty = lines[(header_index + 1)..].to_a.find { |line| !line.strip.empty? }
|
|
21
|
+
marker_indent = next_non_empty ? (next_non_empty[/\A[ \t]*/] || "") : ((lines[header_index][/\A[ \t]*/] || "") + " ")
|
|
22
|
+
end
|
|
8
23
|
out = []
|
|
9
|
-
|
|
24
|
+
begin_marker = "#{marker_indent}== (Thread.current[:floatable_enabled] && defined?(@output_buffer)) ? '<!-- BEGIN #{view_path} -->' : ''"
|
|
25
|
+
end_marker = "#{marker_indent}== (Thread.current[:floatable_enabled] && defined?(@output_buffer)) ? '<!-- END #{view_path} -->' : ''"
|
|
26
|
+
out << begin_marker if header_index.nil?
|
|
27
|
+
filter_indent = nil
|
|
10
28
|
|
|
11
29
|
lines.each_with_index do |line, idx|
|
|
30
|
+
if header_index && idx < header_index
|
|
31
|
+
out << line
|
|
32
|
+
next
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
if header_index && idx == header_index
|
|
36
|
+
out << line
|
|
37
|
+
out << begin_marker
|
|
38
|
+
next
|
|
39
|
+
end
|
|
40
|
+
|
|
12
41
|
indent = line[/\A[ \t]*/] || ""
|
|
13
|
-
|
|
42
|
+
indent_level = indent.size
|
|
43
|
+
stripped = line.lstrip
|
|
44
|
+
if stripped.empty?
|
|
45
|
+
out << line
|
|
46
|
+
next
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
if stripped.match?(/\A-\s*(else|elsif|when|rescue|ensure)\b/)
|
|
50
|
+
out << line
|
|
51
|
+
next
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if filter_indent && indent_level > filter_indent
|
|
55
|
+
out << line
|
|
56
|
+
next
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
filter_indent = nil if filter_indent && indent_level <= filter_indent
|
|
60
|
+
|
|
61
|
+
if stripped.match?(/\A[a-zA-Z_][\w-]*:\s*\z/) && !stripped.start_with?("-", "=", "|")
|
|
62
|
+
filter_indent = indent_level
|
|
63
|
+
out << line
|
|
64
|
+
next
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
out << "#{indent}== (Thread.current[:floatable_enabled] && defined?(@output_buffer)) ? '<!--#{ErbLineInstrumentation::LINE_MARKER_PREFIX}#{idx + 1}-->' : ''"
|
|
14
68
|
out << line
|
|
15
69
|
end
|
|
16
70
|
|
|
17
|
-
out <<
|
|
71
|
+
out << end_marker
|
|
18
72
|
out.join("\n")
|
|
19
73
|
end
|
|
20
74
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: floatable-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tobias Almstrand
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version:
|
|
18
|
+
version: '7.0'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version:
|
|
25
|
+
version: '7.0'
|
|
26
26
|
description: Instruments HTML output with metadata and injects the Floatable script
|
|
27
27
|
so your UI can be inspected and annotated in the browser.
|
|
28
28
|
email:
|