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.
- checksums.yaml +4 -4
- data/lib/actionview/path_hints.rb +18 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71cbaa87fd02fe93b6afcd42261e66ba081ec3f1
|
4
|
+
data.tar.gz: 26ea3aa4d48503fd899647d5b0302499598508b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ccbd76eddbd8866be9bd81756746f3ff4e6cb1cb616bf008036eac8a11cd2c82ff68f1e144d5934f86ebca02c592bd2ab2e3a509c365a507311ad0b1d297f76
|
7
|
+
data.tar.gz: 529a582bd9a1503dd940b8e352da337cfc2ae023d24064b93d36eeb22f2eeafff16529dcb7911f19610ad11841270f7acf2d5e2b1d368eca442aec241bc0e5f9
|
@@ -1,18 +1,25 @@
|
|
1
1
|
module ActionView
|
2
2
|
class PathHints
|
3
|
-
def
|
4
|
-
|
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?
|
15
|
-
rails_latest? ?
|
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
|
-
|
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
|
-
#
|
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
|