10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/view_source_map.rb', line 10
def self.attach
return if defined?(@attached) && @attached
@attached = true
ActionView::PartialRenderer.class_eval do
def (context, options, block)
content = (context, options, block)
return content if ViewSourceMap.force_disabled?(options)
if @lookup_context.rendered_format == :html
if options[:layout]
name = "#{options[:layout]}(layout)"
else
path = Pathname.new(@template.identifier)
name = path.relative_path_from(Rails.root)
end
"<!-- BEGIN #{name} -->\n#{content}<!-- END #{name} -->".html_safe
else
content
end
end
alias_method :render_without_path_comment, :render
alias_method :render, :render_with_path_comment
end
ActionView::TemplateRenderer.class_eval do
def (template, layout_name = nil, locals = {})
view, locals = @view, locals || {}
render_with_layout(layout_name, locals) do |layout|
instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
content = template.render(view, locals) { |*name| view._layout_for(*name) }
return content if ViewSourceMap.force_disabled?(locals)
if @lookup_context.rendered_format == :html && template.class != ActionView::Template::Text && !template.identifier.to_s.empty?
path = Pathname.new(template.identifier)
name = path.relative_path_from(Rails.root)
"<!-- BEGIN #{name} -->\n#{content}<!-- END #{name} -->".html_safe
else
content
end
end
end
end
alias_method :render_template_without_path_comment, :render_template
alias_method :render_template, :render_template_with_path_comment
end
end
|