inspect_partials 0.0.1
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.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/app/assets/stylesheets/inspect_partials/inspect_partials.css +26 -0
- data/inspect_partials.gemspec +20 -0
- data/lib/inspect_partials/engine.rb +37 -0
- data/lib/inspect_partials/rack_handler.rb +41 -0
- data/lib/inspect_partials/version.rb +3 -0
- data/lib/inspect_partials.rb +3 -0
- metadata +54 -0
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
div.inspect-partials-tooltip {
|
2
|
+
display: block;
|
3
|
+
}
|
4
|
+
|
5
|
+
div.inspect-partials-tooltip::before {
|
6
|
+
content: attr(data-tip);
|
7
|
+
|
8
|
+
font-size: 10px;
|
9
|
+
position: fixed;
|
10
|
+
z-index: 999;
|
11
|
+
white-space: nowrap;
|
12
|
+
left: 5px;
|
13
|
+
top: 5px;
|
14
|
+
background: #000;
|
15
|
+
color: #e0e0e0;
|
16
|
+
padding: 0px 7px;
|
17
|
+
line-height: 24px;
|
18
|
+
height: 24px;
|
19
|
+
width: 500px;
|
20
|
+
opacity: 0;
|
21
|
+
}
|
22
|
+
|
23
|
+
div.inspect-partials-tooltip:hover::before {
|
24
|
+
opacity: 1;
|
25
|
+
bottom: -35px;
|
26
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "inspect_partials/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "inspect_partials"
|
7
|
+
s.version = InspectPartials::VERSION
|
8
|
+
s.authors = ["Victor Savkin"]
|
9
|
+
s.email = ["vic.savkin@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Gem showing partial names}
|
12
|
+
s.description = %q{Gem showing partial names}
|
13
|
+
|
14
|
+
s.rubyforge_project = "inspect_partials"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module InspectPartials
|
2
|
+
class InspectPartialsEngine < Rails::Engine
|
3
|
+
initializer "inspect_partials_engine.add_rack_middleware" do |app|
|
4
|
+
app.middleware.use ::ActionDispatch::Static, "#{root}/app/assets"
|
5
|
+
app.middleware.use InspectPartials::RackHandler
|
6
|
+
end
|
7
|
+
|
8
|
+
initializer "inspect_partials_engine.patch_action_view_template" do
|
9
|
+
next unless config.respond_to?(:inspect_partials)
|
10
|
+
next unless config.inspect_partials
|
11
|
+
|
12
|
+
class ActionView::Template
|
13
|
+
alias :show_partials_railtie_old_source :source
|
14
|
+
|
15
|
+
def source
|
16
|
+
@show_partials_railtie_new_source ||= source_wrapped_into_tooltip
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def source_wrapped_into_tooltip
|
21
|
+
source = show_partials_railtie_old_source
|
22
|
+
return source if layout?
|
23
|
+
%Q{<div class="inspect-partials-tooltip" data-tip="#{relative_identifier}">#{source}</div>}
|
24
|
+
end
|
25
|
+
|
26
|
+
def relative_identifier
|
27
|
+
match = /app\/views.*/.match identifier
|
28
|
+
match[0] ? match[0] : identifier
|
29
|
+
end
|
30
|
+
|
31
|
+
def layout?
|
32
|
+
relative_identifier =~ /layouts\//
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module InspectPartials
|
2
|
+
class RackHandler
|
3
|
+
def initialize app
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call env
|
8
|
+
status, headers, response = @app.call(env)
|
9
|
+
new_response = transform_response(response)
|
10
|
+
new_headers = transform_headers(new_response, headers)
|
11
|
+
[status, new_headers, new_response]
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def transform_response response
|
16
|
+
source = ""
|
17
|
+
response.each {|_| source << _}
|
18
|
+
source.blank? ? response : [add_stylesheet(source)]
|
19
|
+
end
|
20
|
+
|
21
|
+
def transform_headers(response, headers)
|
22
|
+
length = 0
|
23
|
+
response.each {|_| length += _.size}
|
24
|
+
headers.has_key?('Content-Length') ? headers.merge('Content-Length' => length.to_s) : headers
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_stylesheet source
|
28
|
+
head_open = source.index("<head")
|
29
|
+
return source unless head_open
|
30
|
+
|
31
|
+
head_pos = source.index(">", head_open) + 1
|
32
|
+
return source unless head_pos
|
33
|
+
|
34
|
+
source.insert(head_pos, stylesheet_tag)
|
35
|
+
end
|
36
|
+
|
37
|
+
def stylesheet_tag
|
38
|
+
%q{<link href="/assets/inspect_partials/inspect_partials.css" media="screen" rel="stylesheet" type="text/css"/>}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inspect_partials
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Victor Savkin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-31 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Gem showing partial names
|
15
|
+
email:
|
16
|
+
- vic.savkin@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- Rakefile
|
24
|
+
- app/assets/stylesheets/inspect_partials/inspect_partials.css
|
25
|
+
- inspect_partials.gemspec
|
26
|
+
- lib/inspect_partials.rb
|
27
|
+
- lib/inspect_partials/engine.rb
|
28
|
+
- lib/inspect_partials/rack_handler.rb
|
29
|
+
- lib/inspect_partials/version.rb
|
30
|
+
homepage: ''
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project: inspect_partials
|
50
|
+
rubygems_version: 1.8.10
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Gem showing partial names
|
54
|
+
test_files: []
|