view_source_map 0.1.2 → 0.3.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
- SHA1:
3
- metadata.gz: bccd483f9450b5b1c9efbe152790a8c4bb5cd469
4
- data.tar.gz: 46d8fbd4a7d9c5d29ae713641e7fb5e1f0a06ddd
2
+ SHA256:
3
+ metadata.gz: f923daab2e503883194ea18ae3b22910194657bd2204f8ca500eea302bf16e85
4
+ data.tar.gz: c93b843812ea243aa14aba360220e38e0cecb769bf065ab5ac62944070b52122
5
5
  SHA512:
6
- metadata.gz: e265a9cb71b6b5e3d0570aed11700eddb302ab2f4af507de28d5089657456ce95226b790bb66719dc29aaf8c4f8a92ac02c06cc32b53660a2f33bc44ab8becda
7
- data.tar.gz: 41de9cbc55c474d9beeb2752b4e9f15d76f3f1db5238fc85f1cbc4b3c9c79e1990b90263dd4a97aaf41c40c0dc0b5b85ddae0809e72b03df13f78f7f90313e0c
6
+ metadata.gz: 8a24d8e8bd7a2179811fe387737b6a58728d5986d8c19a7a6dff417448bc13a2f0fa8b015a21cc5c31a03b7294aeccb6590e7c794390870f52a7fc638bc203a9
7
+ data.tar.gz: ec45b183e48a0d735fc6cbe3eecc3df082675c5c51402b24c799f8fdc27c5dc4e85578de0fbf961530b4260f336d1cee32daae9e94c885b5f6dae5c7ed701be5
data/README.md CHANGED
@@ -1,7 +1,12 @@
1
1
  # ViewSourceMap
2
+
3
+ [![Gem](https://img.shields.io/gem/v/view_source_map.svg)](https://rubygems.org/gems/view_source_map)
4
+ [![Build Status](https://travis-ci.org/r7kamura/view_source_map.svg?branch=master)](https://travis-ci.org/r7kamura/view_source_map)
5
+
2
6
  This is a Rails plugin to insert the path name of a rendered partial view as HTML comment in development environment.
3
7
 
4
8
  ## Usage
9
+
5
10
  In your Gemfile
6
11
 
7
12
  ```ruby
@@ -16,11 +21,8 @@ and launch your rails server in development environment:
16
21
  $ rails s
17
22
  ```
18
23
 
19
- then see the source of your page:
20
-
21
- ![](http://dl.dropbox.com/u/5978869/image/20121204_171625.png)
22
-
23
24
  ## Tips
25
+
24
26
  Sometimes this adds too much noise to the html when you're developing.
25
27
  There is a simple way to turn it off.
26
28
 
@@ -1,60 +1,14 @@
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
- path = Pathname.new(@template.identifier)
23
- name = path.relative_path_from(Rails.root)
24
- end
25
- "<!-- BEGIN #{name} -->\n#{content}<!-- END #{name} -->".html_safe
26
- else
27
- content
28
- end
29
- end
30
- alias_method :render_without_path_comment, :render
31
- alias_method :render, :render_with_path_comment
32
- end
33
-
34
- ActionView::TemplateRenderer.class_eval do
35
- def render_template_with_path_comment(template, layout_name = nil, locals = {})
36
- view, locals = @view, locals || {}
37
-
38
- render_with_layout(layout_name, locals) do |layout|
39
- instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
40
- content = template.render(view, locals) { |*name| view._layout_for(*name) }
41
- return content if ViewSourceMap.force_disabled?(locals)
42
-
43
- if @lookup_context.rendered_format == :html and template.class != ActionView::Template::Text
44
- path = Pathname.new(template.identifier)
45
- name = path.relative_path_from(Rails.root)
46
- "<!-- BEGIN #{name} -->\n#{content}<!-- END #{name} -->".html_safe
47
- else
48
- content
49
- end
50
- end
51
- end
52
- end
53
- alias_method :render_template_without_path_comment, :render_template
54
- alias_method :render_template, :render_template_with_path_comment
55
- end
56
- end
1
+ require 'view_source_map/railtie'
2
+
3
+ if Rails.gem_version >= Gem::Version.new('6.1')
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'
7
+ else
8
+ require 'view_source_map_rails_4_and_5'
9
+ end
57
10
 
11
+ module ViewSourceMap
58
12
  def self.detach
59
13
  return unless @attached
60
14
  @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.2"
2
+ VERSION = "0.3.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,73 @@
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(partial, context, block)
8
+ content = render_without_path_comment(partial, context, 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
+ ActiveSupport::Notifications.instrument(
31
+ 'render_template.action_view',
32
+ identifier: template.identifier,
33
+ layout: layout.try(:virtual_path),
34
+ ) do
35
+ content = template.render(view, locals) { |*name| view._layout_for(*name) }
36
+ return content if ViewSourceMap.force_disabled?(locals)
37
+
38
+ path = Pathname.new(template.identifier)
39
+
40
+ if @lookup_context.formats.first == :html && path.file?
41
+ name = path.relative_path_from(Rails.root)
42
+ "<!-- BEGIN #{name} -->\n#{content}<!-- END #{name} -->".html_safe
43
+ else
44
+ content
45
+ end
46
+ end
47
+ end
48
+ end
49
+ alias_method :render_template_without_path_comment, :render_template
50
+ alias_method :render_template, :render_template_with_path_comment
51
+ end
52
+ end
53
+
54
+ # @private
55
+ # @param [ActionView::AbstractRenderer::RenderedTemplate] rendered_template
56
+ # @param [Hash] options Options passed to #render method.
57
+ def self.wrap_rendered_template(rendered_template, options)
58
+ name = begin
59
+ if options[:layout]
60
+ "#{options[:layout]}(layout)"
61
+ elsif rendered_template.template.respond_to?(:identifier)
62
+ Pathname.new(rendered_template.template.identifier).relative_path_from(Rails.root)
63
+ end
64
+ end
65
+
66
+ if name
67
+ rendered_template.instance_variable_set(
68
+ :@body,
69
+ "<!-- BEGIN #{name} -->\n#{rendered_template.body}<!-- END #{name} -->".html_safe
70
+ )
71
+ end
72
+ end
73
+ 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.2
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: 2016-12-05 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
@@ -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,11 @@ 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
43
+ - lib/view_source_map_rails_6_0.rb
54
44
  homepage: https://github.com/r7kamura/view_source_map
55
45
  licenses: []
56
46
  metadata: {}
@@ -69,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
59
  - !ruby/object:Gem::Version
70
60
  version: '0'
71
61
  requirements: []
72
- rubyforge_project:
73
- rubygems_version: 2.5.2
62
+ rubygems_version: 3.1.4
74
63
  signing_key:
75
64
  specification_version: 4
76
65
  summary: Rails plugin to view source map