actionpack 4.0.1 → 4.2.11.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +402 -1173
- data/MIT-LICENSE +1 -1
- data/README.rdoc +7 -7
- data/lib/abstract_controller/base.rb +39 -7
- data/lib/abstract_controller/callbacks.rb +32 -53
- data/lib/abstract_controller/collector.rb +11 -1
- data/lib/abstract_controller/helpers.rb +26 -16
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
- data/lib/abstract_controller/rendering.rb +57 -127
- data/lib/abstract_controller/url_for.rb +1 -1
- data/lib/abstract_controller.rb +1 -2
- data/lib/action_controller/base.rb +19 -10
- data/lib/action_controller/caching/fragments.rb +7 -1
- data/lib/action_controller/caching.rb +2 -12
- data/lib/action_controller/log_subscriber.rb +29 -20
- data/lib/action_controller/metal/conditional_get.rb +37 -12
- data/lib/action_controller/metal/data_streaming.rb +1 -1
- data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
- data/lib/action_controller/metal/exceptions.rb +1 -1
- data/lib/action_controller/metal/flash.rb +17 -0
- data/lib/action_controller/metal/force_ssl.rb +2 -2
- data/lib/action_controller/metal/head.rb +8 -6
- data/lib/action_controller/metal/helpers.rb +6 -2
- data/lib/action_controller/metal/http_authentication.rb +45 -23
- data/lib/action_controller/metal/instrumentation.rb +9 -6
- data/lib/action_controller/metal/live.rb +173 -20
- data/lib/action_controller/metal/mime_responds.rb +127 -232
- data/lib/action_controller/metal/params_wrapper.rb +16 -9
- data/lib/action_controller/metal/rack_delegation.rb +1 -1
- data/lib/action_controller/metal/redirecting.rb +34 -26
- data/lib/action_controller/metal/renderers.rb +39 -12
- data/lib/action_controller/metal/rendering.rb +41 -14
- data/lib/action_controller/metal/request_forgery_protection.rb +147 -19
- data/lib/action_controller/metal/streaming.rb +19 -21
- data/lib/action_controller/metal/strong_parameters.rb +166 -22
- data/lib/action_controller/metal/testing.rb +0 -1
- data/lib/action_controller/metal/url_for.rb +11 -12
- data/lib/action_controller/metal.rb +14 -8
- data/lib/action_controller/model_naming.rb +1 -1
- data/lib/action_controller/railtie.rb +5 -1
- data/lib/action_controller/test_case.rb +160 -94
- data/lib/action_controller.rb +2 -18
- data/lib/action_dispatch/http/cache.rb +5 -4
- data/lib/action_dispatch/http/filter_parameters.rb +2 -2
- data/lib/action_dispatch/http/filter_redirect.rb +5 -4
- data/lib/action_dispatch/http/headers.rb +46 -10
- data/lib/action_dispatch/http/mime_negotiation.rb +31 -4
- data/lib/action_dispatch/http/mime_type.rb +25 -26
- data/lib/action_dispatch/http/mime_types.rb +1 -0
- data/lib/action_dispatch/http/parameter_filter.rb +1 -1
- data/lib/action_dispatch/http/parameters.rb +25 -41
- data/lib/action_dispatch/http/request.rb +49 -32
- data/lib/action_dispatch/http/response.rb +127 -25
- data/lib/action_dispatch/http/upload.rb +9 -21
- data/lib/action_dispatch/http/url.rb +97 -70
- data/lib/action_dispatch/journey/formatter.rb +35 -19
- data/lib/action_dispatch/journey/gtg/builder.rb +3 -3
- data/lib/action_dispatch/journey/gtg/simulator.rb +10 -7
- data/lib/action_dispatch/journey/gtg/transition_table.rb +23 -33
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
- data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
- data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -5
- data/lib/action_dispatch/journey/nodes/node.rb +4 -0
- data/lib/action_dispatch/journey/parser.rb +51 -59
- data/lib/action_dispatch/journey/parser.y +12 -10
- data/lib/action_dispatch/journey/path/pattern.rb +16 -19
- data/lib/action_dispatch/journey/route.rb +8 -19
- data/lib/action_dispatch/journey/router/strexp.rb +9 -6
- data/lib/action_dispatch/journey/router/utils.rb +54 -18
- data/lib/action_dispatch/journey/router.rb +53 -75
- data/lib/action_dispatch/journey/routes.rb +4 -0
- data/lib/action_dispatch/journey/scanner.rb +5 -5
- data/lib/action_dispatch/journey/visitors.rb +81 -60
- data/lib/action_dispatch/journey/visualizer/fsm.css +0 -4
- data/lib/action_dispatch/journey/visualizer/index.html.erb +2 -2
- data/lib/action_dispatch/middleware/callbacks.rb +7 -7
- data/lib/action_dispatch/middleware/cookies.rb +119 -43
- data/lib/action_dispatch/middleware/debug_exceptions.rb +32 -13
- data/lib/action_dispatch/middleware/exception_wrapper.rb +60 -20
- data/lib/action_dispatch/middleware/flash.rb +37 -24
- data/lib/action_dispatch/middleware/params_parser.rb +2 -2
- data/lib/action_dispatch/middleware/public_exceptions.rb +12 -3
- data/lib/action_dispatch/middleware/reloader.rb +11 -2
- data/lib/action_dispatch/middleware/remote_ip.rb +40 -54
- data/lib/action_dispatch/middleware/request_id.rb +1 -1
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +8 -7
- data/lib/action_dispatch/middleware/show_exceptions.rb +6 -2
- data/lib/action_dispatch/middleware/ssl.rb +10 -7
- data/lib/action_dispatch/middleware/static.rb +79 -23
- data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +21 -19
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/{diagnostics.erb → diagnostics.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +6 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/{routing_error.erb → routing_error.html.erb} +3 -1
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
- data/lib/action_dispatch/middleware/templates/rescues/{unknown_action.erb → unknown_action.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +120 -64
- data/lib/action_dispatch/railtie.rb +5 -2
- data/lib/action_dispatch/request/session.rb +12 -0
- data/lib/action_dispatch/request/utils.rb +35 -0
- data/lib/action_dispatch/routing/endpoint.rb +10 -0
- data/lib/action_dispatch/routing/inspector.rb +11 -17
- data/lib/action_dispatch/routing/mapper.rb +519 -312
- data/lib/action_dispatch/routing/polymorphic_routes.rb +204 -79
- data/lib/action_dispatch/routing/redirection.rb +51 -26
- data/lib/action_dispatch/routing/route_set.rb +331 -206
- data/lib/action_dispatch/routing/routes_proxy.rb +5 -4
- data/lib/action_dispatch/routing/url_for.rb +19 -5
- data/lib/action_dispatch/routing.rb +9 -6
- data/lib/action_dispatch/testing/assertions/dom.rb +2 -26
- data/lib/action_dispatch/testing/assertions/response.rb +9 -15
- data/lib/action_dispatch/testing/assertions/routing.rb +22 -22
- data/lib/action_dispatch/testing/assertions/selector.rb +2 -429
- data/lib/action_dispatch/testing/assertions/tag.rb +2 -134
- data/lib/action_dispatch/testing/assertions.rb +11 -7
- data/lib/action_dispatch/testing/integration.rb +31 -29
- data/lib/action_dispatch/testing/test_request.rb +1 -1
- data/lib/action_dispatch/testing/test_response.rb +1 -5
- data/lib/action_dispatch.rb +5 -8
- data/lib/action_pack/gem_version.rb +15 -0
- data/lib/action_pack/version.rb +4 -7
- data/lib/action_pack.rb +1 -1
- metadata +77 -159
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/deprecated/integration_test.rb +0 -5
- data/lib/action_controller/deprecated.rb +0 -7
- data/lib/action_controller/metal/responder.rb +0 -287
- data/lib/action_controller/record_identifier.rb +0 -31
- data/lib/action_controller/vendor/html-scanner.rb +0 -5
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -24
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -7
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -43
- data/lib/action_view/base.rb +0 -201
- data/lib/action_view/buffers.rb +0 -49
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/dependency_tracker.rb +0 -93
- data/lib/action_view/digestor.rb +0 -113
- data/lib/action_view/flows.rb +0 -76
- data/lib/action_view/helpers/active_model_helper.rb +0 -49
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
- data/lib/action_view/helpers/asset_url_helper.rb +0 -355
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
- data/lib/action_view/helpers/cache_helper.rb +0 -196
- data/lib/action_view/helpers/capture_helper.rb +0 -216
- data/lib/action_view/helpers/controller_helper.rb +0 -25
- data/lib/action_view/helpers/csrf_helper.rb +0 -30
- data/lib/action_view/helpers/date_helper.rb +0 -1083
- data/lib/action_view/helpers/debug_helper.rb +0 -39
- data/lib/action_view/helpers/form_helper.rb +0 -1880
- data/lib/action_view/helpers/form_options_helper.rb +0 -838
- data/lib/action_view/helpers/form_tag_helper.rb +0 -785
- data/lib/action_view/helpers/javascript_helper.rb +0 -117
- data/lib/action_view/helpers/number_helper.rb +0 -441
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -106
- data/lib/action_view/helpers/rendering_helper.rb +0 -90
- data/lib/action_view/helpers/sanitize_helper.rb +0 -256
- data/lib/action_view/helpers/tag_helper.rb +0 -173
- data/lib/action_view/helpers/tags/base.rb +0 -148
- data/lib/action_view/helpers/tags/check_box.rb +0 -64
- data/lib/action_view/helpers/tags/checkable.rb +0 -16
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -44
- data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
- data/lib/action_view/helpers/tags/collection_select.rb +0 -28
- data/lib/action_view/helpers/tags/color_field.rb +0 -25
- data/lib/action_view/helpers/tags/date_field.rb +0 -13
- data/lib/action_view/helpers/tags/date_select.rb +0 -72
- data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
- data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
- data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
- data/lib/action_view/helpers/tags/email_field.rb +0 -8
- data/lib/action_view/helpers/tags/file_field.rb +0 -8
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
- data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
- data/lib/action_view/helpers/tags/label.rb +0 -66
- data/lib/action_view/helpers/tags/month_field.rb +0 -13
- data/lib/action_view/helpers/tags/number_field.rb +0 -18
- data/lib/action_view/helpers/tags/password_field.rb +0 -12
- data/lib/action_view/helpers/tags/radio_button.rb +0 -31
- data/lib/action_view/helpers/tags/range_field.rb +0 -8
- data/lib/action_view/helpers/tags/search_field.rb +0 -24
- data/lib/action_view/helpers/tags/select.rb +0 -40
- data/lib/action_view/helpers/tags/tel_field.rb +0 -8
- data/lib/action_view/helpers/tags/text_area.rb +0 -18
- data/lib/action_view/helpers/tags/text_field.rb +0 -29
- data/lib/action_view/helpers/tags/time_field.rb +0 -13
- data/lib/action_view/helpers/tags/time_select.rb +0 -8
- data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
- data/lib/action_view/helpers/tags/url_field.rb +0 -8
- data/lib/action_view/helpers/tags/week_field.rb +0 -13
- data/lib/action_view/helpers/tags.rb +0 -39
- data/lib/action_view/helpers/text_helper.rb +0 -443
- data/lib/action_view/helpers/translation_helper.rb +0 -107
- data/lib/action_view/helpers/url_helper.rb +0 -635
- data/lib/action_view/helpers.rb +0 -58
- data/lib/action_view/locale/en.yml +0 -56
- data/lib/action_view/log_subscriber.rb +0 -30
- data/lib/action_view/lookup_context.rb +0 -241
- data/lib/action_view/model_naming.rb +0 -12
- data/lib/action_view/path_set.rb +0 -77
- data/lib/action_view/railtie.rb +0 -43
- data/lib/action_view/record_identifier.rb +0 -84
- data/lib/action_view/renderer/abstract_renderer.rb +0 -47
- data/lib/action_view/renderer/partial_renderer.rb +0 -492
- data/lib/action_view/renderer/renderer.rb +0 -50
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
- data/lib/action_view/renderer/template_renderer.rb +0 -96
- data/lib/action_view/routing_url_for.rb +0 -107
- data/lib/action_view/tasks/dependencies.rake +0 -17
- data/lib/action_view/template/error.rb +0 -138
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -146
- data/lib/action_view/template/handlers/raw.rb +0 -11
- data/lib/action_view/template/handlers.rb +0 -53
- data/lib/action_view/template/resolver.rb +0 -326
- data/lib/action_view/template/text.rb +0 -34
- data/lib/action_view/template/types.rb +0 -57
- data/lib/action_view/template.rb +0 -339
- data/lib/action_view/test_case.rb +0 -270
- data/lib/action_view/testing/resolvers.rb +0 -50
- data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
- data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
- data/lib/action_view/vendor/html-scanner.rb +0 -20
- data/lib/action_view.rb +0 -93
@@ -1,326 +0,0 @@
|
|
1
|
-
require "pathname"
|
2
|
-
require "active_support/core_ext/class"
|
3
|
-
require "active_support/core_ext/class/attribute_accessors"
|
4
|
-
require "action_view/template"
|
5
|
-
require "thread"
|
6
|
-
require "thread_safe"
|
7
|
-
|
8
|
-
module ActionView
|
9
|
-
# = Action View Resolver
|
10
|
-
class Resolver
|
11
|
-
# Keeps all information about view path and builds virtual path.
|
12
|
-
class Path
|
13
|
-
attr_reader :name, :prefix, :partial, :virtual
|
14
|
-
alias_method :partial?, :partial
|
15
|
-
|
16
|
-
def self.build(name, prefix, partial)
|
17
|
-
virtual = ""
|
18
|
-
virtual << "#{prefix}/" unless prefix.empty?
|
19
|
-
virtual << (partial ? "_#{name}" : name)
|
20
|
-
new name, prefix, partial, virtual
|
21
|
-
end
|
22
|
-
|
23
|
-
def initialize(name, prefix, partial, virtual)
|
24
|
-
@name = name
|
25
|
-
@prefix = prefix
|
26
|
-
@partial = partial
|
27
|
-
@virtual = virtual
|
28
|
-
end
|
29
|
-
|
30
|
-
def to_str
|
31
|
-
@virtual
|
32
|
-
end
|
33
|
-
alias :to_s :to_str
|
34
|
-
end
|
35
|
-
|
36
|
-
# Threadsafe template cache
|
37
|
-
class Cache #:nodoc:
|
38
|
-
class SmallCache < ThreadSafe::Cache
|
39
|
-
def initialize(options = {})
|
40
|
-
super(options.merge(:initial_capacity => 2))
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# preallocate all the default blocks for performance/memory consumption reasons
|
45
|
-
PARTIAL_BLOCK = lambda {|cache, partial| cache[partial] = SmallCache.new}
|
46
|
-
PREFIX_BLOCK = lambda {|cache, prefix| cache[prefix] = SmallCache.new(&PARTIAL_BLOCK)}
|
47
|
-
NAME_BLOCK = lambda {|cache, name| cache[name] = SmallCache.new(&PREFIX_BLOCK)}
|
48
|
-
KEY_BLOCK = lambda {|cache, key| cache[key] = SmallCache.new(&NAME_BLOCK)}
|
49
|
-
|
50
|
-
# usually a majority of template look ups return nothing, use this canonical preallocated array to save memory
|
51
|
-
NO_TEMPLATES = [].freeze
|
52
|
-
|
53
|
-
def initialize
|
54
|
-
@data = SmallCache.new(&KEY_BLOCK)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Cache the templates returned by the block
|
58
|
-
def cache(key, name, prefix, partial, locals)
|
59
|
-
if Resolver.caching?
|
60
|
-
@data[key][name][prefix][partial][locals] ||= canonical_no_templates(yield)
|
61
|
-
else
|
62
|
-
fresh_templates = yield
|
63
|
-
cached_templates = @data[key][name][prefix][partial][locals]
|
64
|
-
|
65
|
-
if templates_have_changed?(cached_templates, fresh_templates)
|
66
|
-
@data[key][name][prefix][partial][locals] = canonical_no_templates(fresh_templates)
|
67
|
-
else
|
68
|
-
cached_templates || NO_TEMPLATES
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def clear
|
74
|
-
@data.clear
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def canonical_no_templates(templates)
|
80
|
-
templates.empty? ? NO_TEMPLATES : templates
|
81
|
-
end
|
82
|
-
|
83
|
-
def templates_have_changed?(cached_templates, fresh_templates)
|
84
|
-
# if either the old or new template list is empty, we don't need to (and can't)
|
85
|
-
# compare modification times, and instead just check whether the lists are different
|
86
|
-
if cached_templates.blank? || fresh_templates.blank?
|
87
|
-
return fresh_templates.blank? != cached_templates.blank?
|
88
|
-
end
|
89
|
-
|
90
|
-
cached_templates_max_updated_at = cached_templates.map(&:updated_at).max
|
91
|
-
|
92
|
-
# if a template has changed, it will be now be newer than all the cached templates
|
93
|
-
fresh_templates.any? { |t| t.updated_at > cached_templates_max_updated_at }
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
cattr_accessor :caching
|
98
|
-
self.caching = true
|
99
|
-
|
100
|
-
class << self
|
101
|
-
alias :caching? :caching
|
102
|
-
end
|
103
|
-
|
104
|
-
def initialize
|
105
|
-
@cache = Cache.new
|
106
|
-
end
|
107
|
-
|
108
|
-
def clear_cache
|
109
|
-
@cache.clear
|
110
|
-
end
|
111
|
-
|
112
|
-
# Normalizes the arguments and passes it on to find_templates.
|
113
|
-
def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
|
114
|
-
cached(key, [name, prefix, partial], details, locals) do
|
115
|
-
find_templates(name, prefix, partial, details)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
delegate :caching?, to: :class
|
122
|
-
|
123
|
-
# This is what child classes implement. No defaults are needed
|
124
|
-
# because Resolver guarantees that the arguments are present and
|
125
|
-
# normalized.
|
126
|
-
def find_templates(name, prefix, partial, details)
|
127
|
-
raise NotImplementedError, "Subclasses must implement a find_templates(name, prefix, partial, details) method"
|
128
|
-
end
|
129
|
-
|
130
|
-
# Helpers that builds a path. Useful for building virtual paths.
|
131
|
-
def build_path(name, prefix, partial)
|
132
|
-
Path.build(name, prefix, partial)
|
133
|
-
end
|
134
|
-
|
135
|
-
# Handles templates caching. If a key is given and caching is on
|
136
|
-
# always check the cache before hitting the resolver. Otherwise,
|
137
|
-
# it always hits the resolver but if the key is present, check if the
|
138
|
-
# resolver is fresher before returning it.
|
139
|
-
def cached(key, path_info, details, locals) #:nodoc:
|
140
|
-
name, prefix, partial = path_info
|
141
|
-
locals = locals.map { |x| x.to_s }.sort!
|
142
|
-
|
143
|
-
if key
|
144
|
-
@cache.cache(key, name, prefix, partial, locals) do
|
145
|
-
decorate(yield, path_info, details, locals)
|
146
|
-
end
|
147
|
-
else
|
148
|
-
decorate(yield, path_info, details, locals)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
# Ensures all the resolver information is set in the template.
|
153
|
-
def decorate(templates, path_info, details, locals) #:nodoc:
|
154
|
-
cached = nil
|
155
|
-
templates.each do |t|
|
156
|
-
t.locals = locals
|
157
|
-
t.formats = details[:formats] || [:html] if t.formats.empty?
|
158
|
-
t.virtual_path ||= (cached ||= build_path(*path_info))
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
# An abstract class that implements a Resolver with path semantics.
|
164
|
-
class PathResolver < Resolver #:nodoc:
|
165
|
-
EXTENSIONS = [:locale, :formats, :handlers]
|
166
|
-
DEFAULT_PATTERN = ":prefix/:action{.:locale,}{.:formats,}{.:handlers,}"
|
167
|
-
|
168
|
-
def initialize(pattern=nil)
|
169
|
-
@pattern = pattern || DEFAULT_PATTERN
|
170
|
-
super()
|
171
|
-
end
|
172
|
-
|
173
|
-
private
|
174
|
-
|
175
|
-
def find_templates(name, prefix, partial, details)
|
176
|
-
path = Path.build(name, prefix, partial)
|
177
|
-
query(path, details, details[:formats])
|
178
|
-
end
|
179
|
-
|
180
|
-
def query(path, details, formats)
|
181
|
-
query = build_query(path, details)
|
182
|
-
|
183
|
-
# deals with case-insensitive file systems.
|
184
|
-
sanitizer = Hash.new { |h,dir| h[dir] = Dir["#{dir}/*"] }
|
185
|
-
|
186
|
-
template_paths = Dir[query].reject { |filename|
|
187
|
-
File.directory?(filename) ||
|
188
|
-
!sanitizer[File.dirname(filename)].include?(filename)
|
189
|
-
}
|
190
|
-
|
191
|
-
template_paths.map { |template|
|
192
|
-
handler, format = extract_handler_and_format(template, formats)
|
193
|
-
contents = File.binread template
|
194
|
-
|
195
|
-
Template.new(contents, File.expand_path(template), handler,
|
196
|
-
:virtual_path => path.virtual,
|
197
|
-
:format => format,
|
198
|
-
:updated_at => mtime(template))
|
199
|
-
}
|
200
|
-
end
|
201
|
-
|
202
|
-
# Helper for building query glob string based on resolver's pattern.
|
203
|
-
def build_query(path, details)
|
204
|
-
query = @pattern.dup
|
205
|
-
|
206
|
-
prefix = path.prefix.empty? ? "" : "#{escape_entry(path.prefix)}\\1"
|
207
|
-
query.gsub!(/\:prefix(\/)?/, prefix)
|
208
|
-
|
209
|
-
partial = escape_entry(path.partial? ? "_#{path.name}" : path.name)
|
210
|
-
query.gsub!(/\:action/, partial)
|
211
|
-
|
212
|
-
details.each do |ext, variants|
|
213
|
-
query.gsub!(/\:#{ext}/, "{#{variants.compact.uniq.join(',')}}")
|
214
|
-
end
|
215
|
-
|
216
|
-
File.expand_path(query, @path)
|
217
|
-
end
|
218
|
-
|
219
|
-
def escape_entry(entry)
|
220
|
-
entry.gsub(/[*?{}\[\]]/, '\\\\\\&')
|
221
|
-
end
|
222
|
-
|
223
|
-
# Returns the file mtime from the filesystem.
|
224
|
-
def mtime(p)
|
225
|
-
File.mtime(p)
|
226
|
-
end
|
227
|
-
|
228
|
-
# Extract handler and formats from path. If a format cannot be a found neither
|
229
|
-
# from the path, or the handler, we should return the array of formats given
|
230
|
-
# to the resolver.
|
231
|
-
def extract_handler_and_format(path, default_formats)
|
232
|
-
pieces = File.basename(path).split(".")
|
233
|
-
pieces.shift
|
234
|
-
|
235
|
-
extension = pieces.pop
|
236
|
-
unless extension
|
237
|
-
message = "The file #{path} did not specify a template handler. The default is currently ERB, " \
|
238
|
-
"but will change to RAW in the future."
|
239
|
-
ActiveSupport::Deprecation.warn message
|
240
|
-
end
|
241
|
-
|
242
|
-
handler = Template.handler_for_extension(extension)
|
243
|
-
format = pieces.last && Template::Types[pieces.last]
|
244
|
-
[handler, format]
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
# A resolver that loads files from the filesystem. It allows setting your own
|
249
|
-
# resolving pattern. Such pattern can be a glob string supported by some variables.
|
250
|
-
#
|
251
|
-
# ==== Examples
|
252
|
-
#
|
253
|
-
# Default pattern, loads views the same way as previous versions of rails, eg. when you're
|
254
|
-
# looking for `users/new` it will produce query glob: `users/new{.{en},}{.{html,js},}{.{erb,haml},}`
|
255
|
-
#
|
256
|
-
# FileSystemResolver.new("/path/to/views", ":prefix/:action{.:locale,}{.:formats,}{.:handlers,}")
|
257
|
-
#
|
258
|
-
# This one allows you to keep files with different formats in separate subdirectories,
|
259
|
-
# eg. `users/new.html` will be loaded from `users/html/new.erb` or `users/new.html.erb`,
|
260
|
-
# `users/new.js` from `users/js/new.erb` or `users/new.js.erb`, etc.
|
261
|
-
#
|
262
|
-
# FileSystemResolver.new("/path/to/views", ":prefix/{:formats/,}:action{.:locale,}{.:formats,}{.:handlers,}")
|
263
|
-
#
|
264
|
-
# If you don't specify a pattern then the default will be used.
|
265
|
-
#
|
266
|
-
# In order to use any of the customized resolvers above in a Rails application, you just need
|
267
|
-
# to configure ActionController::Base.view_paths in an initializer, for example:
|
268
|
-
#
|
269
|
-
# ActionController::Base.view_paths = FileSystemResolver.new(
|
270
|
-
# Rails.root.join("app/views"),
|
271
|
-
# ":prefix{/:locale}/:action{.:formats,}{.:handlers,}"
|
272
|
-
# )
|
273
|
-
#
|
274
|
-
# ==== Pattern format and variables
|
275
|
-
#
|
276
|
-
# Pattern has to be a valid glob string, and it allows you to use the
|
277
|
-
# following variables:
|
278
|
-
#
|
279
|
-
# * <tt>:prefix</tt> - usually the controller path
|
280
|
-
# * <tt>:action</tt> - name of the action
|
281
|
-
# * <tt>:locale</tt> - possible locale versions
|
282
|
-
# * <tt>:formats</tt> - possible request formats (for example html, json, xml...)
|
283
|
-
# * <tt>:handlers</tt> - possible handlers (for example erb, haml, builder...)
|
284
|
-
#
|
285
|
-
class FileSystemResolver < PathResolver
|
286
|
-
def initialize(path, pattern=nil)
|
287
|
-
raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
|
288
|
-
super(pattern)
|
289
|
-
@path = File.expand_path(path)
|
290
|
-
end
|
291
|
-
|
292
|
-
def to_s
|
293
|
-
@path.to_s
|
294
|
-
end
|
295
|
-
alias :to_path :to_s
|
296
|
-
|
297
|
-
def eql?(resolver)
|
298
|
-
self.class.equal?(resolver.class) && to_path == resolver.to_path
|
299
|
-
end
|
300
|
-
alias :== :eql?
|
301
|
-
end
|
302
|
-
|
303
|
-
# An Optimized resolver for Rails' most common case.
|
304
|
-
class OptimizedFileSystemResolver < FileSystemResolver #:nodoc:
|
305
|
-
def build_query(path, details)
|
306
|
-
exts = EXTENSIONS.map { |ext| details[ext] }
|
307
|
-
query = escape_entry(File.join(@path, path))
|
308
|
-
|
309
|
-
query + exts.map { |ext|
|
310
|
-
"{#{ext.compact.uniq.map { |e| ".#{e}," }.join}}"
|
311
|
-
}.join
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
# The same as FileSystemResolver but does not allow templates to store
|
316
|
-
# a virtual path since it is invalid for such resolvers.
|
317
|
-
class FallbackFileSystemResolver < FileSystemResolver #:nodoc:
|
318
|
-
def self.instances
|
319
|
-
[new(""), new("/")]
|
320
|
-
end
|
321
|
-
|
322
|
-
def decorate(*)
|
323
|
-
super.each { |t| t.virtual_path = nil }
|
324
|
-
end
|
325
|
-
end
|
326
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module ActionView #:nodoc:
|
2
|
-
# = Action View Text Template
|
3
|
-
class Template
|
4
|
-
class Text #:nodoc:
|
5
|
-
attr_accessor :type
|
6
|
-
|
7
|
-
def initialize(string, type = nil)
|
8
|
-
@string = string.to_s
|
9
|
-
@type = Types[type] || type if type
|
10
|
-
@type ||= Types[:text]
|
11
|
-
end
|
12
|
-
|
13
|
-
def identifier
|
14
|
-
'text template'
|
15
|
-
end
|
16
|
-
|
17
|
-
def inspect
|
18
|
-
'text template'
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_str
|
22
|
-
@string
|
23
|
-
end
|
24
|
-
|
25
|
-
def render(*args)
|
26
|
-
to_str
|
27
|
-
end
|
28
|
-
|
29
|
-
def formats
|
30
|
-
[@type.to_sym]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'active_support/core_ext/class/attribute_accessors'
|
3
|
-
|
4
|
-
module ActionView
|
5
|
-
class Template
|
6
|
-
class Types
|
7
|
-
class Type
|
8
|
-
cattr_accessor :types
|
9
|
-
self.types = Set.new
|
10
|
-
|
11
|
-
def self.register(*t)
|
12
|
-
types.merge(t.map { |type| type.to_s })
|
13
|
-
end
|
14
|
-
|
15
|
-
register :html, :text, :js, :css, :xml, :json
|
16
|
-
|
17
|
-
def self.[](type)
|
18
|
-
return type if type.is_a?(self)
|
19
|
-
|
20
|
-
if type.is_a?(Symbol) || types.member?(type.to_s)
|
21
|
-
new(type)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
attr_reader :symbol
|
26
|
-
|
27
|
-
def initialize(symbol)
|
28
|
-
@symbol = symbol.to_sym
|
29
|
-
end
|
30
|
-
|
31
|
-
delegate :to_s, :to_sym, :to => :symbol
|
32
|
-
alias to_str to_s
|
33
|
-
|
34
|
-
def ref
|
35
|
-
to_sym || to_s
|
36
|
-
end
|
37
|
-
|
38
|
-
def ==(type)
|
39
|
-
return false if type.blank?
|
40
|
-
symbol.to_sym == type.to_sym
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
cattr_accessor :type_klass
|
45
|
-
|
46
|
-
def self.delegate_to(klass)
|
47
|
-
self.type_klass = klass
|
48
|
-
end
|
49
|
-
|
50
|
-
delegate_to Type
|
51
|
-
|
52
|
-
def self.[](type)
|
53
|
-
type_klass[type]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|