actionpack 4.0.13 → 4.1.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +131 -1636
- data/README.rdoc +1 -6
- data/lib/abstract_controller.rb +1 -2
- data/lib/abstract_controller/base.rb +3 -25
- data/lib/abstract_controller/callbacks.rb +4 -2
- data/lib/abstract_controller/collector.rb +11 -1
- data/lib/abstract_controller/helpers.rb +18 -15
- data/lib/abstract_controller/rendering.rb +48 -127
- data/lib/action_controller.rb +1 -17
- data/lib/action_controller/base.rb +14 -6
- data/lib/action_controller/caching.rb +1 -11
- data/lib/action_controller/log_subscriber.rb +1 -1
- data/lib/action_controller/metal.rb +0 -4
- data/lib/action_controller/metal/flash.rb +17 -0
- data/lib/action_controller/metal/force_ssl.rb +1 -1
- data/lib/action_controller/metal/head.rb +1 -3
- data/lib/action_controller/metal/helpers.rb +6 -2
- data/lib/action_controller/metal/http_authentication.rb +7 -14
- data/lib/action_controller/metal/instrumentation.rb +1 -1
- data/lib/action_controller/metal/live.rb +74 -0
- data/lib/action_controller/metal/mime_responds.rb +93 -16
- data/lib/action_controller/metal/params_wrapper.rb +4 -11
- data/lib/action_controller/metal/rack_delegation.rb +1 -1
- data/lib/action_controller/metal/redirecting.rb +20 -20
- data/lib/action_controller/metal/renderers.rb +8 -5
- data/lib/action_controller/metal/rendering.rb +14 -11
- data/lib/action_controller/metal/request_forgery_protection.rb +67 -13
- data/lib/action_controller/metal/responder.rb +12 -2
- data/lib/action_controller/metal/streaming.rb +18 -20
- data/lib/action_controller/metal/strong_parameters.rb +22 -34
- data/lib/action_controller/railtie.rb +0 -1
- data/lib/action_controller/test_case.rb +0 -15
- data/lib/action_dispatch.rb +1 -0
- data/lib/action_dispatch/http/headers.rb +1 -3
- data/lib/action_dispatch/http/mime_negotiation.rb +16 -2
- data/lib/action_dispatch/http/mime_type.rb +4 -22
- data/lib/action_dispatch/http/mime_types.rb +1 -0
- data/lib/action_dispatch/http/parameters.rb +18 -19
- data/lib/action_dispatch/http/request.rb +16 -25
- data/lib/action_dispatch/http/response.rb +21 -8
- data/lib/action_dispatch/http/upload.rb +0 -13
- data/lib/action_dispatch/http/url.rb +10 -18
- data/lib/action_dispatch/journey/formatter.rb +3 -3
- data/lib/action_dispatch/journey/gtg/transition_table.rb +3 -5
- data/lib/action_dispatch/journey/parser.rb +1 -1
- data/lib/action_dispatch/journey/parser.y +1 -0
- data/lib/action_dispatch/journey/router.rb +7 -1
- data/lib/action_dispatch/journey/router/utils.rb +1 -1
- data/lib/action_dispatch/journey/visitors.rb +26 -47
- data/lib/action_dispatch/middleware/callbacks.rb +6 -6
- data/lib/action_dispatch/middleware/cookies.rb +15 -15
- data/lib/action_dispatch/middleware/debug_exceptions.rb +21 -13
- data/lib/action_dispatch/middleware/exception_wrapper.rb +1 -1
- data/lib/action_dispatch/middleware/flash.rb +5 -11
- data/lib/action_dispatch/middleware/params_parser.rb +1 -1
- data/lib/action_dispatch/middleware/public_exceptions.rb +1 -5
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +4 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +5 -2
- data/lib/action_dispatch/middleware/ssl.rb +1 -1
- data/lib/action_dispatch/middleware/static.rb +5 -25
- 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/{_trace.erb → _trace.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +15 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/{missing_template.erb → missing_template.html.erb} +1 -1
- 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} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/{template_error.erb → template_error.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +8 -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 +3 -3
- data/lib/action_dispatch/railtie.rb +1 -2
- data/lib/action_dispatch/request/session.rb +12 -0
- data/lib/action_dispatch/request/utils.rb +24 -0
- data/lib/action_dispatch/routing.rb +7 -6
- data/lib/action_dispatch/routing/inspector.rb +4 -4
- data/lib/action_dispatch/routing/mapper.rb +81 -138
- data/lib/action_dispatch/routing/polymorphic_routes.rb +13 -0
- data/lib/action_dispatch/routing/redirection.rb +34 -27
- data/lib/action_dispatch/routing/route_set.rb +43 -37
- data/lib/action_dispatch/routing/url_for.rb +3 -1
- data/lib/action_dispatch/testing/assertions/response.rb +8 -15
- data/lib/action_dispatch/testing/assertions/selector.rb +4 -4
- data/lib/action_dispatch/testing/integration.rb +1 -7
- data/lib/action_pack/version.rb +1 -1
- metadata +43 -167
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/deprecated.rb +0 -7
- data/lib/action_controller/deprecated/integration_test.rb +0 -5
- data/lib/action_controller/record_identifier.rb +0 -31
- data/lib/action_controller/vendor/html-scanner.rb +0 -5
- data/lib/action_view.rb +0 -93
- data/lib/action_view/base.rb +0 -205
- 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.rb +0 -58
- 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 -32
- data/lib/action_view/helpers/date_helper.rb +0 -1087
- data/lib/action_view/helpers/debug_helper.rb +0 -39
- data/lib/action_view/helpers/form_helper.rb +0 -1882
- 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 -451
- 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.rb +0 -39
- 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 -53
- 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 -65
- 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 -22
- 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 -30
- 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/text_helper.rb +0 -448
- data/lib/action_view/helpers/translation_helper.rb +0 -112
- data/lib/action_view/helpers/url_helper.rb +0 -635
- 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 -248
- 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 -500
- 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.rb +0 -339
- data/lib/action_view/template/error.rb +0 -138
- data/lib/action_view/template/handlers.rb +0 -53
- 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/resolver.rb +0 -340
- data/lib/action_view/template/text.rb +0 -34
- data/lib/action_view/template/types.rb +0 -57
- 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.rb +0 -20
- 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
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
module ActionView
|
|
2
|
-
# This is the main entry point for rendering. It basically delegates
|
|
3
|
-
# to other objects like TemplateRenderer and PartialRenderer which
|
|
4
|
-
# actually renders the template.
|
|
5
|
-
#
|
|
6
|
-
# The Renderer will parse the options from the +render+ or +render_body+
|
|
7
|
-
# method and render a partial or a template based on the options. The
|
|
8
|
-
# +TemplateRenderer+ and +PartialRenderer+ objects are wrappers which do all
|
|
9
|
-
# the setup and logic necessary to render a view and a new object is created
|
|
10
|
-
# each time +render+ is called.
|
|
11
|
-
class Renderer
|
|
12
|
-
attr_accessor :lookup_context
|
|
13
|
-
|
|
14
|
-
def initialize(lookup_context)
|
|
15
|
-
@lookup_context = lookup_context
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Main render entry point shared by AV and AC.
|
|
19
|
-
def render(context, options)
|
|
20
|
-
if options.key?(:partial)
|
|
21
|
-
render_partial(context, options)
|
|
22
|
-
else
|
|
23
|
-
render_template(context, options)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Render but returns a valid Rack body. If fibers are defined, we return
|
|
28
|
-
# a streaming body that renders the template piece by piece.
|
|
29
|
-
#
|
|
30
|
-
# Note that partials are not supported to be rendered with streaming,
|
|
31
|
-
# so in such cases, we just wrap them in an array.
|
|
32
|
-
def render_body(context, options)
|
|
33
|
-
if options.key?(:partial)
|
|
34
|
-
[render_partial(context, options)]
|
|
35
|
-
else
|
|
36
|
-
StreamingTemplateRenderer.new(@lookup_context).render(context, options)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# Direct accessor to template rendering.
|
|
41
|
-
def render_template(context, options) #:nodoc:
|
|
42
|
-
TemplateRenderer.new(@lookup_context).render(context, options)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# Direct access to partial rendering.
|
|
46
|
-
def render_partial(context, options, &block) #:nodoc:
|
|
47
|
-
PartialRenderer.new(@lookup_context).render(context, options, block)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
require 'fiber'
|
|
2
|
-
|
|
3
|
-
module ActionView
|
|
4
|
-
# == TODO
|
|
5
|
-
#
|
|
6
|
-
# * Support streaming from child templates, partials and so on.
|
|
7
|
-
# * Integrate exceptions with exceptron
|
|
8
|
-
# * Rack::Cache needs to support streaming bodies
|
|
9
|
-
class StreamingTemplateRenderer < TemplateRenderer #:nodoc:
|
|
10
|
-
# A valid Rack::Body (i.e. it responds to each).
|
|
11
|
-
# It is initialized with a block that, when called, starts
|
|
12
|
-
# rendering the template.
|
|
13
|
-
class Body #:nodoc:
|
|
14
|
-
def initialize(&start)
|
|
15
|
-
@start = start
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def each(&block)
|
|
19
|
-
begin
|
|
20
|
-
@start.call(block)
|
|
21
|
-
rescue Exception => exception
|
|
22
|
-
log_error(exception)
|
|
23
|
-
block.call ActionView::Base.streaming_completion_on_exception
|
|
24
|
-
end
|
|
25
|
-
self
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
# This is the same logging logic as in ShowExceptions middleware.
|
|
31
|
-
# TODO Once "exceptron" is in, refactor this piece to simply re-use exceptron.
|
|
32
|
-
def log_error(exception) #:nodoc:
|
|
33
|
-
logger = ActionView::Base.logger
|
|
34
|
-
return unless logger
|
|
35
|
-
|
|
36
|
-
message = "\n#{exception.class} (#{exception.message}):\n"
|
|
37
|
-
message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
|
|
38
|
-
message << " " << exception.backtrace.join("\n ")
|
|
39
|
-
logger.fatal("#{message}\n\n")
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# For streaming, instead of rendering a given a template, we return a Body
|
|
44
|
-
# object that responds to each. This object is initialized with a block
|
|
45
|
-
# that knows how to render the template.
|
|
46
|
-
def render_template(template, layout_name = nil, locals = {}) #:nodoc:
|
|
47
|
-
return [super] unless layout_name && template.supports_streaming?
|
|
48
|
-
|
|
49
|
-
locals ||= {}
|
|
50
|
-
layout = layout_name && find_layout(layout_name, locals.keys)
|
|
51
|
-
|
|
52
|
-
Body.new do |buffer|
|
|
53
|
-
delayed_render(buffer, template, layout, @view, locals)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
private
|
|
58
|
-
|
|
59
|
-
def delayed_render(buffer, template, layout, view, locals)
|
|
60
|
-
# Wrap the given buffer in the StreamingBuffer and pass it to the
|
|
61
|
-
# underlying template handler. Now, everytime something is concatenated
|
|
62
|
-
# to the buffer, it is not appended to an array, but streamed straight
|
|
63
|
-
# to the client.
|
|
64
|
-
output = ActionView::StreamingBuffer.new(buffer)
|
|
65
|
-
yielder = lambda { |*name| view._layout_for(*name) }
|
|
66
|
-
|
|
67
|
-
instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
|
|
68
|
-
fiber = Fiber.new do
|
|
69
|
-
if layout
|
|
70
|
-
layout.render(view, locals, output, &yielder)
|
|
71
|
-
else
|
|
72
|
-
# If you don't have a layout, just render the thing
|
|
73
|
-
# and concatenate the final result. This is the same
|
|
74
|
-
# as a layout with just <%= yield %>
|
|
75
|
-
output.safe_concat view._layout_for
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Set the view flow to support streaming. It will be aware
|
|
80
|
-
# when to stop rendering the layout because it needs to search
|
|
81
|
-
# something in the template and vice-versa.
|
|
82
|
-
view.view_flow = StreamingFlow.new(view, fiber)
|
|
83
|
-
|
|
84
|
-
# Yo! Start the fiber!
|
|
85
|
-
fiber.resume
|
|
86
|
-
|
|
87
|
-
# If the fiber is still alive, it means we need something
|
|
88
|
-
# from the template, so start rendering it. If not, it means
|
|
89
|
-
# the layout exited without requiring anything from the template.
|
|
90
|
-
if fiber.alive?
|
|
91
|
-
content = template.render(view, locals, &yielder)
|
|
92
|
-
|
|
93
|
-
# Once rendering the template is done, sets its content in the :layout key.
|
|
94
|
-
view.view_flow.set(:layout, content)
|
|
95
|
-
|
|
96
|
-
# In case the layout continues yielding, we need to resume
|
|
97
|
-
# the fiber until all yields are handled.
|
|
98
|
-
fiber.resume while fiber.alive?
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -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
|
data/lib/action_view/template.rb
DELETED
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
require 'active_support/core_ext/object/try'
|
|
2
|
-
require 'active_support/core_ext/kernel/singleton_class'
|
|
3
|
-
require 'thread'
|
|
4
|
-
|
|
5
|
-
module ActionView
|
|
6
|
-
# = Action View Template
|
|
7
|
-
class Template
|
|
8
|
-
extend ActiveSupport::Autoload
|
|
9
|
-
|
|
10
|
-
# === Encodings in ActionView::Template
|
|
11
|
-
#
|
|
12
|
-
# ActionView::Template is one of a few sources of potential
|
|
13
|
-
# encoding issues in Rails. This is because the source for
|
|
14
|
-
# templates are usually read from disk, and Ruby (like most
|
|
15
|
-
# encoding-aware programming languages) assumes that the
|
|
16
|
-
# String retrieved through File IO is encoded in the
|
|
17
|
-
# <tt>default_external</tt> encoding. In Rails, the default
|
|
18
|
-
# <tt>default_external</tt> encoding is UTF-8.
|
|
19
|
-
#
|
|
20
|
-
# As a result, if a user saves their template as ISO-8859-1
|
|
21
|
-
# (for instance, using a non-Unicode-aware text editor),
|
|
22
|
-
# and uses characters outside of the ASCII range, their
|
|
23
|
-
# users will see diamonds with question marks in them in
|
|
24
|
-
# the browser.
|
|
25
|
-
#
|
|
26
|
-
# For the rest of this documentation, when we say "UTF-8",
|
|
27
|
-
# we mean "UTF-8 or whatever the default_internal encoding
|
|
28
|
-
# is set to". By default, it will be UTF-8.
|
|
29
|
-
#
|
|
30
|
-
# To mitigate this problem, we use a few strategies:
|
|
31
|
-
# 1. If the source is not valid UTF-8, we raise an exception
|
|
32
|
-
# when the template is compiled to alert the user
|
|
33
|
-
# to the problem.
|
|
34
|
-
# 2. The user can specify the encoding using Ruby-style
|
|
35
|
-
# encoding comments in any template engine. If such
|
|
36
|
-
# a comment is supplied, Rails will apply that encoding
|
|
37
|
-
# to the resulting compiled source returned by the
|
|
38
|
-
# template handler.
|
|
39
|
-
# 3. In all cases, we transcode the resulting String to
|
|
40
|
-
# the UTF-8.
|
|
41
|
-
#
|
|
42
|
-
# This means that other parts of Rails can always assume
|
|
43
|
-
# that templates are encoded in UTF-8, even if the original
|
|
44
|
-
# source of the template was not UTF-8.
|
|
45
|
-
#
|
|
46
|
-
# From a user's perspective, the easiest thing to do is
|
|
47
|
-
# to save your templates as UTF-8. If you do this, you
|
|
48
|
-
# do not need to do anything else for things to "just work".
|
|
49
|
-
#
|
|
50
|
-
# === Instructions for template handlers
|
|
51
|
-
#
|
|
52
|
-
# The easiest thing for you to do is to simply ignore
|
|
53
|
-
# encodings. Rails will hand you the template source
|
|
54
|
-
# as the default_internal (generally UTF-8), raising
|
|
55
|
-
# an exception for the user before sending the template
|
|
56
|
-
# to you if it could not determine the original encoding.
|
|
57
|
-
#
|
|
58
|
-
# For the greatest simplicity, you can support only
|
|
59
|
-
# UTF-8 as the <tt>default_internal</tt>. This means
|
|
60
|
-
# that from the perspective of your handler, the
|
|
61
|
-
# entire pipeline is just UTF-8.
|
|
62
|
-
#
|
|
63
|
-
# === Advanced: Handlers with alternate metadata sources
|
|
64
|
-
#
|
|
65
|
-
# If you want to provide an alternate mechanism for
|
|
66
|
-
# specifying encodings (like ERB does via <%# encoding: ... %>),
|
|
67
|
-
# you may indicate that you will handle encodings yourself
|
|
68
|
-
# by implementing <tt>self.handles_encoding?</tt>
|
|
69
|
-
# on your handler.
|
|
70
|
-
#
|
|
71
|
-
# If you do, Rails will not try to encode the String
|
|
72
|
-
# into the default_internal, passing you the unaltered
|
|
73
|
-
# bytes tagged with the assumed encoding (from
|
|
74
|
-
# default_external).
|
|
75
|
-
#
|
|
76
|
-
# In this case, make sure you return a String from
|
|
77
|
-
# your handler encoded in the default_internal. Since
|
|
78
|
-
# you are handling out-of-band metadata, you are
|
|
79
|
-
# also responsible for alerting the user to any
|
|
80
|
-
# problems with converting the user's data to
|
|
81
|
-
# the <tt>default_internal</tt>.
|
|
82
|
-
#
|
|
83
|
-
# To do so, simply raise +WrongEncodingError+ as follows:
|
|
84
|
-
#
|
|
85
|
-
# raise WrongEncodingError.new(
|
|
86
|
-
# problematic_string,
|
|
87
|
-
# expected_encoding
|
|
88
|
-
# )
|
|
89
|
-
|
|
90
|
-
eager_autoload do
|
|
91
|
-
autoload :Error
|
|
92
|
-
autoload :Handlers
|
|
93
|
-
autoload :Text
|
|
94
|
-
autoload :Types
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
extend Template::Handlers
|
|
98
|
-
|
|
99
|
-
attr_accessor :locals, :formats, :virtual_path
|
|
100
|
-
|
|
101
|
-
attr_reader :source, :identifier, :handler, :original_encoding, :updated_at
|
|
102
|
-
|
|
103
|
-
# This finalizer is needed (and exactly with a proc inside another proc)
|
|
104
|
-
# otherwise templates leak in development.
|
|
105
|
-
Finalizer = proc do |method_name, mod|
|
|
106
|
-
proc do
|
|
107
|
-
mod.module_eval do
|
|
108
|
-
remove_possible_method method_name
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def initialize(source, identifier, handler, details)
|
|
114
|
-
format = details[:format] || (handler.default_format if handler.respond_to?(:default_format))
|
|
115
|
-
|
|
116
|
-
@source = source
|
|
117
|
-
@identifier = identifier
|
|
118
|
-
@handler = handler
|
|
119
|
-
@compiled = false
|
|
120
|
-
@original_encoding = nil
|
|
121
|
-
@locals = details[:locals] || []
|
|
122
|
-
@virtual_path = details[:virtual_path]
|
|
123
|
-
@updated_at = details[:updated_at] || Time.now
|
|
124
|
-
@formats = Array(format).map { |f| f.respond_to?(:ref) ? f.ref : f }
|
|
125
|
-
@compile_mutex = Mutex.new
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
# Returns if the underlying handler supports streaming. If so,
|
|
129
|
-
# a streaming buffer *may* be passed when it start rendering.
|
|
130
|
-
def supports_streaming?
|
|
131
|
-
handler.respond_to?(:supports_streaming?) && handler.supports_streaming?
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
# Render a template. If the template was not compiled yet, it is done
|
|
135
|
-
# exactly before rendering.
|
|
136
|
-
#
|
|
137
|
-
# This method is instrumented as "!render_template.action_view". Notice that
|
|
138
|
-
# we use a bang in this instrumentation because you don't want to
|
|
139
|
-
# consume this in production. This is only slow if it's being listened to.
|
|
140
|
-
def render(view, locals, buffer=nil, &block)
|
|
141
|
-
ActiveSupport::Notifications.instrument("!render_template.action_view", virtual_path: @virtual_path, identifier: @identifier) do
|
|
142
|
-
compile!(view)
|
|
143
|
-
view.send(method_name, locals, buffer, &block)
|
|
144
|
-
end
|
|
145
|
-
rescue => e
|
|
146
|
-
handle_render_error(view, e)
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def mime_type
|
|
150
|
-
message = 'Template#mime_type is deprecated and will be removed in Rails 4.1. Please use type method instead.'
|
|
151
|
-
ActiveSupport::Deprecation.warn message
|
|
152
|
-
@mime_type ||= Mime::Type.lookup_by_extension(@formats.first.to_s) if @formats.first
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def type
|
|
156
|
-
@type ||= Types[@formats.first] if @formats.first
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
# Receives a view object and return a template similar to self by using @virtual_path.
|
|
160
|
-
#
|
|
161
|
-
# This method is useful if you have a template object but it does not contain its source
|
|
162
|
-
# anymore since it was already compiled. In such cases, all you need to do is to call
|
|
163
|
-
# refresh passing in the view object.
|
|
164
|
-
#
|
|
165
|
-
# Notice this method raises an error if the template to be refreshed does not have a
|
|
166
|
-
# virtual path set (true just for inline templates).
|
|
167
|
-
def refresh(view)
|
|
168
|
-
raise "A template needs to have a virtual path in order to be refreshed" unless @virtual_path
|
|
169
|
-
lookup = view.lookup_context
|
|
170
|
-
pieces = @virtual_path.split("/")
|
|
171
|
-
name = pieces.pop
|
|
172
|
-
partial = !!name.sub!(/^_/, "")
|
|
173
|
-
lookup.disable_cache do
|
|
174
|
-
lookup.find_template(name, [ pieces.join('/') ], partial, @locals)
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
def inspect
|
|
179
|
-
@inspect ||= defined?(Rails.root) ? identifier.sub("#{Rails.root}/", '') : identifier
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
# This method is responsible for properly setting the encoding of the
|
|
183
|
-
# source. Until this point, we assume that the source is BINARY data.
|
|
184
|
-
# If no additional information is supplied, we assume the encoding is
|
|
185
|
-
# the same as <tt>Encoding.default_external</tt>.
|
|
186
|
-
#
|
|
187
|
-
# The user can also specify the encoding via a comment on the first
|
|
188
|
-
# line of the template (# encoding: NAME-OF-ENCODING). This will work
|
|
189
|
-
# with any template engine, as we process out the encoding comment
|
|
190
|
-
# before passing the source on to the template engine, leaving a
|
|
191
|
-
# blank line in its stead.
|
|
192
|
-
def encode!
|
|
193
|
-
return unless source.encoding == Encoding::BINARY
|
|
194
|
-
|
|
195
|
-
# Look for # encoding: *. If we find one, we'll encode the
|
|
196
|
-
# String in that encoding, otherwise, we'll use the
|
|
197
|
-
# default external encoding.
|
|
198
|
-
if source.sub!(/\A#{ENCODING_FLAG}/, '')
|
|
199
|
-
encoding = magic_encoding = $1
|
|
200
|
-
else
|
|
201
|
-
encoding = Encoding.default_external
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
# Tag the source with the default external encoding
|
|
205
|
-
# or the encoding specified in the file
|
|
206
|
-
source.force_encoding(encoding)
|
|
207
|
-
|
|
208
|
-
# If the user didn't specify an encoding, and the handler
|
|
209
|
-
# handles encodings, we simply pass the String as is to
|
|
210
|
-
# the handler (with the default_external tag)
|
|
211
|
-
if !magic_encoding && @handler.respond_to?(:handles_encoding?) && @handler.handles_encoding?
|
|
212
|
-
source
|
|
213
|
-
# Otherwise, if the String is valid in the encoding,
|
|
214
|
-
# encode immediately to default_internal. This means
|
|
215
|
-
# that if a handler doesn't handle encodings, it will
|
|
216
|
-
# always get Strings in the default_internal
|
|
217
|
-
elsif source.valid_encoding?
|
|
218
|
-
source.encode!
|
|
219
|
-
# Otherwise, since the String is invalid in the encoding
|
|
220
|
-
# specified, raise an exception
|
|
221
|
-
else
|
|
222
|
-
raise WrongEncodingError.new(source, encoding)
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
protected
|
|
227
|
-
|
|
228
|
-
# Compile a template. This method ensures a template is compiled
|
|
229
|
-
# just once and removes the source after it is compiled.
|
|
230
|
-
def compile!(view) #:nodoc:
|
|
231
|
-
return if @compiled
|
|
232
|
-
|
|
233
|
-
# Templates can be used concurrently in threaded environments
|
|
234
|
-
# so compilation and any instance variable modification must
|
|
235
|
-
# be synchronized
|
|
236
|
-
@compile_mutex.synchronize do
|
|
237
|
-
# Any thread holding this lock will be compiling the template needed
|
|
238
|
-
# by the threads waiting. So re-check the @compiled flag to avoid
|
|
239
|
-
# re-compilation
|
|
240
|
-
return if @compiled
|
|
241
|
-
|
|
242
|
-
if view.is_a?(ActionView::CompiledTemplates)
|
|
243
|
-
mod = ActionView::CompiledTemplates
|
|
244
|
-
else
|
|
245
|
-
mod = view.singleton_class
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
compile(view, mod)
|
|
249
|
-
|
|
250
|
-
# Just discard the source if we have a virtual path. This
|
|
251
|
-
# means we can get the template back.
|
|
252
|
-
@source = nil if @virtual_path
|
|
253
|
-
@compiled = true
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
# Among other things, this method is responsible for properly setting
|
|
258
|
-
# the encoding of the compiled template.
|
|
259
|
-
#
|
|
260
|
-
# If the template engine handles encodings, we send the encoded
|
|
261
|
-
# String to the engine without further processing. This allows
|
|
262
|
-
# the template engine to support additional mechanisms for
|
|
263
|
-
# specifying the encoding. For instance, ERB supports <%# encoding: %>
|
|
264
|
-
#
|
|
265
|
-
# Otherwise, after we figure out the correct encoding, we then
|
|
266
|
-
# encode the source into <tt>Encoding.default_internal</tt>.
|
|
267
|
-
# In general, this means that templates will be UTF-8 inside of Rails,
|
|
268
|
-
# regardless of the original source encoding.
|
|
269
|
-
def compile(view, mod) #:nodoc:
|
|
270
|
-
encode!
|
|
271
|
-
method_name = self.method_name
|
|
272
|
-
code = @handler.call(self)
|
|
273
|
-
|
|
274
|
-
# Make sure that the resulting String to be evalled is in the
|
|
275
|
-
# encoding of the code
|
|
276
|
-
source = <<-end_src
|
|
277
|
-
def #{method_name}(local_assigns, output_buffer)
|
|
278
|
-
_old_virtual_path, @virtual_path = @virtual_path, #{@virtual_path.inspect};_old_output_buffer = @output_buffer;#{locals_code};#{code}
|
|
279
|
-
ensure
|
|
280
|
-
@virtual_path, @output_buffer = _old_virtual_path, _old_output_buffer
|
|
281
|
-
end
|
|
282
|
-
end_src
|
|
283
|
-
|
|
284
|
-
# Make sure the source is in the encoding of the returned code
|
|
285
|
-
source.force_encoding(code.encoding)
|
|
286
|
-
|
|
287
|
-
# In case we get back a String from a handler that is not in
|
|
288
|
-
# BINARY or the default_internal, encode it to the default_internal
|
|
289
|
-
source.encode!
|
|
290
|
-
|
|
291
|
-
# Now, validate that the source we got back from the template
|
|
292
|
-
# handler is valid in the default_internal. This is for handlers
|
|
293
|
-
# that handle encoding but screw up
|
|
294
|
-
unless source.valid_encoding?
|
|
295
|
-
raise WrongEncodingError.new(@source, Encoding.default_internal)
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
begin
|
|
299
|
-
mod.module_eval(source, identifier, 0)
|
|
300
|
-
ObjectSpace.define_finalizer(self, Finalizer[method_name, mod])
|
|
301
|
-
rescue => e # errors from template code
|
|
302
|
-
if logger = (view && view.logger)
|
|
303
|
-
logger.debug "ERROR: compiling #{method_name} RAISED #{e}"
|
|
304
|
-
logger.debug "Function body: #{source}"
|
|
305
|
-
logger.debug "Backtrace: #{e.backtrace.join("\n")}"
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
raise ActionView::Template::Error.new(self, e)
|
|
309
|
-
end
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
def handle_render_error(view, e) #:nodoc:
|
|
313
|
-
if e.is_a?(Template::Error)
|
|
314
|
-
e.sub_template_of(self)
|
|
315
|
-
raise e
|
|
316
|
-
else
|
|
317
|
-
template = self
|
|
318
|
-
unless template.source
|
|
319
|
-
template = refresh(view)
|
|
320
|
-
template.encode!
|
|
321
|
-
end
|
|
322
|
-
raise Template::Error.new(template, e)
|
|
323
|
-
end
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
def locals_code #:nodoc:
|
|
327
|
-
# Double assign to suppress the dreaded 'assigned but unused variable' warning
|
|
328
|
-
@locals.map { |key| "#{key} = #{key} = local_assigns[:#{key}];" }.join
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
def method_name #:nodoc:
|
|
332
|
-
@method_name ||= "_#{identifier_method_name}__#{@identifier.hash}_#{__id__}".gsub('-', "_")
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
def identifier_method_name #:nodoc:
|
|
336
|
-
inspect.gsub(/[^a-z_]/, '_')
|
|
337
|
-
end
|
|
338
|
-
end
|
|
339
|
-
end
|