view_inspect 0.2.0 → 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 +8 -8
- data/LICENSE.txt +2 -0
- data/README.markdown +64 -12
- data/lib/view_inspect.rb +34 -13
- data/lib/view_inspect/client_side_template.rb +33 -0
- data/lib/view_inspect/handlers/eco.rb +11 -0
- data/lib/view_inspect/handlers/ejs.rb +11 -0
- data/lib/view_inspect/handlers/erb.rb +11 -0
- data/lib/view_inspect/handlers/haml.rb +28 -0
- data/lib/view_inspect/handlers/handlebars.rb +11 -0
- data/lib/view_inspect/handlers/html_template.rb +68 -0
- data/lib/view_inspect/{view_inspect.js → handlers/javascript_handler.js} +1 -1
- data/lib/view_inspect/{middleware.rb → rails/middleware.rb} +11 -2
- data/lib/view_inspect/rails/railtie.rb +10 -0
- data/lib/view_inspect/server_side_template.rb +31 -0
- data/lib/view_inspect/version.rb +1 -1
- data/view_inspect.gemspec +2 -2
- metadata +17 -11
- data/example/sample.html +0 -118
- data/lib/view_inspect/erb.rb +0 -58
- data/lib/view_inspect/haml.rb +0 -24
- data/lib/view_inspect/railtie.rb +0 -12
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2U3Y2M4ZDMyMDE3YmM4NjMwNjI0YjEwYzU1NGFiMjk2NGIxZTQ2OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2FiNDI4OTZhMWJmNTE1ODk1YTcyYjQxZDY1MDIxN2Y2NjA1ZjcxZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWM2ZWM2NTZiZDdkZTJhNTMyYjQ4YTI2MmY5NDAxNDNkMmQzMTkwN2JmZTQw
|
10
|
+
N2YwMWY2MjJkMzc3YmUyNDU5MDk2M2ViYzY0YTg0ZjdmMTAyZTExNDNlZDg1
|
11
|
+
OGMyYTUyZjU4MzBkNTczNjYwNmM0OWQyZjNiNzM3NjFkOWU3OWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWY4MTBiNjNiMDBhMTZlOWFlNDNlYzUwNjY0OTJhYWE2ZGQwMTI2ZmZmODQ2
|
14
|
+
Mjg0ODYxZmMxZTkzNTgxNDg1MGNmY2NhYTYzNzE4OTY1OWQ1MTU1ODBlOTZk
|
15
|
+
N2UwMDI4NGIxNzI1YWY2MzExZDViOGRmMTYyZGQ0MjRjZWMwZGY=
|
data/LICENSE.txt
CHANGED
data/README.markdown
CHANGED
@@ -1,33 +1,85 @@
|
|
1
|
-
|
1
|
+
View Inspect
|
2
|
+
============
|
2
3
|
|
3
|
-
View Inspect
|
4
|
+
View Inspect tells you which server-side or client-side template is responsible for rendering a DOM element. Instead of using grep to sift through a large codebase to find the source location of a UI, the information can be found right away in its data-attribute when you open up web inspector. Works with Rails 3 and 4. See below for templates supported and their required libraries.
|
4
5
|
|
5
|
-
|
6
|
+
Source location is added by first stubbing out all template specific expressions (i.e. `<% %>` for erb). Nokogiri parses the resulting valid HTML fragment and adds file:line information to each DOM node. After which stubs are replaced back with original template expressions.
|
6
7
|
|
7
|
-
|
8
|
+
Screenshot
|
9
|
+
----
|
10
|
+
|
11
|
+
[See screenshot](http://i.imgur.com/mD7sQ2m.png)
|
12
|
+
|
13
|
+
Support
|
14
|
+
----
|
15
|
+
| Template | Required Library |
|
16
|
+
| ----------------------- | ---------------------- |
|
17
|
+
| Haml | haml |
|
18
|
+
| ERB | any erb implementation |
|
19
|
+
| Handlebars | ember-rails |
|
20
|
+
| EJS | sprockets |
|
21
|
+
| Eco | sprockets |
|
22
|
+
|
23
|
+
|
24
|
+
Installation
|
25
|
+
----
|
8
26
|
|
9
27
|
group :development do
|
10
28
|
gem "view_inspect"
|
11
29
|
end
|
12
30
|
|
13
|
-
|
31
|
+
ViewInspect is disabled by default. To enable it, add this line on config/environments/development.rb
|
32
|
+
|
33
|
+
ViewInspect.enable = true
|
34
|
+
|
35
|
+
Server-Side Templates
|
36
|
+
----
|
37
|
+
|
38
|
+
If you just want to track file:line origin of server-side templates such as ERB and Haml, you don't have to do anything else. It should just work after enabling it on development.rb
|
39
|
+
|
40
|
+
Client-Side Templates
|
41
|
+
----
|
42
|
+
|
43
|
+
For client-side templates to work, they have to live in separate files as opposed to being embedded in script tags. Also, you might need to clear the sprockets cache on initial use and cache directory is usually stored in `tmp/cache/assets`. Alternatively, you can just clear the whole cache via:
|
44
|
+
|
45
|
+
rake tmp:clear
|
46
|
+
|
47
|
+
Javascript DOM insertion
|
48
|
+
----
|
49
|
+
|
50
|
+
If you use a lot of javascript/jquery to manually insert DOM elements, you can also enable javascript DOM insertion tracking by adding this line to `config/environments/development.rb`.
|
51
|
+
|
52
|
+
ViewInspect.enable_javascript_tracking!
|
53
|
+
|
54
|
+
Then, you need to make sure that in your `config/environments/development.rb`, asset compression is turned off
|
55
|
+
|
56
|
+
config.assets.compress = false
|
57
|
+
|
58
|
+
Also, depending which library you're using, you may need to specify external libraries you wish to prevent from showing up as a potential source location. This is because of the way we track the origin of javascript DOM insertion. In order to do that, pass in an array of library names you want to exclude to `enable_javascript_tracking!` . For example:
|
59
|
+
|
60
|
+
ViewInspect.enable_javascript_tracking!([:jquery, :backbone])
|
61
|
+
|
62
|
+
|
63
|
+
The reason why you may need to do this is because of the way we track the javascript file:line. We intercept the native DOM insertion methods such as appendChild, insertBefore, or replaceChild, look at the stacktrace, and then go through it to find the most recent caller which corresponds to our javascript code.
|
14
64
|
|
15
|
-
<head data-orig-exclude-list="jquery,backbone">
|
16
65
|
|
17
|
-
|
66
|
+
Disable ViewInspect
|
67
|
+
-----
|
18
68
|
|
19
|
-
|
69
|
+
If you want to temporarily disable ViewInspect (ie. you want to profile your code and don't want the extra overhead), you can simply set ViewInspect.enable to false in config/environments/development.rb
|
20
70
|
|
21
|
-
|
71
|
+
ViewInspect.enable = false
|
22
72
|
|
23
73
|
|
74
|
+
Warning
|
75
|
+
----
|
24
76
|
|
25
|
-
|
77
|
+
By default, this is only enabled for development to avoid exposing source code filepath information publicly.
|
26
78
|
|
27
|
-
Don't run this on production. Preferably, you should only run this locally, not even on staging environments. View Inspect shows you the fullpath of your and back-end and front-end code. That is unless you dont mind people seeing things like /home/nandato/rails/app/releases/20131012158211/app/views/ganbatte/show.html.erb:2 in the HTML source
|
28
79
|
|
29
80
|
|
30
|
-
|
81
|
+
Copyright
|
82
|
+
----
|
31
83
|
|
32
84
|
Copyright (c) 2014 Reginald Tan. See LICENSE.txt for
|
33
85
|
further details.
|
data/lib/view_inspect.rb
CHANGED
@@ -1,24 +1,45 @@
|
|
1
|
-
require 'view_inspect/
|
2
|
-
require 'view_inspect/
|
1
|
+
require 'view_inspect/server_side_template'
|
2
|
+
require 'view_inspect/client_side_template'
|
3
|
+
require 'view_inspect/rails/middleware'
|
3
4
|
|
4
5
|
module ViewInspect
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
def self.init(app)
|
8
|
+
return unless allow_view_source_location?
|
9
|
+
|
10
|
+
ServerSideTemplate.handle
|
11
|
+
ClientSideTemplate.handle
|
12
|
+
|
13
|
+
if track_javascript?
|
14
|
+
app.middleware.use ViewInspect::Middleware
|
15
|
+
end
|
8
16
|
end
|
9
17
|
|
10
18
|
def self.allow_view_source_location?
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
19
|
+
enabled? && ::Rails.env.development?
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.enable=(bool)
|
23
|
+
@enable = bool
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.enabled?
|
27
|
+
@enable
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.enable_javascript_tracking!(*library_exclude_list)
|
31
|
+
@track_javascript = true
|
32
|
+
@library_exclude_list = library_exclude_list.flatten
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.track_javascript?
|
36
|
+
@track_javascript
|
16
37
|
end
|
17
38
|
|
18
|
-
def self.
|
19
|
-
@
|
39
|
+
def self.library_exclude_list
|
40
|
+
Array(@library_exclude_list)
|
20
41
|
end
|
21
42
|
|
22
43
|
end
|
23
44
|
|
24
|
-
require 'view_inspect/railtie'
|
45
|
+
require 'view_inspect/rails/railtie'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'view_inspect/handlers/handlebars'
|
2
|
+
require 'view_inspect/handlers/ejs'
|
3
|
+
require 'view_inspect/handlers/eco'
|
4
|
+
|
5
|
+
# Were monkey patching subclasses of Tilt::Template to add file:line information to the original source
|
6
|
+
module ViewInspect
|
7
|
+
module ClientSideTemplate
|
8
|
+
|
9
|
+
def self.handle
|
10
|
+
class_handler_map.each do |klass, handler|
|
11
|
+
klass.class_eval do
|
12
|
+
alias_method :orig_initialize, :initialize
|
13
|
+
|
14
|
+
def initialize(file=nil, line=1, options={}, &block)
|
15
|
+
orig_initialize(file, line, options, &block)
|
16
|
+
handler = ViewInspect::ClientSideTemplate.class_handler_map[self.class]
|
17
|
+
@data = handler.new.add_file_line_to_html_tags(@data, file.to_s)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# only works for sublcasses of Tilt::Template
|
24
|
+
def self.class_handler_map
|
25
|
+
hash = {}
|
26
|
+
hash[::Ember::Handlebars::Template] = Handlers::Handlebars if defined? ::Ember::Handlebars::Template
|
27
|
+
hash[::Sprockets::EjsTemplate] = Handlers::EJS if defined? ::Sprockets::EjsTemplate
|
28
|
+
hash[::Sprockets::EcoTemplate] = Handlers::Eco if defined? ::Sprockets::EcoTemplate
|
29
|
+
hash
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'view_inspect/handlers/html_template'
|
2
|
+
|
3
|
+
module ViewInspect
|
4
|
+
module Handlers
|
5
|
+
class ERB < HTMLTemplate
|
6
|
+
def self.expression_regex
|
7
|
+
/(<%(=+|-|\#|%)?(.*?)([-=])?%>([ \t]*)?)/m # from erubis 2.7.0 #DEFAULT_REGEX = /(<%(=+|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?)/m
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ViewInspect
|
2
|
+
module Handlers
|
3
|
+
module Haml
|
4
|
+
|
5
|
+
def self.augment_source
|
6
|
+
return unless haml_installed?
|
7
|
+
|
8
|
+
::Haml::Compiler.class_eval do
|
9
|
+
alias_method :orig_compile, :compile
|
10
|
+
|
11
|
+
def compile(node)
|
12
|
+
if node.type == :tag
|
13
|
+
file_line = [@options[:filename], node.line].join(":")
|
14
|
+
node.value.attributes.merge!(:data => { :orig_file_line => file_line })
|
15
|
+
end
|
16
|
+
orig_compile(node)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.haml_installed?
|
22
|
+
defined? ::Haml::Compiler
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module ViewInspect
|
4
|
+
module Handlers
|
5
|
+
class HTMLTemplate
|
6
|
+
|
7
|
+
STUB_PREFIX = "__template_expression_stub__"
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@expression_stub_map = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.expression_regex
|
14
|
+
raise "must be implemented by subclass"
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_file_line_to_html_tags(source, filepath)
|
18
|
+
return source if html_layout?(source) # currently dont support html layout templates
|
19
|
+
|
20
|
+
source = replace_expression_with_stub(source)
|
21
|
+
source = add_file_line(source, filepath)
|
22
|
+
source = replace_stub_with_expression(source)
|
23
|
+
|
24
|
+
source
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_file_line(source, filepath)
|
28
|
+
doc = ::Nokogiri::HTML.fragment(source)
|
29
|
+
|
30
|
+
doc.traverse do |node|
|
31
|
+
if node.is_a?(::Nokogiri::XML::Element)
|
32
|
+
file_line = [filepath, node.line].join(":")
|
33
|
+
node.set_attribute "data-orig-file-line", file_line
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
CGI.unescapeHTML(doc.inner_html)
|
38
|
+
end
|
39
|
+
|
40
|
+
def replace_expression_with_stub(source)
|
41
|
+
source.gsub(self.class.expression_regex).with_index do |match, index|
|
42
|
+
stub = "#{STUB_PREFIX}#{index}"
|
43
|
+
stub = preserve_linecount(stub, match)
|
44
|
+
@expression_stub_map[stub] = match
|
45
|
+
stub
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def replace_stub_with_expression(source)
|
50
|
+
@expression_stub_map.inject(source) do |result, (stub, expression)|
|
51
|
+
result = result.sub(stub, expression)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def html_layout?(source)
|
58
|
+
source =~ /<\/html>/
|
59
|
+
end
|
60
|
+
|
61
|
+
def preserve_linecount(stub, match)
|
62
|
+
newline_padding_count = match.lines.count - 1
|
63
|
+
stub + "\n" * newline_padding_count
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ViewInspect
|
2
2
|
class Middleware
|
3
|
-
HEAD_REGEXP = /(<head
|
3
|
+
HEAD_REGEXP = /(<head.*?>)/
|
4
4
|
HTML_CONTENT_TYPE_REGEXP = /text\/html|application\/xhtml\+xml/
|
5
5
|
|
6
6
|
def initialize(app)
|
@@ -20,11 +20,20 @@ module ViewInspect
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def insert_view_inspect_script(body)
|
23
|
+
body = add_library_exclude_list(body)
|
23
24
|
index = get_insert_position(body)
|
24
25
|
body.insert(index, get_inline_script)
|
25
26
|
body
|
26
27
|
end
|
27
28
|
|
29
|
+
def add_library_exclude_list(body)
|
30
|
+
index = body.index(HEAD_REGEXP)
|
31
|
+
old_head = $1
|
32
|
+
new_head = old_head.dup
|
33
|
+
new_head.insert("<head".length, " data-orig-exclude-list='#{ViewInspect.library_exclude_list.join(",")}' ")
|
34
|
+
body.sub(old_head,new_head)
|
35
|
+
end
|
36
|
+
|
28
37
|
def get_insert_position(body)
|
29
38
|
index = body.index(HEAD_REGEXP)
|
30
39
|
match = $1
|
@@ -32,7 +41,7 @@ module ViewInspect
|
|
32
41
|
end
|
33
42
|
|
34
43
|
def get_script
|
35
|
-
filepath = File.expand_path("
|
44
|
+
filepath = File.expand_path("javascript_handler.js","#{File.dirname(__FILE__)}/../handlers")
|
36
45
|
File.read(filepath)
|
37
46
|
end
|
38
47
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'view_inspect/handlers/erb'
|
2
|
+
require 'view_inspect/handlers/haml'
|
3
|
+
|
4
|
+
module ViewInspect
|
5
|
+
module ServerSideTemplate
|
6
|
+
|
7
|
+
def self.handle
|
8
|
+
Handlers::Haml.augment_source
|
9
|
+
|
10
|
+
::ActionView::Template.class_eval do
|
11
|
+
alias_method :orig_initialize, :initialize
|
12
|
+
|
13
|
+
# ActionView Template Resolver uses File.binread to read views
|
14
|
+
# thus making ASCII-8BIT (alias for binary) the default encoding.
|
15
|
+
#
|
16
|
+
# libxml2 which nokogiri uses doesnt support ASCII-8BIT encoding.
|
17
|
+
# That's why we need to encode first before letting nokogiri parse
|
18
|
+
# html fragment and add file:line information to DOM nodes
|
19
|
+
def initialize(source, identifier, handler, details)
|
20
|
+
orig_initialize(source, identifier, handler, details)
|
21
|
+
|
22
|
+
if handler.respond_to? :erb_implementation
|
23
|
+
encode!
|
24
|
+
@source = Handlers::ERB.new.add_file_line_to_html_tags(@source, identifier)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/view_inspect/version.rb
CHANGED
data/view_inspect.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
|
9
9
|
s.authors = ["Reginald Tan"]
|
10
10
|
s.email = "redge.tan@gmail.com"
|
11
|
-
s.summary = "Shows you the source location of a DOM element"
|
12
|
-
s.description = "Shows you the source location of a DOM element. Works with
|
11
|
+
s.summary = "Shows you the source location of a server-side or client-side rendered DOM element"
|
12
|
+
s.description = "Shows you the source location of a server-side or client-side rendered DOM element. Works with Rails 3 and 4"
|
13
13
|
s.files = `git ls-files`.split($/)
|
14
14
|
s.homepage = "http://github.com/redgetan/view_inspect"
|
15
15
|
s.licenses = ["MIT"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_inspect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reginald Tan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -24,8 +24,8 @@ dependencies:
|
|
24
24
|
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description: Shows you the source location of a
|
28
|
-
|
27
|
+
description: Shows you the source location of a server-side or client-side rendered
|
28
|
+
DOM element. Works with Rails 3 and 4
|
29
29
|
email: redge.tan@gmail.com
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
@@ -37,14 +37,19 @@ files:
|
|
37
37
|
- LICENSE.txt
|
38
38
|
- README.markdown
|
39
39
|
- Rakefile
|
40
|
-
- example/sample.html
|
41
40
|
- lib/view_inspect.rb
|
42
|
-
- lib/view_inspect/
|
43
|
-
- lib/view_inspect/
|
44
|
-
- lib/view_inspect/
|
45
|
-
- lib/view_inspect/
|
41
|
+
- lib/view_inspect/client_side_template.rb
|
42
|
+
- lib/view_inspect/handlers/eco.rb
|
43
|
+
- lib/view_inspect/handlers/ejs.rb
|
44
|
+
- lib/view_inspect/handlers/erb.rb
|
45
|
+
- lib/view_inspect/handlers/haml.rb
|
46
|
+
- lib/view_inspect/handlers/handlebars.rb
|
47
|
+
- lib/view_inspect/handlers/html_template.rb
|
48
|
+
- lib/view_inspect/handlers/javascript_handler.js
|
49
|
+
- lib/view_inspect/rails/middleware.rb
|
50
|
+
- lib/view_inspect/rails/railtie.rb
|
51
|
+
- lib/view_inspect/server_side_template.rb
|
46
52
|
- lib/view_inspect/version.rb
|
47
|
-
- lib/view_inspect/view_inspect.js
|
48
53
|
- test/helper.rb
|
49
54
|
- test/test_view_inspect.rb
|
50
55
|
- view_inspect.gemspec
|
@@ -71,6 +76,7 @@ rubyforge_project:
|
|
71
76
|
rubygems_version: 2.1.10
|
72
77
|
signing_key:
|
73
78
|
specification_version: 4
|
74
|
-
summary: Shows you the source location of a DOM
|
79
|
+
summary: Shows you the source location of a server-side or client-side rendered DOM
|
80
|
+
element
|
75
81
|
test_files: []
|
76
82
|
has_rdoc:
|
data/example/sample.html
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="pt-BR">
|
3
|
-
<head data-orig-exclude-list='jquery'>
|
4
|
-
<title>Yes</title>
|
5
|
-
|
6
|
-
<meta charset="utf-8">
|
7
|
-
<meta name="keywords" content=""/>
|
8
|
-
<meta name="description" content=""/>
|
9
|
-
|
10
|
-
<link rel="shortcut icon" href="favicon.ico">
|
11
|
-
|
12
|
-
<style type="text/css" media="screen">
|
13
|
-
.white {
|
14
|
-
width: 50px;
|
15
|
-
height: 50px;
|
16
|
-
background-color: white;
|
17
|
-
border: solid 1px black;
|
18
|
-
}
|
19
|
-
|
20
|
-
.black {
|
21
|
-
width: 50px;
|
22
|
-
height: 50px;
|
23
|
-
background-color: black;
|
24
|
-
border: solid 1px black;
|
25
|
-
margin-top: 20px;
|
26
|
-
}
|
27
|
-
|
28
|
-
.green {
|
29
|
-
width: 30px;
|
30
|
-
height: 10px;
|
31
|
-
background-color: green;
|
32
|
-
}
|
33
|
-
|
34
|
-
.blue {
|
35
|
-
width: 20px;
|
36
|
-
height: 30px;
|
37
|
-
background-color: blue;
|
38
|
-
}
|
39
|
-
|
40
|
-
.red {
|
41
|
-
width: 40px;
|
42
|
-
height: 20px;
|
43
|
-
background-color: red;
|
44
|
-
}
|
45
|
-
|
46
|
-
.yellow {
|
47
|
-
width: 10px;
|
48
|
-
height: 10px;
|
49
|
-
background-color: yellow;
|
50
|
-
}
|
51
|
-
</style>
|
52
|
-
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
53
|
-
<script src="./../lib/view_inspect/view_inspect.js" type="text/javascript" charset="utf-8"></script>
|
54
|
-
|
55
|
-
<!--[if IE]>
|
56
|
-
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
57
|
-
<![endif]-->
|
58
|
-
</head>
|
59
|
-
|
60
|
-
<body>
|
61
|
-
<header>
|
62
|
-
</header>
|
63
|
-
|
64
|
-
<section id="main">
|
65
|
-
</section>
|
66
|
-
|
67
|
-
<footer>
|
68
|
-
</footer>
|
69
|
-
</body>
|
70
|
-
|
71
|
-
<script type="text/javascript" language="javascript" charset="utf-8">
|
72
|
-
//<![CDATA[
|
73
|
-
|
74
|
-
jQuery(document).ready(function(){
|
75
|
-
var node;
|
76
|
-
var child;
|
77
|
-
|
78
|
-
node = document.createElement("div");
|
79
|
-
node.className = "white";
|
80
|
-
|
81
|
-
document.getElementById("main").appendChild(node);
|
82
|
-
|
83
|
-
child = document.createElement("div");
|
84
|
-
child.className = "green";
|
85
|
-
|
86
|
-
node.appendChild(child);
|
87
|
-
|
88
|
-
child_2 = document.createElement("div");
|
89
|
-
child_2.className = "green";
|
90
|
-
|
91
|
-
node.replaceChild(child_2,child);
|
92
|
-
|
93
|
-
child_3 = document.createElement("div");
|
94
|
-
child_3.className = "blue";
|
95
|
-
|
96
|
-
node.insertBefore(child_3,child_2);
|
97
|
-
|
98
|
-
$node = $("<div class='black'>");
|
99
|
-
|
100
|
-
$("#main").append($node);
|
101
|
-
|
102
|
-
$child = $("<div class='green'>");
|
103
|
-
|
104
|
-
$node.append($child);
|
105
|
-
|
106
|
-
|
107
|
-
$child_2 = $("<div class='yellow'>");
|
108
|
-
|
109
|
-
$child.replaceWith($child_2);
|
110
|
-
|
111
|
-
$child_3 = $("<div class='red'>");
|
112
|
-
|
113
|
-
$child_3.insertBefore($child_2);
|
114
|
-
|
115
|
-
});
|
116
|
-
//]]>
|
117
|
-
</script>
|
118
|
-
</html>
|
data/lib/view_inspect/erb.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
|
3
|
-
module ViewInspect
|
4
|
-
module ERB
|
5
|
-
# from erubis 2.7.0
|
6
|
-
#DEFAULT_REGEX = /(<%(=+|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?)/m
|
7
|
-
|
8
|
-
ERB_REGEX_EXCLUDE_ENDING_NEWLINE = /(<%(=+|-|\#|%)?(.*?)([-=])?%>([ \t]*)?)/m
|
9
|
-
ERB_STUB = "__erb_stub_placement___"
|
10
|
-
|
11
|
-
@erb_orig_list = []
|
12
|
-
|
13
|
-
def self.enable
|
14
|
-
ActionView::Template.class_eval do
|
15
|
-
alias_method :orig_source, :source
|
16
|
-
|
17
|
-
def source
|
18
|
-
return orig_source unless handler.respond_to? :erb_implementation
|
19
|
-
::ViewInspect::ERB.add_file_line_to_html_tags(orig_source, identifier)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.add_file_line_to_html_tags(source, filepath)
|
25
|
-
|
26
|
-
source = replace_erb_with_stub(source)
|
27
|
-
source = add_file_line(source, filepath)
|
28
|
-
source = replace_stub_with_erb(source)
|
29
|
-
|
30
|
-
source
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.add_file_line(source, filepath)
|
34
|
-
doc = ::Nokogiri::HTML(source)
|
35
|
-
|
36
|
-
doc.traverse do |node|
|
37
|
-
if node.is_a?(::Nokogiri::XML::Element)
|
38
|
-
file_line = [filepath, node.line].join(":")
|
39
|
-
node.set_attribute "data-orig-file-line", file_line
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
doc.inner_html
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.replace_erb_with_stub(source)
|
47
|
-
@erb_orig_list = source.scan(ERB_REGEX_EXCLUDE_ENDING_NEWLINE).map { |a,b,c,d,e| a }
|
48
|
-
source.gsub(ERB_REGEX_EXCLUDE_ENDING_NEWLINE,ERB_STUB)
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.replace_stub_with_erb(source)
|
52
|
-
source.gsub(ERB_STUB).with_index do |match, index|
|
53
|
-
@erb_orig_list[index]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
data/lib/view_inspect/haml.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module ViewInspect
|
2
|
-
module Haml
|
3
|
-
def self.enable
|
4
|
-
return unless haml_installed?
|
5
|
-
|
6
|
-
::Haml::Compiler.class_eval do
|
7
|
-
alias_method :orig_compile, :compile
|
8
|
-
|
9
|
-
def compile(node)
|
10
|
-
if node.type == :tag
|
11
|
-
file_line = [@options[:filename], node.line].join(":")
|
12
|
-
node.value.attributes.merge!(:data => { :orig_file_line => file_line })
|
13
|
-
end
|
14
|
-
orig_compile(node)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.haml_installed?
|
20
|
-
defined? ::Haml::Compiler
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
data/lib/view_inspect/railtie.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'view_inspect/middleware'
|
2
|
-
|
3
|
-
module ViewInspect
|
4
|
-
class Railtie < Rails::Railtie
|
5
|
-
initializer "view_inspect_railtie.configure_rails_initialization" do |app|
|
6
|
-
if ViewInspect.allow_view_source_location?
|
7
|
-
ViewInspect.enable
|
8
|
-
app.middleware.use ViewInspect::Middleware
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|