actionpack 3.2.19 → 4.2.11.3
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 +7 -0
- data/CHANGELOG.md +412 -503
- data/MIT-LICENSE +1 -1
- data/README.rdoc +11 -294
- data/lib/abstract_controller/asset_paths.rb +2 -2
- data/lib/abstract_controller/base.rb +52 -18
- data/lib/abstract_controller/callbacks.rb +87 -89
- data/lib/abstract_controller/collector.rb +17 -3
- data/lib/abstract_controller/helpers.rb +41 -14
- data/lib/abstract_controller/logger.rb +1 -2
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
- data/lib/abstract_controller/rendering.rb +65 -118
- data/lib/abstract_controller/translation.rb +16 -1
- data/lib/abstract_controller/url_for.rb +7 -7
- data/lib/abstract_controller.rb +2 -10
- data/lib/action_controller/base.rb +61 -28
- data/lib/action_controller/caching/fragments.rb +30 -54
- data/lib/action_controller/caching.rb +38 -35
- data/lib/action_controller/log_subscriber.rb +35 -18
- data/lib/action_controller/metal/conditional_get.rb +103 -34
- data/lib/action_controller/metal/data_streaming.rb +20 -26
- data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
- data/lib/action_controller/metal/exceptions.rb +19 -6
- data/lib/action_controller/metal/flash.rb +41 -9
- data/lib/action_controller/metal/force_ssl.rb +70 -12
- data/lib/action_controller/metal/head.rb +30 -7
- data/lib/action_controller/metal/helpers.rb +11 -11
- data/lib/action_controller/metal/hide_actions.rb +0 -1
- data/lib/action_controller/metal/http_authentication.rb +140 -94
- data/lib/action_controller/metal/implicit_render.rb +1 -1
- data/lib/action_controller/metal/instrumentation.rb +11 -7
- data/lib/action_controller/metal/live.rb +328 -0
- data/lib/action_controller/metal/mime_responds.rb +161 -152
- data/lib/action_controller/metal/params_wrapper.rb +126 -81
- data/lib/action_controller/metal/rack_delegation.rb +10 -4
- data/lib/action_controller/metal/redirecting.rb +44 -41
- data/lib/action_controller/metal/renderers.rb +48 -19
- data/lib/action_controller/metal/rendering.rb +46 -11
- data/lib/action_controller/metal/request_forgery_protection.rb +250 -29
- data/lib/action_controller/metal/streaming.rb +30 -38
- data/lib/action_controller/metal/strong_parameters.rb +669 -0
- data/lib/action_controller/metal/testing.rb +12 -18
- data/lib/action_controller/metal/url_for.rb +31 -29
- data/lib/action_controller/metal.rb +31 -40
- data/lib/action_controller/model_naming.rb +12 -0
- data/lib/action_controller/railtie.rb +38 -18
- data/lib/action_controller/railties/helpers.rb +22 -0
- data/lib/action_controller/test_case.rb +359 -173
- data/lib/action_controller.rb +9 -16
- data/lib/action_dispatch/http/cache.rb +64 -11
- data/lib/action_dispatch/http/filter_parameters.rb +20 -10
- data/lib/action_dispatch/http/filter_redirect.rb +38 -0
- data/lib/action_dispatch/http/headers.rb +85 -17
- data/lib/action_dispatch/http/mime_negotiation.rb +55 -5
- data/lib/action_dispatch/http/mime_type.rb +167 -114
- data/lib/action_dispatch/http/mime_types.rb +2 -1
- data/lib/action_dispatch/http/parameter_filter.rb +44 -46
- data/lib/action_dispatch/http/parameters.rb +30 -46
- data/lib/action_dispatch/http/rack_cache.rb +2 -3
- data/lib/action_dispatch/http/request.rb +108 -45
- data/lib/action_dispatch/http/response.rb +247 -48
- data/lib/action_dispatch/http/upload.rb +60 -29
- data/lib/action_dispatch/http/url.rb +135 -45
- data/lib/action_dispatch/journey/backwards.rb +5 -0
- data/lib/action_dispatch/journey/formatter.rb +166 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +162 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +47 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +157 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +76 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +163 -0
- data/lib/action_dispatch/journey/nodes/node.rb +128 -0
- data/lib/action_dispatch/journey/parser.rb +198 -0
- data/lib/action_dispatch/journey/parser.y +49 -0
- data/lib/action_dispatch/journey/parser_extras.rb +23 -0
- data/lib/action_dispatch/journey/path/pattern.rb +193 -0
- data/lib/action_dispatch/journey/route.rb +125 -0
- data/lib/action_dispatch/journey/router/strexp.rb +27 -0
- data/lib/action_dispatch/journey/router/utils.rb +93 -0
- data/lib/action_dispatch/journey/router.rb +144 -0
- data/lib/action_dispatch/journey/routes.rb +80 -0
- data/lib/action_dispatch/journey/scanner.rb +61 -0
- data/lib/action_dispatch/journey/visitors.rb +221 -0
- data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
- data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
- data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
- data/lib/action_dispatch/journey.rb +5 -0
- data/lib/action_dispatch/middleware/callbacks.rb +16 -11
- data/lib/action_dispatch/middleware/cookies.rb +346 -125
- data/lib/action_dispatch/middleware/debug_exceptions.rb +52 -24
- data/lib/action_dispatch/middleware/exception_wrapper.rb +75 -9
- data/lib/action_dispatch/middleware/flash.rb +85 -72
- data/lib/action_dispatch/middleware/params_parser.rb +16 -31
- data/lib/action_dispatch/middleware/public_exceptions.rb +39 -14
- data/lib/action_dispatch/middleware/reloader.rb +16 -7
- data/lib/action_dispatch/middleware/remote_ip.rb +132 -40
- data/lib/action_dispatch/middleware/request_id.rb +3 -7
- data/lib/action_dispatch/middleware/session/abstract_store.rb +22 -20
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +84 -29
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +15 -44
- data/lib/action_dispatch/middleware/ssl.rb +72 -0
- data/lib/action_dispatch/middleware/stack.rb +6 -1
- data/lib/action_dispatch/middleware/static.rb +80 -23
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +34 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +27 -0
- 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.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +133 -5
- 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.html.erb +32 -0
- 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.html.erb +6 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
- data/lib/action_dispatch/railtie.rb +19 -6
- data/lib/action_dispatch/request/session.rb +193 -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 +234 -0
- data/lib/action_dispatch/routing/mapper.rb +897 -436
- data/lib/action_dispatch/routing/polymorphic_routes.rb +213 -92
- data/lib/action_dispatch/routing/redirection.rb +97 -37
- data/lib/action_dispatch/routing/route_set.rb +432 -239
- data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
- data/lib/action_dispatch/routing/url_for.rb +63 -34
- data/lib/action_dispatch/routing.rb +57 -89
- data/lib/action_dispatch/testing/assertions/dom.rb +2 -36
- data/lib/action_dispatch/testing/assertions/response.rb +24 -38
- data/lib/action_dispatch/testing/assertions/routing.rb +55 -54
- data/lib/action_dispatch/testing/assertions/selector.rb +2 -434
- data/lib/action_dispatch/testing/assertions/tag.rb +2 -137
- data/lib/action_dispatch/testing/assertions.rb +11 -7
- data/lib/action_dispatch/testing/integration.rb +88 -72
- data/lib/action_dispatch/testing/test_process.rb +9 -6
- data/lib/action_dispatch/testing/test_request.rb +13 -9
- data/lib/action_dispatch/testing/test_response.rb +1 -5
- data/lib/action_dispatch.rb +24 -21
- data/lib/action_pack/gem_version.rb +15 -0
- data/lib/action_pack/version.rb +5 -7
- data/lib/action_pack.rb +1 -1
- metadata +181 -292
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/caching/actions.rb +0 -185
- data/lib/action_controller/caching/pages.rb +0 -187
- data/lib/action_controller/caching/sweeping.rb +0 -97
- data/lib/action_controller/deprecated/integration_test.rb +0 -2
- data/lib/action_controller/deprecated/performance_test.rb +0 -1
- data/lib/action_controller/deprecated.rb +0 -3
- data/lib/action_controller/metal/compatibility.rb +0 -65
- data/lib/action_controller/metal/responder.rb +0 -286
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/railties/paths.rb +0 -25
- data/lib/action_controller/record_identifier.rb +0 -85
- data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
- data/lib/action_controller/vendor/html-scanner.rb +0 -20
- data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
- data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
- data/lib/action_dispatch/middleware/head.rb +0 -18
- data/lib/action_dispatch/middleware/rescue.rb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
- data/lib/action_dispatch/testing/performance_test.rb +0 -10
- data/lib/action_view/asset_paths.rb +0 -142
- data/lib/action_view/base.rb +0 -220
- data/lib/action_view/buffers.rb +0 -43
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/flows.rb +0 -79
- data/lib/action_view/helpers/active_model_helper.rb +0 -50
- data/lib/action_view/helpers/asset_paths.rb +0 -7
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
- data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
- data/lib/action_view/helpers/cache_helper.rb +0 -64
- data/lib/action_view/helpers/capture_helper.rb +0 -203
- data/lib/action_view/helpers/controller_helper.rb +0 -25
- data/lib/action_view/helpers/csrf_helper.rb +0 -32
- data/lib/action_view/helpers/date_helper.rb +0 -1062
- data/lib/action_view/helpers/debug_helper.rb +0 -40
- data/lib/action_view/helpers/form_helper.rb +0 -1486
- data/lib/action_view/helpers/form_options_helper.rb +0 -658
- data/lib/action_view/helpers/form_tag_helper.rb +0 -685
- data/lib/action_view/helpers/javascript_helper.rb +0 -110
- data/lib/action_view/helpers/number_helper.rb +0 -622
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -111
- data/lib/action_view/helpers/rendering_helper.rb +0 -90
- data/lib/action_view/helpers/sanitize_helper.rb +0 -259
- data/lib/action_view/helpers/tag_helper.rb +0 -160
- data/lib/action_view/helpers/text_helper.rb +0 -426
- data/lib/action_view/helpers/translation_helper.rb +0 -91
- data/lib/action_view/helpers/url_helper.rb +0 -693
- data/lib/action_view/helpers.rb +0 -60
- data/lib/action_view/locale/en.yml +0 -160
- data/lib/action_view/log_subscriber.rb +0 -28
- data/lib/action_view/lookup_context.rb +0 -254
- data/lib/action_view/path_set.rb +0 -89
- data/lib/action_view/railtie.rb +0 -55
- data/lib/action_view/renderer/abstract_renderer.rb +0 -41
- data/lib/action_view/renderer/partial_renderer.rb +0 -415
- data/lib/action_view/renderer/renderer.rb +0 -54
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
- data/lib/action_view/renderer/template_renderer.rb +0 -94
- data/lib/action_view/template/error.rb +0 -128
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -125
- data/lib/action_view/template/handlers.rb +0 -50
- data/lib/action_view/template/resolver.rb +0 -272
- data/lib/action_view/template/text.rb +0 -30
- data/lib/action_view/template.rb +0 -337
- data/lib/action_view/test_case.rb +0 -245
- data/lib/action_view/testing/resolvers.rb +0 -50
- data/lib/action_view.rb +0 -84
- data/lib/sprockets/assets.rake +0 -99
- data/lib/sprockets/bootstrap.rb +0 -37
- data/lib/sprockets/compressors.rb +0 -83
- data/lib/sprockets/helpers/isolated_helper.rb +0 -13
- data/lib/sprockets/helpers/rails_helper.rb +0 -182
- data/lib/sprockets/helpers.rb +0 -6
- data/lib/sprockets/railtie.rb +0 -62
- data/lib/sprockets/static_compiler.rb +0 -56
@@ -1,128 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/array/wrap"
|
2
|
-
require "active_support/core_ext/enumerable"
|
3
|
-
|
4
|
-
module ActionView
|
5
|
-
# = Action View Errors
|
6
|
-
class ActionViewError < StandardError #:nodoc:
|
7
|
-
end
|
8
|
-
|
9
|
-
class EncodingError < StandardError #:nodoc:
|
10
|
-
end
|
11
|
-
|
12
|
-
class WrongEncodingError < EncodingError #:nodoc:
|
13
|
-
def initialize(string, encoding)
|
14
|
-
@string, @encoding = string, encoding
|
15
|
-
end
|
16
|
-
|
17
|
-
def message
|
18
|
-
@string.force_encoding("BINARY")
|
19
|
-
"Your template was not saved as valid #{@encoding}. Please " \
|
20
|
-
"either specify #{@encoding} as the encoding for your template " \
|
21
|
-
"in your text editor, or mark the template with its " \
|
22
|
-
"encoding by inserting the following as the first line " \
|
23
|
-
"of the template:\n\n# encoding: <name of correct encoding>.\n\n" \
|
24
|
-
"The source of your template was:\n\n#{@string}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class MissingTemplate < ActionViewError #:nodoc:
|
29
|
-
attr_reader :path
|
30
|
-
|
31
|
-
def initialize(paths, path, prefixes, partial, details, *)
|
32
|
-
@path = path
|
33
|
-
prefixes = Array.wrap(prefixes)
|
34
|
-
template_type = if partial
|
35
|
-
"partial"
|
36
|
-
elsif path =~ /layouts/i
|
37
|
-
'layout'
|
38
|
-
else
|
39
|
-
'template'
|
40
|
-
end
|
41
|
-
|
42
|
-
searched_paths = prefixes.map { |prefix| [prefix, path].join("/") }
|
43
|
-
|
44
|
-
out = "Missing #{template_type} #{searched_paths.join(", ")} with #{details.inspect}. Searched in:\n"
|
45
|
-
out += paths.compact.map { |p| " * #{p.to_s.inspect}\n" }.join
|
46
|
-
super out
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class Template
|
51
|
-
# The Template::Error exception is raised when the compilation or rendering of the template
|
52
|
-
# fails. This exception then gathers a bunch of intimate details and uses it to report a
|
53
|
-
# precise exception message.
|
54
|
-
class Error < ActionViewError #:nodoc:
|
55
|
-
SOURCE_CODE_RADIUS = 3
|
56
|
-
|
57
|
-
attr_reader :original_exception, :backtrace
|
58
|
-
|
59
|
-
def initialize(template, assigns, original_exception)
|
60
|
-
super(original_exception.message)
|
61
|
-
@template, @assigns, @original_exception = template, assigns.dup, original_exception
|
62
|
-
@sub_templates = nil
|
63
|
-
@backtrace = original_exception.backtrace
|
64
|
-
end
|
65
|
-
|
66
|
-
def file_name
|
67
|
-
@template.identifier
|
68
|
-
end
|
69
|
-
|
70
|
-
def sub_template_message
|
71
|
-
if @sub_templates
|
72
|
-
"Trace of template inclusion: " +
|
73
|
-
@sub_templates.collect { |template| template.inspect }.join(", ")
|
74
|
-
else
|
75
|
-
""
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def source_extract(indentation = 0)
|
80
|
-
return unless num = line_number
|
81
|
-
num = num.to_i
|
82
|
-
|
83
|
-
source_code = @template.source.split("\n")
|
84
|
-
|
85
|
-
start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max
|
86
|
-
end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min
|
87
|
-
|
88
|
-
indent = ' ' * indentation
|
89
|
-
line_counter = start_on_line
|
90
|
-
return unless source_code = source_code[start_on_line..end_on_line]
|
91
|
-
|
92
|
-
source_code.sum do |line|
|
93
|
-
line_counter += 1
|
94
|
-
"#{indent}#{line_counter}: #{line}\n"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def sub_template_of(template_path)
|
99
|
-
@sub_templates ||= []
|
100
|
-
@sub_templates << template_path
|
101
|
-
end
|
102
|
-
|
103
|
-
def line_number
|
104
|
-
@line_number ||=
|
105
|
-
if file_name
|
106
|
-
regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/
|
107
|
-
$1 if message =~ regexp || backtrace.find { |line| line =~ regexp }
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def annoted_source_code
|
112
|
-
source_extract(4)
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
|
117
|
-
def source_location
|
118
|
-
if line_number
|
119
|
-
"on line ##{line_number} of "
|
120
|
-
else
|
121
|
-
'in '
|
122
|
-
end + file_name
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
TemplateError = Template::Error
|
128
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module ActionView
|
2
|
-
module Template::Handlers
|
3
|
-
class Builder
|
4
|
-
# Default format used by Builder.
|
5
|
-
class_attribute :default_format
|
6
|
-
self.default_format = Mime::XML
|
7
|
-
|
8
|
-
def call(template)
|
9
|
-
require_engine
|
10
|
-
"xml = ::Builder::XmlMarkup.new(:indent => 2);" +
|
11
|
-
"self.output_buffer = xml.target!;" +
|
12
|
-
template.source +
|
13
|
-
";xml.target!;"
|
14
|
-
end
|
15
|
-
|
16
|
-
protected
|
17
|
-
|
18
|
-
def require_engine
|
19
|
-
@required ||= begin
|
20
|
-
require "builder"
|
21
|
-
true
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,125 +0,0 @@
|
|
1
|
-
require 'action_dispatch/http/mime_type'
|
2
|
-
require 'active_support/core_ext/class/attribute'
|
3
|
-
require 'erubis'
|
4
|
-
|
5
|
-
module ActionView
|
6
|
-
class Template
|
7
|
-
module Handlers
|
8
|
-
class Erubis < ::Erubis::Eruby
|
9
|
-
def add_preamble(src)
|
10
|
-
src << "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_text(src, text)
|
14
|
-
return if text.empty?
|
15
|
-
src << "@output_buffer.safe_concat('" << escape_text(text) << "');"
|
16
|
-
end
|
17
|
-
|
18
|
-
# Erubis toggles <%= and <%== behavior when escaping is enabled.
|
19
|
-
# We override to always treat <%== as escaped.
|
20
|
-
def add_expr(src, code, indicator)
|
21
|
-
case indicator
|
22
|
-
when '=='
|
23
|
-
add_expr_escaped(src, code)
|
24
|
-
else
|
25
|
-
super
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
|
30
|
-
|
31
|
-
def add_expr_literal(src, code)
|
32
|
-
if code =~ BLOCK_EXPR
|
33
|
-
src << '@output_buffer.append= ' << code
|
34
|
-
else
|
35
|
-
src << '@output_buffer.append= (' << code << ');'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def add_expr_escaped(src, code)
|
40
|
-
if code =~ BLOCK_EXPR
|
41
|
-
src << "@output_buffer.safe_append= " << code
|
42
|
-
else
|
43
|
-
src << "@output_buffer.safe_concat((" << code << ").to_s);"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def add_postamble(src)
|
48
|
-
src << '@output_buffer.to_s'
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class ERB
|
53
|
-
# Specify trim mode for the ERB compiler. Defaults to '-'.
|
54
|
-
# See ERB documentation for suitable values.
|
55
|
-
class_attribute :erb_trim_mode
|
56
|
-
self.erb_trim_mode = '-'
|
57
|
-
|
58
|
-
# Default implementation used.
|
59
|
-
class_attribute :erb_implementation
|
60
|
-
self.erb_implementation = Erubis
|
61
|
-
|
62
|
-
# Do not escape templates of these mime types.
|
63
|
-
class_attribute :escape_whitelist
|
64
|
-
self.escape_whitelist = ["text/plain"]
|
65
|
-
|
66
|
-
ENCODING_TAG = Regexp.new("\\A(<%#{ENCODING_FLAG}-?%>)[ \\t]*")
|
67
|
-
|
68
|
-
def self.call(template)
|
69
|
-
new.call(template)
|
70
|
-
end
|
71
|
-
|
72
|
-
def supports_streaming?
|
73
|
-
true
|
74
|
-
end
|
75
|
-
|
76
|
-
def handles_encoding?
|
77
|
-
true
|
78
|
-
end
|
79
|
-
|
80
|
-
def call(template)
|
81
|
-
if template.source.encoding_aware?
|
82
|
-
# First, convert to BINARY, so in case the encoding is
|
83
|
-
# wrong, we can still find an encoding tag
|
84
|
-
# (<%# encoding %>) inside the String using a regular
|
85
|
-
# expression
|
86
|
-
template_source = template.source.dup.force_encoding("BINARY")
|
87
|
-
|
88
|
-
erb = template_source.gsub(ENCODING_TAG, '')
|
89
|
-
encoding = $2
|
90
|
-
|
91
|
-
erb.force_encoding valid_encoding(template.source.dup, encoding)
|
92
|
-
|
93
|
-
# Always make sure we return a String in the default_internal
|
94
|
-
erb.encode!
|
95
|
-
else
|
96
|
-
erb = template.source.dup
|
97
|
-
end
|
98
|
-
|
99
|
-
self.class.erb_implementation.new(
|
100
|
-
erb,
|
101
|
-
:escape => (self.class.escape_whitelist.include? template.mime_type),
|
102
|
-
:trim => (self.class.erb_trim_mode == "-")
|
103
|
-
).src
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
|
108
|
-
def valid_encoding(string, encoding)
|
109
|
-
# If a magic encoding comment was found, tag the
|
110
|
-
# String with this encoding. This is for a case
|
111
|
-
# where the original String was assumed to be,
|
112
|
-
# for instance, UTF-8, but a magic comment
|
113
|
-
# proved otherwise
|
114
|
-
string.force_encoding(encoding) if encoding
|
115
|
-
|
116
|
-
# If the String is valid, return the encoding we found
|
117
|
-
return string.encoding if string.valid_encoding?
|
118
|
-
|
119
|
-
# Otherwise, raise an exception
|
120
|
-
raise WrongEncodingError.new(string, string.encoding)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module ActionView #:nodoc:
|
2
|
-
# = Action View Template Handlers
|
3
|
-
class Template
|
4
|
-
module Handlers #:nodoc:
|
5
|
-
autoload :ERB, 'action_view/template/handlers/erb'
|
6
|
-
autoload :Builder, 'action_view/template/handlers/builder'
|
7
|
-
|
8
|
-
def self.extended(base)
|
9
|
-
base.register_default_template_handler :erb, ERB.new
|
10
|
-
base.register_template_handler :builder, Builder.new
|
11
|
-
end
|
12
|
-
|
13
|
-
@@template_handlers = {}
|
14
|
-
@@default_template_handlers = nil
|
15
|
-
|
16
|
-
def self.extensions
|
17
|
-
@@template_extensions ||= @@template_handlers.keys
|
18
|
-
end
|
19
|
-
|
20
|
-
# Register a class that knows how to handle template files with the given
|
21
|
-
# extension. This can be used to implement new template types.
|
22
|
-
# The constructor for the class must take the ActiveView::Base instance
|
23
|
-
# as a parameter, and the class must implement a +render+ method that
|
24
|
-
# takes the contents of the template to render as well as the Hash of
|
25
|
-
# local assigns available to the template. The +render+ method ought to
|
26
|
-
# return the rendered template as a string.
|
27
|
-
def register_template_handler(extension, klass)
|
28
|
-
@@template_handlers[extension.to_sym] = klass
|
29
|
-
@@template_extensions = nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def template_handler_extensions
|
33
|
-
@@template_handlers.keys.map {|key| key.to_s }.sort
|
34
|
-
end
|
35
|
-
|
36
|
-
def registered_template_handler(extension)
|
37
|
-
extension && @@template_handlers[extension.to_sym]
|
38
|
-
end
|
39
|
-
|
40
|
-
def register_default_template_handler(extension, klass)
|
41
|
-
register_template_handler(extension, klass)
|
42
|
-
@@default_template_handlers = klass
|
43
|
-
end
|
44
|
-
|
45
|
-
def handler_for_extension(extension)
|
46
|
-
registered_template_handler(extension) || @@default_template_handlers
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,272 +0,0 @@
|
|
1
|
-
require "pathname"
|
2
|
-
require "active_support/core_ext/class"
|
3
|
-
require "active_support/core_ext/io"
|
4
|
-
require "action_view/template"
|
5
|
-
|
6
|
-
module ActionView
|
7
|
-
# = Action View Resolver
|
8
|
-
class Resolver
|
9
|
-
# Keeps all information about view path and builds virtual path.
|
10
|
-
class Path < String
|
11
|
-
attr_reader :name, :prefix, :partial, :virtual
|
12
|
-
alias_method :partial?, :partial
|
13
|
-
|
14
|
-
def self.build(name, prefix, partial)
|
15
|
-
virtual = ""
|
16
|
-
virtual << "#{prefix}/" unless prefix.empty?
|
17
|
-
virtual << (partial ? "_#{name}" : name)
|
18
|
-
new name, prefix, partial, virtual
|
19
|
-
end
|
20
|
-
|
21
|
-
def initialize(name, prefix, partial, virtual)
|
22
|
-
@name, @prefix, @partial = name, prefix, partial
|
23
|
-
super(virtual)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
cattr_accessor :caching
|
28
|
-
self.caching = true
|
29
|
-
|
30
|
-
class << self
|
31
|
-
alias :caching? :caching
|
32
|
-
end
|
33
|
-
|
34
|
-
def initialize
|
35
|
-
@cached = Hash.new { |h1,k1| h1[k1] = Hash.new { |h2,k2|
|
36
|
-
h2[k2] = Hash.new { |h3,k3| h3[k3] = Hash.new { |h4,k4| h4[k4] = {} } } } }
|
37
|
-
end
|
38
|
-
|
39
|
-
def clear_cache
|
40
|
-
@cached.clear
|
41
|
-
end
|
42
|
-
|
43
|
-
# Normalizes the arguments and passes it on to find_template.
|
44
|
-
def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
|
45
|
-
cached(key, [name, prefix, partial], details, locals) do
|
46
|
-
find_templates(name, prefix, partial, details)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
delegate :caching?, :to => "self.class"
|
53
|
-
|
54
|
-
# This is what child classes implement. No defaults are needed
|
55
|
-
# because Resolver guarantees that the arguments are present and
|
56
|
-
# normalized.
|
57
|
-
def find_templates(name, prefix, partial, details)
|
58
|
-
raise NotImplementedError, "Subclasses must implement a find_templates(name, prefix, partial, details) method"
|
59
|
-
end
|
60
|
-
|
61
|
-
# Helpers that builds a path. Useful for building virtual paths.
|
62
|
-
def build_path(name, prefix, partial)
|
63
|
-
Path.build(name, prefix, partial)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Handles templates caching. If a key is given and caching is on
|
67
|
-
# always check the cache before hitting the resolver. Otherwise,
|
68
|
-
# it always hits the resolver but check if the resolver is fresher
|
69
|
-
# before returning it.
|
70
|
-
def cached(key, path_info, details, locals) #:nodoc:
|
71
|
-
name, prefix, partial = path_info
|
72
|
-
locals = locals.map { |x| x.to_s }.sort!
|
73
|
-
|
74
|
-
if key && caching?
|
75
|
-
@cached[key][name][prefix][partial][locals] ||= decorate(yield, path_info, details, locals)
|
76
|
-
else
|
77
|
-
fresh = decorate(yield, path_info, details, locals)
|
78
|
-
return fresh unless key
|
79
|
-
|
80
|
-
scope = @cached[key][name][prefix][partial]
|
81
|
-
cache = scope[locals]
|
82
|
-
mtime = cache && cache.map(&:updated_at).max
|
83
|
-
|
84
|
-
if !mtime || fresh.empty? || fresh.any? { |t| t.updated_at > mtime }
|
85
|
-
scope[locals] = fresh
|
86
|
-
else
|
87
|
-
cache
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Ensures all the resolver information is set in the template.
|
93
|
-
def decorate(templates, path_info, details, locals) #:nodoc:
|
94
|
-
cached = nil
|
95
|
-
templates.each do |t|
|
96
|
-
t.locals = locals
|
97
|
-
t.formats = details[:formats] || [:html] if t.formats.empty?
|
98
|
-
t.virtual_path ||= (cached ||= build_path(*path_info))
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# An abstract class that implements a Resolver with path semantics.
|
104
|
-
class PathResolver < Resolver #:nodoc:
|
105
|
-
EXTENSIONS = [:locale, :formats, :handlers]
|
106
|
-
DEFAULT_PATTERN = ":prefix/:action{.:locale,}{.:formats,}{.:handlers,}"
|
107
|
-
|
108
|
-
def initialize(pattern=nil)
|
109
|
-
@pattern = pattern || DEFAULT_PATTERN
|
110
|
-
super()
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
|
115
|
-
def find_templates(name, prefix, partial, details)
|
116
|
-
path = Path.build(name, prefix, partial)
|
117
|
-
query(path, details, details[:formats])
|
118
|
-
end
|
119
|
-
|
120
|
-
def query(path, details, formats)
|
121
|
-
query = build_query(path, details)
|
122
|
-
|
123
|
-
template_paths = find_template_paths query
|
124
|
-
|
125
|
-
template_paths.map { |template|
|
126
|
-
handler, format = extract_handler_and_format(template, formats)
|
127
|
-
contents = File.binread template
|
128
|
-
|
129
|
-
Template.new(contents, File.expand_path(template), handler,
|
130
|
-
:virtual_path => path.virtual,
|
131
|
-
:format => format,
|
132
|
-
:updated_at => mtime(template))
|
133
|
-
}
|
134
|
-
end
|
135
|
-
|
136
|
-
if RUBY_VERSION >= '2.2.0'
|
137
|
-
def find_template_paths(query)
|
138
|
-
Dir[query].reject { |filename|
|
139
|
-
File.directory?(filename) ||
|
140
|
-
# deals with case-insensitive file systems.
|
141
|
-
!File.fnmatch(query, filename, File::FNM_EXTGLOB)
|
142
|
-
}
|
143
|
-
end
|
144
|
-
else
|
145
|
-
def find_template_paths(query)
|
146
|
-
# deals with case-insensitive file systems.
|
147
|
-
sanitizer = Hash.new { |h,dir| h[dir] = Dir["#{dir}/*"] }
|
148
|
-
|
149
|
-
Dir[query].reject { |filename|
|
150
|
-
File.directory?(filename) ||
|
151
|
-
!sanitizer[File.dirname(filename)].include?(filename)
|
152
|
-
}
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
# Helper for building query glob string based on resolver's pattern.
|
157
|
-
def build_query(path, details)
|
158
|
-
query = @pattern.dup
|
159
|
-
|
160
|
-
prefix = path.prefix.empty? ? "" : "#{escape_entry(path.prefix)}\\1"
|
161
|
-
query.gsub!(/\:prefix(\/)?/, prefix)
|
162
|
-
|
163
|
-
partial = escape_entry(path.partial? ? "_#{path.name}" : path.name)
|
164
|
-
query.gsub!(/\:action/, partial)
|
165
|
-
|
166
|
-
details.each do |ext, variants|
|
167
|
-
query.gsub!(/\:#{ext}/, "{#{variants.compact.uniq.join(',')}}")
|
168
|
-
end
|
169
|
-
|
170
|
-
File.expand_path(query, @path)
|
171
|
-
end
|
172
|
-
|
173
|
-
def escape_entry(entry)
|
174
|
-
entry.gsub(/[*?{}\[\]]/, '\\\\\\&')
|
175
|
-
end
|
176
|
-
|
177
|
-
# Returns the file mtime from the filesystem.
|
178
|
-
def mtime(p)
|
179
|
-
File.mtime(p)
|
180
|
-
end
|
181
|
-
|
182
|
-
# Extract handler and formats from path. If a format cannot be a found neither
|
183
|
-
# from the path, or the handler, we should return the array of formats given
|
184
|
-
# to the resolver.
|
185
|
-
def extract_handler_and_format(path, default_formats)
|
186
|
-
pieces = File.basename(path).split(".")
|
187
|
-
pieces.shift
|
188
|
-
handler = Template.handler_for_extension(pieces.pop)
|
189
|
-
format = pieces.last && Mime[pieces.last]
|
190
|
-
[handler, format]
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
# A resolver that loads files from the filesystem. It allows to set your own
|
195
|
-
# resolving pattern. Such pattern can be a glob string supported by some variables.
|
196
|
-
#
|
197
|
-
# ==== Examples
|
198
|
-
#
|
199
|
-
# Default pattern, loads views the same way as previous versions of rails, eg. when you're
|
200
|
-
# looking for `users/new` it will produce query glob: `users/new{.{en},}{.{html,js},}{.{erb,haml},}`
|
201
|
-
#
|
202
|
-
# FileSystemResolver.new("/path/to/views", ":prefix/:action{.:locale,}{.:formats,}{.:handlers,}")
|
203
|
-
#
|
204
|
-
# This one allows you to keep files with different formats in seperated subdirectories,
|
205
|
-
# eg. `users/new.html` will be loaded from `users/html/new.erb` or `users/new.html.erb`,
|
206
|
-
# `users/new.js` from `users/js/new.erb` or `users/new.js.erb`, etc.
|
207
|
-
#
|
208
|
-
# FileSystemResolver.new("/path/to/views", ":prefix/{:formats/,}:action{.:locale,}{.:formats,}{.:handlers,}")
|
209
|
-
#
|
210
|
-
# If you don't specify pattern then the default will be used.
|
211
|
-
#
|
212
|
-
# In order to use any of the customized resolvers above in a Rails application, you just need
|
213
|
-
# to configure ActionController::Base.view_paths in an initializer, for example:
|
214
|
-
#
|
215
|
-
# ActionController::Base.view_paths = FileSystemResolver.new(
|
216
|
-
# Rails.root.join("app/views"),
|
217
|
-
# ":prefix{/:locale}/:action{.:formats,}{.:handlers,}"
|
218
|
-
# )
|
219
|
-
#
|
220
|
-
# ==== Pattern format and variables
|
221
|
-
#
|
222
|
-
# Pattern have to be a valid glob string, and it allows you to use the
|
223
|
-
# following variables:
|
224
|
-
#
|
225
|
-
# * <tt>:prefix</tt> - usualy the controller path
|
226
|
-
# * <tt>:action</tt> - name of the action
|
227
|
-
# * <tt>:locale</tt> - possible locale versions
|
228
|
-
# * <tt>:formats</tt> - possible request formats (for example html, json, xml...)
|
229
|
-
# * <tt>:handlers</tt> - possible handlers (for example erb, haml, builder...)
|
230
|
-
#
|
231
|
-
class FileSystemResolver < PathResolver
|
232
|
-
def initialize(path, pattern=nil)
|
233
|
-
raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
|
234
|
-
super(pattern)
|
235
|
-
@path = File.expand_path(path)
|
236
|
-
end
|
237
|
-
|
238
|
-
def to_s
|
239
|
-
@path.to_s
|
240
|
-
end
|
241
|
-
alias :to_path :to_s
|
242
|
-
|
243
|
-
def eql?(resolver)
|
244
|
-
self.class.equal?(resolver.class) && to_path == resolver.to_path
|
245
|
-
end
|
246
|
-
alias :== :eql?
|
247
|
-
end
|
248
|
-
|
249
|
-
# An Optimized resolver for Rails' most common case.
|
250
|
-
class OptimizedFileSystemResolver < FileSystemResolver #:nodoc:
|
251
|
-
def build_query(path, details)
|
252
|
-
exts = EXTENSIONS.map { |ext| details[ext] }
|
253
|
-
query = escape_entry(File.join(@path, path))
|
254
|
-
|
255
|
-
query + exts.map { |ext|
|
256
|
-
"{#{ext.compact.uniq.map { |e| ".#{e}," }.join}}"
|
257
|
-
}.join
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
# The same as FileSystemResolver but does not allow templates to store
|
262
|
-
# a virtual path since it is invalid for such resolvers.
|
263
|
-
class FallbackFileSystemResolver < FileSystemResolver #:nodoc:
|
264
|
-
def self.instances
|
265
|
-
[new(""), new("/")]
|
266
|
-
end
|
267
|
-
|
268
|
-
def decorate(*)
|
269
|
-
super.each { |t| t.virtual_path = nil }
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module ActionView #:nodoc:
|
2
|
-
# = Action View Text Template
|
3
|
-
class Template
|
4
|
-
class Text < String #:nodoc:
|
5
|
-
attr_accessor :mime_type
|
6
|
-
|
7
|
-
def initialize(string, mime_type = nil)
|
8
|
-
super(string.to_s)
|
9
|
-
@mime_type = Mime[mime_type] || mime_type if mime_type
|
10
|
-
@mime_type ||= Mime::TEXT
|
11
|
-
end
|
12
|
-
|
13
|
-
def identifier
|
14
|
-
'text template'
|
15
|
-
end
|
16
|
-
|
17
|
-
def inspect
|
18
|
-
'text template'
|
19
|
-
end
|
20
|
-
|
21
|
-
def render(*args)
|
22
|
-
to_s
|
23
|
-
end
|
24
|
-
|
25
|
-
def formats
|
26
|
-
[@mime_type.respond_to?(:ref) ? @mime_type.ref : @mime_type.to_s]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|