fluoroscope 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/fluoroscope/hover.js +13 -0
- data/app/assets/javascripts/fluoroscope/index.js +1 -0
- data/app/controllers/fluoroscope/action_controller_extension.rb +14 -0
- data/app/views/fluoroscope/_fluoroscope_wrapper.html.erb +9 -0
- data/lib/fluoroscope.rb +0 -1
- data/lib/fluoroscope/engine.rb +5 -0
- data/lib/fluoroscope/rendering.rb +23 -14
- data/lib/fluoroscope/version.rb +1 -1
- metadata +8 -7
- data/app/views/fluoroscope/_close_fluoroscope.html.erb +0 -2
- data/app/views/fluoroscope/_open_fluoroscope.html.erb +0 -2
- data/lib/fluoroscope/fluoroscope_renderer.rb +0 -135
@@ -0,0 +1 @@
|
|
1
|
+
//= require_tree .
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Fluoroscope::ActionControllerExtension
|
2
|
+
def self.included(base)
|
3
|
+
base.send(:include, Filters)
|
4
|
+
base.send(:before_filter, :enable_fluoroscope?)
|
5
|
+
end
|
6
|
+
|
7
|
+
module Filters
|
8
|
+
def enable_fluoroscope?
|
9
|
+
if params[:fluoroscope] == 'true'
|
10
|
+
request.env[:fluoroscope_enabled] = true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/fluoroscope.rb
CHANGED
data/lib/fluoroscope/engine.rb
CHANGED
@@ -2,26 +2,35 @@ module ActionView
|
|
2
2
|
class PartialRenderer
|
3
3
|
alias_method :render_original, :render
|
4
4
|
def render(context, options, block)
|
5
|
-
if context.request
|
5
|
+
if fluoroscope_enabled?(context.request)
|
6
6
|
setup(context, options, block)
|
7
|
-
fluoroscope_renderer =
|
8
|
-
|
9
|
-
|
7
|
+
fluoroscope_renderer = PartialRenderer.new(@lookup_context)
|
8
|
+
template = find_template(path=@path, locals=@locals.keys)
|
9
|
+
locals = options[:locals].nil? ? {:template => template} : {:template => template}.merge(options[:locals])
|
10
|
+
|
11
|
+
fluoroscope_renderer.render_original(context,
|
12
|
+
{:partial => '/fluoroscope/fluoroscope_wrapper',
|
13
|
+
:locals => locals
|
14
|
+
}, lambda{render_original(context, options, block)})
|
10
15
|
|
11
|
-
result << fluoroscope_renderer.render(context,
|
12
|
-
{:partial => '/fluoroscope/open_fluoroscope',
|
13
|
-
:locals => {:path => template}
|
14
|
-
}, nil)
|
15
|
-
result << render_original(context, options, block)
|
16
|
-
result << fluoroscope_renderer.render(context,
|
17
|
-
{:partial => '/fluoroscope/close_fluoroscope',
|
18
|
-
:locals => {:path => template}
|
19
|
-
}, nil)
|
20
|
-
result
|
21
16
|
else
|
22
17
|
render_original(context, options, block)
|
23
18
|
end
|
24
19
|
end
|
25
20
|
|
21
|
+
protected
|
22
|
+
|
23
|
+
def fluoroscope_enabled?(request)
|
24
|
+
config_setting = Rails.application.config.enable_fluoroscope rescue nil
|
25
|
+
if config_setting.nil?
|
26
|
+
if defined?(request.env[:fluoroscope_enabled]) && request.env[:fluoroscope_enabled]
|
27
|
+
return true
|
28
|
+
end
|
29
|
+
else
|
30
|
+
return config_setting
|
31
|
+
end
|
32
|
+
|
33
|
+
return false
|
34
|
+
end
|
26
35
|
end
|
27
36
|
end
|
data/lib/fluoroscope/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluoroscope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -50,11 +50,12 @@ executables: []
|
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
|
-
- app/
|
54
|
-
- app/
|
53
|
+
- app/assets/javascripts/fluoroscope/hover.js
|
54
|
+
- app/assets/javascripts/fluoroscope/index.js
|
55
|
+
- app/controllers/fluoroscope/action_controller_extension.rb
|
56
|
+
- app/views/fluoroscope/_fluoroscope_wrapper.html.erb
|
55
57
|
- config/routes.rb
|
56
58
|
- lib/fluoroscope/engine.rb
|
57
|
-
- lib/fluoroscope/fluoroscope_renderer.rb
|
58
59
|
- lib/fluoroscope/rendering.rb
|
59
60
|
- lib/fluoroscope/version.rb
|
60
61
|
- lib/fluoroscope.rb
|
@@ -76,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
77
|
version: '0'
|
77
78
|
segments:
|
78
79
|
- 0
|
79
|
-
hash:
|
80
|
+
hash: -1350007233444960618
|
80
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
82
|
none: false
|
82
83
|
requirements:
|
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
86
|
version: '0'
|
86
87
|
segments:
|
87
88
|
- 0
|
88
|
-
hash:
|
89
|
+
hash: -1350007233444960618
|
89
90
|
requirements: []
|
90
91
|
rubyforge_project:
|
91
92
|
rubygems_version: 1.8.24
|
@@ -1,135 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/object/blank'
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
class FluoroscopeRenderer < AbstractRenderer
|
5
|
-
PARTIAL_NAMES = Hash.new { |h,k| h[k] = {} }
|
6
|
-
|
7
|
-
def initialize(*)
|
8
|
-
super
|
9
|
-
@context_prefix = @lookup_context.prefixes.first
|
10
|
-
@partial_names = PARTIAL_NAMES[@context_prefix]
|
11
|
-
end
|
12
|
-
|
13
|
-
def render(context, options, block)
|
14
|
-
setup(context, options, block)
|
15
|
-
identifier = (@template = find_partial) ? @template.identifier : @path
|
16
|
-
|
17
|
-
@lookup_context.rendered_format ||= begin
|
18
|
-
if @template && @template.formats.present?
|
19
|
-
@template.formats.first
|
20
|
-
else
|
21
|
-
formats.first
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
render_partial
|
26
|
-
end
|
27
|
-
|
28
|
-
def render_partial
|
29
|
-
locals, view, block = @locals, @view, @block
|
30
|
-
object, as = @object, @variable
|
31
|
-
|
32
|
-
if !block && (layout = @options[:layout])
|
33
|
-
layout = find_template(layout.to_s)
|
34
|
-
end
|
35
|
-
|
36
|
-
object ||= locals[as]
|
37
|
-
locals[as] = object
|
38
|
-
|
39
|
-
content = @template.render(view, locals) do |*name|
|
40
|
-
view._layout_for(*name, &block)
|
41
|
-
end
|
42
|
-
|
43
|
-
content = layout.render(view, locals){ content } if layout
|
44
|
-
content
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def setup(context, options, block)
|
50
|
-
@view = context
|
51
|
-
partial = options[:partial]
|
52
|
-
|
53
|
-
@options = options
|
54
|
-
@locals = options[:locals] || {}
|
55
|
-
@block = block
|
56
|
-
@details = extract_details(options)
|
57
|
-
|
58
|
-
if String === partial
|
59
|
-
@object = options[:object]
|
60
|
-
@path = partial
|
61
|
-
else
|
62
|
-
@object = partial
|
63
|
-
@path = partial_path
|
64
|
-
end
|
65
|
-
|
66
|
-
if @path
|
67
|
-
@variable, @variable_counter = retrieve_variable(@path)
|
68
|
-
else
|
69
|
-
paths.map! { |path| retrieve_variable(path).unshift(path) }
|
70
|
-
end
|
71
|
-
|
72
|
-
if String === partial && @variable.to_s !~ /^[a-z_][a-zA-Z_0-9]*$/
|
73
|
-
raise ArgumentError.new("The partial name (#{partial}) is not a valid Ruby identifier; " +
|
74
|
-
"make sure your partial name starts with a letter or underscore, " +
|
75
|
-
"and is followed by any combinations of letters, numbers, or underscores.")
|
76
|
-
end
|
77
|
-
|
78
|
-
extract_format(@path, @details)
|
79
|
-
self
|
80
|
-
end
|
81
|
-
|
82
|
-
def find_partial
|
83
|
-
if path = @path
|
84
|
-
locals = @locals.keys
|
85
|
-
locals << @variable
|
86
|
-
find_template(path, locals)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def find_template(path=@path, locals=@locals.keys)
|
91
|
-
prefixes = path.include?(?/) ? [] : @lookup_context.prefixes
|
92
|
-
@lookup_context.find_template(path, prefixes, true, locals, @details)
|
93
|
-
end
|
94
|
-
|
95
|
-
def partial_path(object = @object)
|
96
|
-
object = object.to_model if object.respond_to?(:to_model)
|
97
|
-
|
98
|
-
path = if object.respond_to?(:to_partial_path)
|
99
|
-
object.to_partial_path
|
100
|
-
else
|
101
|
-
klass = object.class
|
102
|
-
if klass.respond_to?(:model_name)
|
103
|
-
ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_partial_path directly instead."
|
104
|
-
klass.model_name.partial_path
|
105
|
-
else
|
106
|
-
raise ArgumentError.new("'#{object.inspect}' is not an ActiveModel-compatible object that returns a valid partial path.")
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
@partial_names[path] ||= merge_prefix_into_object_path(@context_prefix, path.dup)
|
111
|
-
end
|
112
|
-
|
113
|
-
def merge_prefix_into_object_path(prefix, object_path)
|
114
|
-
if prefix.include?(?/) && object_path.include?(?/)
|
115
|
-
prefixes = []
|
116
|
-
prefix_array = File.dirname(prefix).split('/')
|
117
|
-
object_path_array = object_path.split('/')[0..-3] # skip model dir & partial
|
118
|
-
|
119
|
-
prefix_array.each_with_index do |dir, index|
|
120
|
-
break if dir == object_path_array[index]
|
121
|
-
prefixes << dir
|
122
|
-
end
|
123
|
-
|
124
|
-
(prefixes << object_path).join("/")
|
125
|
-
else
|
126
|
-
object_path
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def retrieve_variable(path)
|
131
|
-
variable = @options.fetch(:as) { path[%r'_?(\w+)(\.\w+)*$', 1] }.try(:to_sym)
|
132
|
-
[variable]
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|