actionview-path_hints 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/actionview/path_hints.rb +18 -8
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d1f31d757c6efc69cdd8e52875a6ff67a0ca069
4
- data.tar.gz: 32328caa2fc14b94104778190cf83bfd4d2fa712
3
+ metadata.gz: 71cbaa87fd02fe93b6afcd42261e66ba081ec3f1
4
+ data.tar.gz: 26ea3aa4d48503fd899647d5b0302499598508b9
5
5
  SHA512:
6
- metadata.gz: edd1d4bbe5083e6d2458d4672bf22ade17ea7dc8a90c6e8f1c8c59ea71d1a9ab8b4a5d93cea9ddda8c40021ecee5eec9cbbdc735d7d0c282e856e7db5ebef302
7
- data.tar.gz: d2e47c458a4e696f3bc6392ea25902f2c981ae03a1cb7ff5a44da958b9df82d1d7c2e3d79e43f18678ad10421b824ba76221edf9a14c4b75d1f4d7449c06420f
6
+ metadata.gz: 0ccbd76eddbd8866be9bd81756746f3ff4e6cb1cb616bf008036eac8a11cd2c82ff68f1e144d5934f86ebca02c592bd2ab2e3a509c365a507311ad0b1d297f76
7
+ data.tar.gz: 529a582bd9a1503dd940b8e352da337cfc2ae023d24064b93d36eeb22f2eeafff16529dcb7911f19610ad11841270f7acf2d5e2b1d368eca442aec241bc0e5f9
@@ -1,18 +1,25 @@
1
1
  module ActionView
2
2
  class PathHints
3
- def self.apply(view, template, output_buffer)
4
- cache_color = cache_hit?(view, template) ? 'red' : 'green'
3
+ def initialize(view, template)
4
+ @view = view
5
+ @template = template
6
+ end
7
+
8
+ def apply(output_buffer)
9
+ cache_color = cache_hit? ? 'red' : 'green'
5
10
  container_style = "position: relative;border:1px solid #{cache_color}!important;"
6
11
  label_style = "font-size: 9px;background:beige;position:absolute;top:0px;left:0px;"
7
12
  path_hints = "<div style='#{container_style}'>"\
8
- "<span style='#{label_style}'>#{template.inspect}</span>"
13
+ "<span style='#{label_style}'>#{@template.inspect}</span>"
9
14
  output_buffer.prepend(path_hints.html_safe).concat('</div>'.html_safe)
10
15
  end
11
16
 
12
17
  private
13
18
 
14
- def cache_hit?(view, template)
15
- rails_latest? ? view.view_renderer.cache : view.view_renderer.cache_hits[template.virtual_path]
19
+ def cache_hit?
20
+ rails_latest? ?
21
+ @view.view_renderer.cache :
22
+ @view.view_renderer.cache_hits[@template.virtual_path]
16
23
  end
17
24
 
18
25
  def rails_latest?
@@ -22,13 +29,17 @@ module ActionView
22
29
 
23
30
  PartialRenderer.class_eval do
24
31
  def render_partial
25
- PathHints.apply(@view, @template, _render_partial)
32
+ path_hints.apply(_render_partial)
26
33
  end
27
34
 
28
35
  private
29
36
 
37
+ def path_hints
38
+ PathHints.new(@view, @template)
39
+ end
40
+
30
41
  # If there's a way to call super instead of copypasta let me know.
31
- # pulled from actionview-5.1.6/lib/action_view/renderer/partial_renderer.rb:330
42
+ # This works for both rails 4 and 5
32
43
  def _render_partial
33
44
  instrument(:partial) do |payload|
34
45
  view, locals, block = @view, @locals, @block
@@ -46,7 +57,6 @@ module ActionView
46
57
  end
47
58
 
48
59
  content = layout.render(view, locals) { content } if layout
49
- payload[:cache_hit] = view.view_renderer.cache_hits[@template.virtual_path]
50
60
  content
51
61
  end
52
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview-path_hints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tulino