view_inspect 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YmU4ZjA5Yjg2OTdkZTg0NjhjOTlhYzllZDIyZDMyZDM1NjYwZTZiZg==
5
+ data.tar.gz: !binary |-
6
+ NjdiM2UwMzZiMjlmYjM4YmVmYzRjNjQ4MDI4MTMzYzk2MWUyNWYxNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YmZlNTIyNjllZWM2YjQ2NjY2YzQ5ZjEwYTAyZTJlZDAyNjY0YjU0Nzk3NmI5
10
+ NWViOGQ2MzdlYTJkZjUxYTE1MzA4OGQzMmU5MDMwOGU4NDY0NTU4NWRiNWQ0
11
+ MWRjNDA5ZTNkMDJkMzYwNDNkOTJlYWU1ZjA5N2E5ZjMzOWRmZDc=
12
+ data.tar.gz: !binary |-
13
+ NTBmMjVkNTYyMmE3OGFkZTc5N2JlNGQwODYwNGUzNWY0MTU4MGE1YTlmNjBm
14
+ MWNiOTVlNDY2MjZmNDQ4MjFiNzM0MDUyY2E5YjQyMzg0NjVhYWNlY2M2MDg1
15
+ YjliMmZkZDkzZTM4NzI2MmEzYmNjZWJjZWU1ODE5MTY4YjA0NjQ=
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Reginald Tan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = View Inspect
2
+
3
+ View Inspect shows you the source location of a client or server rendered DOM element.
4
+
5
+ == Demo
6
+
7
+
8
+
9
+ == Installation
10
+
11
+ group :development do
12
+ gem "view_inspect"
13
+ end
14
+
15
+ == Warning
16
+
17
+ 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
18
+
19
+ == Support
20
+
21
+ Server Side:
22
+ works with plain html, erb, haml
23
+
24
+ Client Side:
25
+ works with plain Javascript, and tested with Backbone, Ember
26
+
27
+ == Copyright
28
+
29
+ Copyright (c) 2014 Reginald Tan. See LICENSE.txt for
30
+ further details.
31
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "view_inspect"
18
+ gem.homepage = "http://github.com/redgetan/view_inspect"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{TODO: one-line summary of your gem}
21
+ gem.description = %Q{TODO: longer description of your gem}
22
+ gem.email = "redge.tan@gmail.com"
23
+ gem.authors = ["Reginald Tan"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "view_inspect #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,56 @@
1
+ module ViewInspect
2
+ module ERB
3
+ # from erubis 2.7.0
4
+ #DEFAULT_REGEX = /(<%(=+|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?)/m
5
+
6
+ ERB_REGEX_EXCLUDE_ENDING_NEWLINE = /(<%(=+|-|\#|%)?(.*?)([-=])?%>([ \t]*)?)/m
7
+ ERB_STUB = "__erb_stub_placement___"
8
+
9
+ @erb_orig_list = []
10
+
11
+ def self.enable
12
+ ActionView::Template.class_eval do
13
+ alias_method :orig_source, :source
14
+
15
+ def source
16
+ return orig_source unless handler.respond_to? :erb_implementation
17
+ ::ViewInspect::ERB.add_file_line_to_html_tags(orig_source, identifier)
18
+ end
19
+ end
20
+ end
21
+
22
+ def self.add_file_line_to_html_tags(source, filepath)
23
+
24
+ source = replace_erb_with_stub(source)
25
+ source = add_file_line(source, filepath)
26
+ source = replace_stub_with_erb(source)
27
+
28
+ source
29
+ end
30
+
31
+ def self.add_file_line(source, filepath)
32
+ doc = Nokogiri::HTML(source)
33
+
34
+ doc.traverse do |node|
35
+ if node.is_a?(Nokogiri::XML::Element)
36
+ file_line = [filepath, node.line].join(":")
37
+ node.set_attribute "data-orig-file-line", file_line
38
+ end
39
+ end
40
+
41
+ doc.inner_html
42
+ end
43
+
44
+ def self.replace_erb_with_stub(source)
45
+ @erb_orig_list = source.scan(ERB_REGEX_EXCLUDE_ENDING_NEWLINE).map { |a,b,c,d,e| a }
46
+ source.gsub(ERB_REGEX_EXCLUDE_ENDING_NEWLINE,ERB_STUB)
47
+ end
48
+
49
+ def self.replace_stub_with_erb(source)
50
+ source.gsub(ERB_STUB).with_index do |match, index|
51
+ @erb_orig_list[index]
52
+ end
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,24 @@
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
+
@@ -0,0 +1,7 @@
1
+ module ViewInspect
2
+ class Railtie < Rails::Railtie
3
+ initializer "view_inspect_railtie.configure_rails_initialization" do
4
+ ViewInspect.enable
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ require 'view_inspect/erb'
2
+ require 'view_inspect/haml'
3
+
4
+ module ViewInspect
5
+ def self.enable
6
+ return unless allow_view_source_location?
7
+
8
+ ERB.enable
9
+ Haml.enable
10
+ end
11
+
12
+ def self.allow_view_source_location?
13
+ if defined?(Rails)
14
+ config[:allow_view_source_location] || Rails.env.development?
15
+ else
16
+ config[:allow_view_source_location] || false
17
+ end
18
+ end
19
+
20
+ def self.config
21
+ @config ||= {}
22
+ end
23
+
24
+ end
25
+
26
+ require 'view_inspect/railtie' if defined?(Rails)
data/test/helper.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require 'test/unit'
27
+ require 'shoulda'
28
+
29
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
31
+ require 'view_inspect'
32
+
33
+ class Test::Unit::TestCase
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestViewInspect < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "view_inspect"
3
+ s.version = "0.1.0"
4
+
5
+ s.required_rubygems_version = ">= 1.9.3"
6
+
7
+ s.authors = ["Reginald Tan"]
8
+ s.email = "redge.tan@gmail.com"
9
+ s.summary = "Shows you the source location of a DOM element"
10
+ s.description = "Shows you the source location of a DOM element. Works with Erb and Haml templates and Javascript generated DOM"
11
+ s.files = `git ls-files`.split($/)
12
+ s.homepage = "http://github.com/redgetan/view_inspect"
13
+ s.licenses = ["MIT"]
14
+ s.require_paths = ["lib"]
15
+ s.rubygems_version = "2.1.10"
16
+
17
+ s.add_dependency "nokogiri"
18
+ end
19
+
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: view_inspect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Reginald Tan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Shows you the source location of a DOM element. Works with Erb and Haml
28
+ templates and Javascript generated DOM
29
+ email: redge.tan@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .document
35
+ - .gitignore
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/view_inspect.rb
42
+ - lib/view_inspect/erb.rb
43
+ - lib/view_inspect/haml.rb
44
+ - lib/view_inspect/railtie.rb
45
+ - test/helper.rb
46
+ - test/test_view_inspect.rb
47
+ - view_inspect.gemspec
48
+ homepage: http://github.com/redgetan/view_inspect
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 1.9.3
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.1.10
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Shows you the source location of a DOM element
72
+ test_files: []
73
+ has_rdoc: