floatable-rails 0.1.1 → 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: ad3e03eaeceb57403d07ba57454e2227c3d0190605eee0a77e46431800e83c44
4
- data.tar.gz: 07a2ea3745784a0a864ce4423d2e74f2fa6707297f81eac782e1b0215144191f
3
+ metadata.gz: 7d7ba3f4dd67001b178b9cc2ce798c344f93f1f6048835797d50ab30e3b8b233
4
+ data.tar.gz: 6ac0062262bb636e6e53db639f9cf5ae4efa3abeace90203c93691ccf205b6cc
5
5
  SHA512:
6
- metadata.gz: 9264dfb773215371f885c0e0e873a9d813316f8087d39fcf4ac4fd7a281196e3fae94471d39bca485518c4f5c07801ee4e757e19a0f05ddb52fb133cc9a03f79
7
- data.tar.gz: e0d206d8866f8d9651476c79c522b39f6e81ab6500d810a947e260b70230e746236b650df8ec7d8227565d51a8c6d81e8aa18146db87279cf2dba13edfe1e252
6
+ metadata.gz: 0f446eb455149fd63b77525932f3d61e978f898c687e373218b538e06f307fce16e289073616c4e41b75de9ba55f60b718a1928506399f1793c77d4df0408c97
7
+ data.tar.gz: 0cfa54163524653e4f0624c17f6677c0ba686e1ef904d168dd7868076ab21a2913d0c3974c9be6801767acaaab2dc83586dfba309128755122b0b1fb071fc298
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.2
4
+
5
+ - Fix Slim instrumentation for doctype/header structure, filters, and control-flow continuations.
6
+
3
7
  ## 0.1.1
4
8
 
5
9
  - Relax Rails dependency to allow earlier versions.
@@ -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
- out << "- @output_buffer.safe_concat('<!-- BEGIN #{view_path} -->') if Thread.current[:floatable_enabled] && defined?(@output_buffer)"
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
- out << "#{indent}- @output_buffer.safe_concat('<!--#{ErbLineInstrumentation::LINE_MARKER_PREFIX}#{idx + 1}-->') if Thread.current[:floatable_enabled] && defined?(@output_buffer)"
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 << "- @output_buffer.safe_concat('<!-- END #{view_path} -->') if Thread.current[:floatable_enabled] && defined?(@output_buffer)"
71
+ out << end_marker
18
72
  out.join("\n")
19
73
  end
20
74
  end
@@ -1,5 +1,5 @@
1
1
  module Floatable
2
2
  module Rails
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Almstrand