view_source_map 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91288add88dcab6f1f5dadc04c3ae970465e05a993835e8c0f0d9204b52ad975
4
- data.tar.gz: 1fbda5300ce5b8bf210a82869293d11ca5d93048b88d6c519fd3e94d5aed6862
3
+ metadata.gz: f923daab2e503883194ea18ae3b22910194657bd2204f8ca500eea302bf16e85
4
+ data.tar.gz: c93b843812ea243aa14aba360220e38e0cecb769bf065ab5ac62944070b52122
5
5
  SHA512:
6
- metadata.gz: 9739c9992f1098b0fe5f1c5a67f6dc34732fdd237dafd0447a4a3d61c51cd8ca9e56453124f1369876abe6e981c88659e9e50efd53e0d8cba1f1c2b185378816
7
- data.tar.gz: 8def99e9ff8a6a31bd77c9dedcada9014d3d9e5f9cd7a47f19e1518344c7b3c11c14efd3b19e9887f4cc0894ededbdc9b74cde60a92e128e41f254da58b17ca7
6
+ metadata.gz: 8a24d8e8bd7a2179811fe387737b6a58728d5986d8c19a7a6dff417448bc13a2f0fa8b015a21cc5c31a03b7294aeccb6590e7c794390870f52a7fc638bc203a9
7
+ data.tar.gz: ec45b183e48a0d735fc6cbe3eecc3df082675c5c51402b24c799f8fdc27c5dc4e85578de0fbf961530b4260f336d1cee32daae9e94c885b5f6dae5c7ed701be5
@@ -1,7 +1,9 @@
1
1
  require 'view_source_map/railtie'
2
2
 
3
- if Rails.gem_version >= Gem::Version.new('6')
3
+ if Rails.gem_version >= Gem::Version.new('6.1')
4
4
  require 'view_source_map_rails_6'
5
+ elsif Rails.gem_version >= Gem::Version.new('6.0')
6
+ require 'view_source_map_rails_6_0'
5
7
  else
6
8
  require 'view_source_map_rails_4_and_5'
7
9
  end
@@ -1,3 +1,3 @@
1
1
  module ViewSourceMap
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -4,18 +4,18 @@ module ViewSourceMap
4
4
  @attached = true
5
5
 
6
6
  ActionView::PartialRenderer.class_eval do
7
- def render_with_path_comment(context, options, block)
8
- content = render_without_path_comment(context, options, block)
9
- return content if ViewSourceMap.force_disabled?(options)
7
+ def render_with_path_comment(partial, context, block)
8
+ content = render_without_path_comment(partial, context, block)
9
+ return content if ViewSourceMap.force_disabled?(@options)
10
10
 
11
11
  if @lookup_context.formats.first == :html
12
12
  case content
13
13
  when ActionView::AbstractRenderer::RenderedCollection
14
14
  content.rendered_templates.each do |rendered_template|
15
- ViewSourceMap.wrap_rendered_template(rendered_template, options)
15
+ ViewSourceMap.wrap_rendered_template(rendered_template, @options)
16
16
  end
17
17
  when ActionView::AbstractRenderer::RenderedTemplate
18
- ViewSourceMap.wrap_rendered_template(content, options)
18
+ ViewSourceMap.wrap_rendered_template(content, @options)
19
19
  end
20
20
  end
21
21
  content
@@ -27,7 +27,11 @@ module ViewSourceMap
27
27
  ActionView::TemplateRenderer.class_eval do
28
28
  def render_template_with_path_comment(view, template, layout_name, locals)
29
29
  render_with_layout(view, template, layout_name, locals) do |layout|
30
- instrument(:template, identifier: template.identifier, layout: layout.try(:virtual_path)) do
30
+ ActiveSupport::Notifications.instrument(
31
+ 'render_template.action_view',
32
+ identifier: template.identifier,
33
+ layout: layout.try(:virtual_path),
34
+ ) do
31
35
  content = template.render(view, locals) { |*name| view._layout_for(*name) }
32
36
  return content if ViewSourceMap.force_disabled?(locals)
33
37
 
@@ -0,0 +1,69 @@
1
+ module ViewSourceMap
2
+ def self.attach
3
+ return if defined?(@attached) && @attached
4
+ @attached = true
5
+
6
+ ActionView::PartialRenderer.class_eval do
7
+ def render_with_path_comment(context, options, block)
8
+ content = render_without_path_comment(context, options, block)
9
+ return content if ViewSourceMap.force_disabled?(options)
10
+
11
+ if @lookup_context.formats.first == :html
12
+ case content
13
+ when ActionView::AbstractRenderer::RenderedCollection
14
+ content.rendered_templates.each do |rendered_template|
15
+ ViewSourceMap.wrap_rendered_template(rendered_template, options)
16
+ end
17
+ when ActionView::AbstractRenderer::RenderedTemplate
18
+ ViewSourceMap.wrap_rendered_template(content, options)
19
+ end
20
+ end
21
+ content
22
+ end
23
+ alias_method :render_without_path_comment, :render
24
+ alias_method :render, :render_with_path_comment
25
+ end
26
+
27
+ ActionView::TemplateRenderer.class_eval do
28
+ def render_template_with_path_comment(view, template, layout_name, locals)
29
+ render_with_layout(view, template, layout_name, locals) do |layout|
30
+ instrument(:template, identifier: template.identifier, layout: layout.try(:virtual_path)) do
31
+ content = template.render(view, locals) { |*name| view._layout_for(*name) }
32
+ return content if ViewSourceMap.force_disabled?(locals)
33
+
34
+ path = Pathname.new(template.identifier)
35
+
36
+ if @lookup_context.formats.first == :html && path.file?
37
+ name = path.relative_path_from(Rails.root)
38
+ "<!-- BEGIN #{name} -->\n#{content}<!-- END #{name} -->".html_safe
39
+ else
40
+ content
41
+ end
42
+ end
43
+ end
44
+ end
45
+ alias_method :render_template_without_path_comment, :render_template
46
+ alias_method :render_template, :render_template_with_path_comment
47
+ end
48
+ end
49
+
50
+ # @private
51
+ # @param [ActionView::AbstractRenderer::RenderedTemplate] rendered_template
52
+ # @param [Hash] options Options passed to #render method.
53
+ def self.wrap_rendered_template(rendered_template, options)
54
+ name = begin
55
+ if options[:layout]
56
+ "#{options[:layout]}(layout)"
57
+ elsif rendered_template.template.respond_to?(:identifier)
58
+ Pathname.new(rendered_template.template.identifier).relative_path_from(Rails.root)
59
+ end
60
+ end
61
+
62
+ if name
63
+ rendered_template.instance_variable_set(
64
+ :@body,
65
+ "<!-- BEGIN #{name} -->\n#{rendered_template.body}<!-- END #{name} -->".html_safe
66
+ )
67
+ end
68
+ end
69
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_source_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-11 00:00:00.000000000 Z
11
+ date: 2020-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -40,6 +40,7 @@ files:
40
40
  - lib/view_source_map/version.rb
41
41
  - lib/view_source_map_rails_4_and_5.rb
42
42
  - lib/view_source_map_rails_6.rb
43
+ - lib/view_source_map_rails_6_0.rb
43
44
  homepage: https://github.com/r7kamura/view_source_map
44
45
  licenses: []
45
46
  metadata: {}
@@ -58,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
59
  - !ruby/object:Gem::Version
59
60
  version: '0'
60
61
  requirements: []
61
- rubyforge_project:
62
- rubygems_version: 2.7.6
62
+ rubygems_version: 3.1.4
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: Rails plugin to view source map