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,96 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/object/try'
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
class TemplateRenderer < AbstractRenderer #:nodoc:
|
5
|
-
def render(context, options)
|
6
|
-
@view = context
|
7
|
-
@details = extract_details(options)
|
8
|
-
template = determine_template(options)
|
9
|
-
context = @lookup_context
|
10
|
-
|
11
|
-
prepend_formats(template.formats)
|
12
|
-
|
13
|
-
unless context.rendered_format
|
14
|
-
context.rendered_format = template.formats.first || formats.first
|
15
|
-
end
|
16
|
-
|
17
|
-
render_template(template, options[:layout], options[:locals])
|
18
|
-
end
|
19
|
-
|
20
|
-
# Determine the template to be rendered using the given options.
|
21
|
-
def determine_template(options) #:nodoc:
|
22
|
-
keys = options.fetch(:locals, {}).keys
|
23
|
-
|
24
|
-
if options.key?(:text)
|
25
|
-
Template::Text.new(options[:text], formats.first)
|
26
|
-
elsif options.key?(:file)
|
27
|
-
with_fallbacks { find_template(options[:file], nil, false, keys, @details) }
|
28
|
-
elsif options.key?(:inline)
|
29
|
-
handler = Template.handler_for_extension(options[:type] || "erb")
|
30
|
-
Template.new(options[:inline], "inline template", handler, :locals => keys)
|
31
|
-
elsif options.key?(:template)
|
32
|
-
if options[:template].respond_to?(:render)
|
33
|
-
options[:template]
|
34
|
-
else
|
35
|
-
find_template(options[:template], options[:prefixes], false, keys, @details)
|
36
|
-
end
|
37
|
-
else
|
38
|
-
raise ArgumentError, "You invoked render but did not give any of :partial, :template, :inline, :file or :text option."
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Renders the given template. A string representing the layout can be
|
43
|
-
# supplied as well.
|
44
|
-
def render_template(template, layout_name = nil, locals = nil) #:nodoc:
|
45
|
-
view, locals = @view, locals || {}
|
46
|
-
|
47
|
-
render_with_layout(layout_name, locals) do |layout|
|
48
|
-
instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
|
49
|
-
template.render(view, locals) { |*name| view._layout_for(*name) }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def render_with_layout(path, locals) #:nodoc:
|
55
|
-
layout = path && find_layout(path, locals.keys)
|
56
|
-
content = yield(layout)
|
57
|
-
|
58
|
-
if layout
|
59
|
-
view = @view
|
60
|
-
view.view_flow.set(:layout, content)
|
61
|
-
layout.render(view, locals){ |*name| view._layout_for(*name) }
|
62
|
-
else
|
63
|
-
content
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# This is the method which actually finds the layout using details in the lookup
|
68
|
-
# context object. If no layout is found, it checks if at least a layout with
|
69
|
-
# the given name exists across all details before raising the error.
|
70
|
-
def find_layout(layout, keys)
|
71
|
-
with_layout_format { resolve_layout(layout, keys) }
|
72
|
-
end
|
73
|
-
|
74
|
-
def resolve_layout(layout, keys)
|
75
|
-
case layout
|
76
|
-
when String
|
77
|
-
begin
|
78
|
-
if layout =~ /^\//
|
79
|
-
with_fallbacks { find_template(layout, nil, false, keys, @details) }
|
80
|
-
else
|
81
|
-
find_template(layout, nil, false, keys, @details)
|
82
|
-
end
|
83
|
-
rescue ActionView::MissingTemplate
|
84
|
-
all_details = @details.merge(:formats => @lookup_context.default_formats)
|
85
|
-
raise unless template_exists?(layout, nil, false, keys, all_details)
|
86
|
-
end
|
87
|
-
when Proc
|
88
|
-
resolve_layout(layout.call, keys)
|
89
|
-
when FalseClass
|
90
|
-
nil
|
91
|
-
else
|
92
|
-
layout
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
module ActionView
|
2
|
-
module RoutingUrlFor
|
3
|
-
|
4
|
-
# Returns the URL for the set of +options+ provided. This takes the
|
5
|
-
# same options as +url_for+ in Action Controller (see the
|
6
|
-
# documentation for <tt>ActionController::Base#url_for</tt>). Note that by default
|
7
|
-
# <tt>:only_path</tt> is <tt>true</tt> so you'll get the relative "/controller/action"
|
8
|
-
# instead of the fully qualified URL like "http://example.com/controller/action".
|
9
|
-
#
|
10
|
-
# ==== Options
|
11
|
-
# * <tt>:anchor</tt> - Specifies the anchor name to be appended to the path.
|
12
|
-
# * <tt>:only_path</tt> - If true, returns the relative URL (omitting the protocol, host name, and port) (<tt>true</tt> by default unless <tt>:host</tt> is specified).
|
13
|
-
# * <tt>:trailing_slash</tt> - If true, adds a trailing slash, as in "/archive/2005/". Note that this
|
14
|
-
# is currently not recommended since it breaks caching.
|
15
|
-
# * <tt>:host</tt> - Overrides the default (current) host if provided.
|
16
|
-
# * <tt>:protocol</tt> - Overrides the default (current) protocol if provided.
|
17
|
-
# * <tt>:user</tt> - Inline HTTP authentication (only plucked out if <tt>:password</tt> is also present).
|
18
|
-
# * <tt>:password</tt> - Inline HTTP authentication (only plucked out if <tt>:user</tt> is also present).
|
19
|
-
#
|
20
|
-
# ==== Relying on named routes
|
21
|
-
#
|
22
|
-
# Passing a record (like an Active Record) instead of a hash as the options parameter will
|
23
|
-
# trigger the named route for that record. The lookup will happen on the name of the class. So passing a
|
24
|
-
# Workshop object will attempt to use the +workshop_path+ route. If you have a nested route, such as
|
25
|
-
# +admin_workshop_path+ you'll have to call that explicitly (it's impossible for +url_for+ to guess that route).
|
26
|
-
#
|
27
|
-
# ==== Implicit Controller Namespacing
|
28
|
-
#
|
29
|
-
# Controllers passed in using the +:controller+ option will retain their namespace unless it is an absolute one.
|
30
|
-
#
|
31
|
-
# ==== Examples
|
32
|
-
# <%= url_for(action: 'index') %>
|
33
|
-
# # => /blog/
|
34
|
-
#
|
35
|
-
# <%= url_for(action: 'find', controller: 'books') %>
|
36
|
-
# # => /books/find
|
37
|
-
#
|
38
|
-
# <%= url_for(action: 'login', controller: 'members', only_path: false, protocol: 'https') %>
|
39
|
-
# # => https://www.example.com/members/login/
|
40
|
-
#
|
41
|
-
# <%= url_for(action: 'play', anchor: 'player') %>
|
42
|
-
# # => /messages/play/#player
|
43
|
-
#
|
44
|
-
# <%= url_for(action: 'jump', anchor: 'tax&ship') %>
|
45
|
-
# # => /testing/jump/#tax&ship
|
46
|
-
#
|
47
|
-
# <%= url_for(Workshop.new) %>
|
48
|
-
# # relies on Workshop answering a persisted? call (and in this case returning false)
|
49
|
-
# # => /workshops
|
50
|
-
#
|
51
|
-
# <%= url_for(@workshop) %>
|
52
|
-
# # calls @workshop.to_param which by default returns the id
|
53
|
-
# # => /workshops/5
|
54
|
-
#
|
55
|
-
# # to_param can be re-defined in a model to provide different URL names:
|
56
|
-
# # => /workshops/1-workshop-name
|
57
|
-
#
|
58
|
-
# <%= url_for("http://www.example.com") %>
|
59
|
-
# # => http://www.example.com
|
60
|
-
#
|
61
|
-
# <%= url_for(:back) %>
|
62
|
-
# # if request.env["HTTP_REFERER"] is set to "http://www.example.com"
|
63
|
-
# # => http://www.example.com
|
64
|
-
#
|
65
|
-
# <%= url_for(:back) %>
|
66
|
-
# # if request.env["HTTP_REFERER"] is not set or is blank
|
67
|
-
# # => javascript:history.back()
|
68
|
-
#
|
69
|
-
# <%= url_for(action: 'index', controller: 'users') %>
|
70
|
-
# # Assuming an "admin" namespace
|
71
|
-
# # => /admin/users
|
72
|
-
#
|
73
|
-
# <%= url_for(action: 'index', controller: '/users') %>
|
74
|
-
# # Specify absolute path with beginning slash
|
75
|
-
# # => /users
|
76
|
-
def url_for(options = nil)
|
77
|
-
case options
|
78
|
-
when String
|
79
|
-
options
|
80
|
-
when nil, Hash
|
81
|
-
options ||= {}
|
82
|
-
options = { :only_path => options[:host].nil? }.merge!(options.symbolize_keys)
|
83
|
-
super
|
84
|
-
when :back
|
85
|
-
_back_url
|
86
|
-
else
|
87
|
-
polymorphic_path(options)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def url_options #:nodoc:
|
92
|
-
return super unless controller.respond_to?(:url_options)
|
93
|
-
controller.url_options
|
94
|
-
end
|
95
|
-
|
96
|
-
def _routes_context #:nodoc:
|
97
|
-
controller
|
98
|
-
end
|
99
|
-
protected :_routes_context
|
100
|
-
|
101
|
-
def optimize_routes_generation? #:nodoc:
|
102
|
-
controller.respond_to?(:optimize_routes_generation?, true) ?
|
103
|
-
controller.optimize_routes_generation? : super
|
104
|
-
end
|
105
|
-
protected :optimize_routes_generation?
|
106
|
-
end
|
107
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
namespace :cache_digests do
|
2
|
-
desc 'Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)'
|
3
|
-
task :nested_dependencies => :environment do
|
4
|
-
abort 'You must provide TEMPLATE for the task to run' unless ENV['TEMPLATE'].present?
|
5
|
-
template, format = ENV['TEMPLATE'].split(".")
|
6
|
-
format ||= :html
|
7
|
-
puts JSON.pretty_generate ActionView::Digestor.new(template, format, ApplicationController.new.lookup_context).nested_dependencies
|
8
|
-
end
|
9
|
-
|
10
|
-
desc 'Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)'
|
11
|
-
task :dependencies => :environment do
|
12
|
-
abort 'You must provide TEMPLATE for the task to run' unless ENV['TEMPLATE'].present?
|
13
|
-
template, format = ENV['TEMPLATE'].split(".")
|
14
|
-
format ||= :html
|
15
|
-
puts JSON.pretty_generate ActionView::Digestor.new(template, format, ApplicationController.new.lookup_context).dependencies
|
16
|
-
end
|
17
|
-
end
|
@@ -1,138 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/enumerable"
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
# = Action View Errors
|
5
|
-
class ActionViewError < StandardError #:nodoc:
|
6
|
-
end
|
7
|
-
|
8
|
-
class EncodingError < StandardError #:nodoc:
|
9
|
-
end
|
10
|
-
|
11
|
-
class MissingRequestError < StandardError #:nodoc:
|
12
|
-
end
|
13
|
-
|
14
|
-
class WrongEncodingError < EncodingError #:nodoc:
|
15
|
-
def initialize(string, encoding)
|
16
|
-
@string, @encoding = string, encoding
|
17
|
-
end
|
18
|
-
|
19
|
-
def message
|
20
|
-
@string.force_encoding(Encoding::ASCII_8BIT)
|
21
|
-
"Your template was not saved as valid #{@encoding}. Please " \
|
22
|
-
"either specify #{@encoding} as the encoding for your template " \
|
23
|
-
"in your text editor, or mark the template with its " \
|
24
|
-
"encoding by inserting the following as the first line " \
|
25
|
-
"of the template:\n\n# encoding: <name of correct encoding>.\n\n" \
|
26
|
-
"The source of your template was:\n\n#{@string}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class MissingTemplate < ActionViewError #:nodoc:
|
31
|
-
attr_reader :path
|
32
|
-
|
33
|
-
def initialize(paths, path, prefixes, partial, details, *)
|
34
|
-
@path = path
|
35
|
-
prefixes = Array(prefixes)
|
36
|
-
template_type = if partial
|
37
|
-
"partial"
|
38
|
-
elsif path =~ /layouts/i
|
39
|
-
'layout'
|
40
|
-
else
|
41
|
-
'template'
|
42
|
-
end
|
43
|
-
|
44
|
-
searched_paths = prefixes.map { |prefix| [prefix, path].join("/") }
|
45
|
-
|
46
|
-
out = "Missing #{template_type} #{searched_paths.join(", ")} with #{details.inspect}. Searched in:\n"
|
47
|
-
out += paths.compact.map { |p| " * #{p.to_s.inspect}\n" }.join
|
48
|
-
super out
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class Template
|
53
|
-
# The Template::Error exception is raised when the compilation or rendering of the template
|
54
|
-
# fails. This exception then gathers a bunch of intimate details and uses it to report a
|
55
|
-
# precise exception message.
|
56
|
-
class Error < ActionViewError #:nodoc:
|
57
|
-
SOURCE_CODE_RADIUS = 3
|
58
|
-
|
59
|
-
attr_reader :original_exception, :backtrace
|
60
|
-
|
61
|
-
def initialize(template, original_exception)
|
62
|
-
super(original_exception.message)
|
63
|
-
@template, @original_exception = template, original_exception
|
64
|
-
@sub_templates = nil
|
65
|
-
@backtrace = original_exception.backtrace
|
66
|
-
end
|
67
|
-
|
68
|
-
def file_name
|
69
|
-
@template.identifier
|
70
|
-
end
|
71
|
-
|
72
|
-
def sub_template_message
|
73
|
-
if @sub_templates
|
74
|
-
"Trace of template inclusion: " +
|
75
|
-
@sub_templates.collect { |template| template.inspect }.join(", ")
|
76
|
-
else
|
77
|
-
""
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def source_extract(indentation = 0, output = :console)
|
82
|
-
return unless num = line_number
|
83
|
-
num = num.to_i
|
84
|
-
|
85
|
-
source_code = @template.source.split("\n")
|
86
|
-
|
87
|
-
start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max
|
88
|
-
end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min
|
89
|
-
|
90
|
-
indent = end_on_line.to_s.size + indentation
|
91
|
-
return unless source_code = source_code[start_on_line..end_on_line]
|
92
|
-
|
93
|
-
formatted_code_for(source_code, start_on_line, indent, output)
|
94
|
-
end
|
95
|
-
|
96
|
-
def sub_template_of(template_path)
|
97
|
-
@sub_templates ||= []
|
98
|
-
@sub_templates << template_path
|
99
|
-
end
|
100
|
-
|
101
|
-
def line_number
|
102
|
-
@line_number ||=
|
103
|
-
if file_name
|
104
|
-
regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/
|
105
|
-
$1 if message =~ regexp || backtrace.find { |line| line =~ regexp }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def annoted_source_code
|
110
|
-
source_extract(4)
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
|
115
|
-
def source_location
|
116
|
-
if line_number
|
117
|
-
"on line ##{line_number} of "
|
118
|
-
else
|
119
|
-
'in '
|
120
|
-
end + file_name
|
121
|
-
end
|
122
|
-
|
123
|
-
def formatted_code_for(source_code, line_counter, indent, output)
|
124
|
-
start_value = (output == :html) ? {} : ""
|
125
|
-
source_code.inject(start_value) do |result, line|
|
126
|
-
line_counter += 1
|
127
|
-
if output == :html
|
128
|
-
result.update(line_counter.to_s => "%#{indent}s %s\n" % ["", line])
|
129
|
-
else
|
130
|
-
result << "%#{indent}s: %s\n" % [line_counter, line]
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
TemplateError = Template::Error
|
138
|
-
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 = :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,146 +0,0 @@
|
|
1
|
-
require 'action_dispatch/http/mime_type'
|
2
|
-
require 'erubis'
|
3
|
-
|
4
|
-
module ActionView
|
5
|
-
class Template
|
6
|
-
module Handlers
|
7
|
-
class Erubis < ::Erubis::Eruby
|
8
|
-
def add_preamble(src)
|
9
|
-
@newline_pending = 0
|
10
|
-
src << "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_text(src, text)
|
14
|
-
return if text.empty?
|
15
|
-
|
16
|
-
if text == "\n"
|
17
|
-
@newline_pending += 1
|
18
|
-
else
|
19
|
-
src << "@output_buffer.safe_append='"
|
20
|
-
src << "\n" * @newline_pending if @newline_pending > 0
|
21
|
-
src << escape_text(text)
|
22
|
-
src << "';"
|
23
|
-
|
24
|
-
@newline_pending = 0
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Erubis toggles <%= and <%== behavior when escaping is enabled.
|
29
|
-
# We override to always treat <%== as escaped.
|
30
|
-
def add_expr(src, code, indicator)
|
31
|
-
case indicator
|
32
|
-
when '=='
|
33
|
-
add_expr_escaped(src, code)
|
34
|
-
else
|
35
|
-
super
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
|
40
|
-
|
41
|
-
def add_expr_literal(src, code)
|
42
|
-
flush_newline_if_pending(src)
|
43
|
-
if code =~ BLOCK_EXPR
|
44
|
-
src << '@output_buffer.append= ' << code
|
45
|
-
else
|
46
|
-
src << '@output_buffer.append=(' << code << ');'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def add_expr_escaped(src, code)
|
51
|
-
flush_newline_if_pending(src)
|
52
|
-
if code =~ BLOCK_EXPR
|
53
|
-
src << "@output_buffer.safe_append= " << code
|
54
|
-
else
|
55
|
-
src << "@output_buffer.safe_append=(" << code << ");"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def add_stmt(src, code)
|
60
|
-
flush_newline_if_pending(src)
|
61
|
-
super
|
62
|
-
end
|
63
|
-
|
64
|
-
def add_postamble(src)
|
65
|
-
flush_newline_if_pending(src)
|
66
|
-
src << '@output_buffer.to_s'
|
67
|
-
end
|
68
|
-
|
69
|
-
def flush_newline_if_pending(src)
|
70
|
-
if @newline_pending > 0
|
71
|
-
src << "@output_buffer.safe_append='#{"\n" * @newline_pending}';"
|
72
|
-
@newline_pending = 0
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class ERB
|
78
|
-
# Specify trim mode for the ERB compiler. Defaults to '-'.
|
79
|
-
# See ERB documentation for suitable values.
|
80
|
-
class_attribute :erb_trim_mode
|
81
|
-
self.erb_trim_mode = '-'
|
82
|
-
|
83
|
-
# Default implementation used.
|
84
|
-
class_attribute :erb_implementation
|
85
|
-
self.erb_implementation = Erubis
|
86
|
-
|
87
|
-
# Do not escape templates of these mime types.
|
88
|
-
class_attribute :escape_whitelist
|
89
|
-
self.escape_whitelist = ["text/plain"]
|
90
|
-
|
91
|
-
ENCODING_TAG = Regexp.new("\\A(<%#{ENCODING_FLAG}-?%>)[ \\t]*")
|
92
|
-
|
93
|
-
def self.call(template)
|
94
|
-
new.call(template)
|
95
|
-
end
|
96
|
-
|
97
|
-
def supports_streaming?
|
98
|
-
true
|
99
|
-
end
|
100
|
-
|
101
|
-
def handles_encoding?
|
102
|
-
true
|
103
|
-
end
|
104
|
-
|
105
|
-
def call(template)
|
106
|
-
# First, convert to BINARY, so in case the encoding is
|
107
|
-
# wrong, we can still find an encoding tag
|
108
|
-
# (<%# encoding %>) inside the String using a regular
|
109
|
-
# expression
|
110
|
-
template_source = template.source.dup.force_encoding(Encoding::ASCII_8BIT)
|
111
|
-
|
112
|
-
erb = template_source.gsub(ENCODING_TAG, '')
|
113
|
-
encoding = $2
|
114
|
-
|
115
|
-
erb.force_encoding valid_encoding(template.source.dup, encoding)
|
116
|
-
|
117
|
-
# Always make sure we return a String in the default_internal
|
118
|
-
erb.encode!
|
119
|
-
|
120
|
-
self.class.erb_implementation.new(
|
121
|
-
erb,
|
122
|
-
:escape => (self.class.escape_whitelist.include? template.type),
|
123
|
-
:trim => (self.class.erb_trim_mode == "-")
|
124
|
-
).src
|
125
|
-
end
|
126
|
-
|
127
|
-
private
|
128
|
-
|
129
|
-
def valid_encoding(string, encoding)
|
130
|
-
# If a magic encoding comment was found, tag the
|
131
|
-
# String with this encoding. This is for a case
|
132
|
-
# where the original String was assumed to be,
|
133
|
-
# for instance, UTF-8, but a magic comment
|
134
|
-
# proved otherwise
|
135
|
-
string.force_encoding(encoding) if encoding
|
136
|
-
|
137
|
-
# If the String is valid, return the encoding we found
|
138
|
-
return string.encoding if string.valid_encoding?
|
139
|
-
|
140
|
-
# Otherwise, raise an exception
|
141
|
-
raise WrongEncodingError.new(string, string.encoding)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
@@ -1,53 +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
|
-
autoload :Raw, 'action_view/template/handlers/raw'
|
8
|
-
|
9
|
-
def self.extended(base)
|
10
|
-
base.register_default_template_handler :erb, ERB.new
|
11
|
-
base.register_template_handler :builder, Builder.new
|
12
|
-
base.register_template_handler :raw, Raw.new
|
13
|
-
base.register_template_handler :ruby, :source.to_proc
|
14
|
-
end
|
15
|
-
|
16
|
-
@@template_handlers = {}
|
17
|
-
@@default_template_handlers = nil
|
18
|
-
|
19
|
-
def self.extensions
|
20
|
-
@@template_extensions ||= @@template_handlers.keys
|
21
|
-
end
|
22
|
-
|
23
|
-
# Register an object that knows how to handle template files with the given
|
24
|
-
# extensions. This can be used to implement new template types.
|
25
|
-
# The handler must respond to `:call`, which will be passed the template
|
26
|
-
# and should return the rendered template as a String.
|
27
|
-
def register_template_handler(*extensions, handler)
|
28
|
-
raise(ArgumentError, "Extension is required") if extensions.empty?
|
29
|
-
extensions.each do |extension|
|
30
|
-
@@template_handlers[extension.to_sym] = handler
|
31
|
-
end
|
32
|
-
@@template_extensions = nil
|
33
|
-
end
|
34
|
-
|
35
|
-
def template_handler_extensions
|
36
|
-
@@template_handlers.keys.map {|key| key.to_s }.sort
|
37
|
-
end
|
38
|
-
|
39
|
-
def registered_template_handler(extension)
|
40
|
-
extension && @@template_handlers[extension.to_sym]
|
41
|
-
end
|
42
|
-
|
43
|
-
def register_default_template_handler(extension, klass)
|
44
|
-
register_template_handler(extension, klass)
|
45
|
-
@@default_template_handlers = klass
|
46
|
-
end
|
47
|
-
|
48
|
-
def handler_for_extension(extension)
|
49
|
-
registered_template_handler(extension) || @@default_template_handlers
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|