view_source_map 0.1.5 → 0.2.0

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: fec1025cecc36c2e8e26e9af8e7e0cde28544221a4b3f95a6daf7cd82cb7b748
4
- data.tar.gz: 7fcb6540bd380f80ec145532e19f967dd463851c9c6486f215df6ea6cc9342e6
3
+ metadata.gz: 91288add88dcab6f1f5dadc04c3ae970465e05a993835e8c0f0d9204b52ad975
4
+ data.tar.gz: 1fbda5300ce5b8bf210a82869293d11ca5d93048b88d6c519fd3e94d5aed6862
5
5
  SHA512:
6
- metadata.gz: 555b0ee72870318f96dae8319827764056f9c8a2b0e8fd0bb5269d7a692c32ddcc3db1701ce132f7d08e353f3493a0b9b3596bcb6e5ae8f2b7f4633c60704183
7
- data.tar.gz: 592bf9032aecd3f4039ca277b3e6a1eccbb821fb582f7ff90423c82f58189df354fe37f886a7757df626d80991227e80fcfce9c6a0adfbcf391105ed2dbdc494
6
+ metadata.gz: 9739c9992f1098b0fe5f1c5a67f6dc34732fdd237dafd0447a4a3d61c51cd8ca9e56453124f1369876abe6e981c88659e9e50efd53e0d8cba1f1c2b185378816
7
+ data.tar.gz: 8def99e9ff8a6a31bd77c9dedcada9014d3d9e5f9cd7a47f19e1518344c7b3c11c14efd3b19e9887f4cc0894ededbdc9b74cde60a92e128e41f254da58b17ca7
@@ -1,62 +1,12 @@
1
- module ViewSourceMap
2
- class Railtie < Rails::Railtie
3
- initializer "render_with_path_comment.initialize" do
4
- if !ENV["DISABLE_VIEW_SOURCE_MAP"] && Rails.env.development?
5
- ViewSourceMap.attach
6
- end
7
- end
8
- end
9
-
10
- def self.attach
11
- return if defined?(@attached) && @attached
12
- @attached = true
13
- ActionView::PartialRenderer.class_eval do
14
- def render_with_path_comment(context, options, block)
15
- content = render_without_path_comment(context, options, block)
16
- return content if ViewSourceMap.force_disabled?(options)
17
-
18
- if @lookup_context.rendered_format == :html
19
- if options[:layout]
20
- name = "#{options[:layout]}(layout)"
21
- else
22
- return content unless @template.respond_to?(:identifier)
23
- path = Pathname.new(@template.identifier)
24
- name = path.relative_path_from(Rails.root)
25
- end
26
- "<!-- BEGIN #{name} -->\n#{content}<!-- END #{name} -->".html_safe
27
- else
28
- content
29
- end
30
- end
31
- alias_method :render_without_path_comment, :render
32
- alias_method :render, :render_with_path_comment
33
- end
1
+ require 'view_source_map/railtie'
34
2
 
35
- ActionView::TemplateRenderer.class_eval do
36
- def render_template_with_path_comment(template, layout_name = nil, locals = {})
37
- view, locals = @view, locals || {}
38
-
39
- render_with_layout(layout_name, locals) do |layout|
40
- instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
41
- content = template.render(view, locals) { |*name| view._layout_for(*name) }
42
- return content if ViewSourceMap.force_disabled?(locals)
43
-
44
- path = Pathname.new(template.identifier)
45
-
46
- if @lookup_context.rendered_format == :html && path.file?
47
- name = path.relative_path_from(Rails.root)
48
- "<!-- BEGIN #{name} -->\n#{content}<!-- END #{name} -->".html_safe
49
- else
50
- content
51
- end
52
- end
53
- end
54
- end
55
- alias_method :render_template_without_path_comment, :render_template
56
- alias_method :render_template, :render_template_with_path_comment
57
- end
58
- end
3
+ if Rails.gem_version >= Gem::Version.new('6')
4
+ require 'view_source_map_rails_6'
5
+ else
6
+ require 'view_source_map_rails_4_and_5'
7
+ end
59
8
 
9
+ module ViewSourceMap
60
10
  def self.detach
61
11
  return unless @attached
62
12
  @attached = false
@@ -0,0 +1,9 @@
1
+ module ViewSourceMap
2
+ class Railtie < Rails::Railtie
3
+ initializer "render_with_path_comment.initialize" do
4
+ if !ENV["DISABLE_VIEW_SOURCE_MAP"] && Rails.env.development?
5
+ ViewSourceMap.attach
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module ViewSourceMap
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,52 @@
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.rendered_format == :html
12
+ if options[:layout]
13
+ name = "#{options[:layout]}(layout)"
14
+ else
15
+ return content unless @template.respond_to?(:identifier)
16
+ path = Pathname.new(@template.identifier)
17
+ name = path.relative_path_from(Rails.root)
18
+ end
19
+ "<!-- BEGIN #{name} -->\n#{content}<!-- END #{name} -->".html_safe
20
+ else
21
+ content
22
+ end
23
+ end
24
+ alias_method :render_without_path_comment, :render
25
+ alias_method :render, :render_with_path_comment
26
+ end
27
+
28
+ ActionView::TemplateRenderer.class_eval do
29
+ def render_template_with_path_comment(template, layout_name = nil, locals = {})
30
+ view, locals = @view, locals || {}
31
+
32
+ render_with_layout(layout_name, locals) do |layout|
33
+ instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
34
+ content = template.render(view, locals) { |*name| view._layout_for(*name) }
35
+ return content if ViewSourceMap.force_disabled?(locals)
36
+
37
+ path = Pathname.new(template.identifier)
38
+
39
+ if @lookup_context.rendered_format == :html && path.file?
40
+ name = path.relative_path_from(Rails.root)
41
+ "<!-- BEGIN #{name} -->\n#{content}<!-- END #{name} -->".html_safe
42
+ else
43
+ content
44
+ end
45
+ end
46
+ end
47
+ end
48
+ alias_method :render_template_without_path_comment, :render_template
49
+ alias_method :render_template, :render_template_with_path_comment
50
+ end
51
+ end
52
+ end
@@ -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.1.5
4
+ version: 0.2.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-05-13 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.2'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec-rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '5'
41
27
  description: This is a Rails plugin to insert the path name of a rendered partial
42
28
  view as HTML comment in development environment
43
29
  email:
@@ -50,7 +36,10 @@ files:
50
36
  - README.md
51
37
  - Rakefile
52
38
  - lib/view_source_map.rb
39
+ - lib/view_source_map/railtie.rb
53
40
  - lib/view_source_map/version.rb
41
+ - lib/view_source_map_rails_4_and_5.rb
42
+ - lib/view_source_map_rails_6.rb
54
43
  homepage: https://github.com/r7kamura/view_source_map
55
44
  licenses: []
56
45
  metadata: {}