actionpack 4.0.13 → 4.1.0.beta1
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 +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
data/lib/action_view/digestor.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'thread_safe'
|
2
|
-
require 'action_view/dependency_tracker'
|
3
|
-
require 'monitor'
|
4
|
-
|
5
|
-
module ActionView
|
6
|
-
class Digestor
|
7
|
-
cattr_reader(:cache)
|
8
|
-
@@cache = ThreadSafe::Cache.new
|
9
|
-
@@digest_monitor = Monitor.new
|
10
|
-
|
11
|
-
class << self
|
12
|
-
def digest(name, format, finder, options = {})
|
13
|
-
cache_key = ([name, format] + Array.wrap(options[:dependencies])).join('.')
|
14
|
-
# this is a correctly done double-checked locking idiom
|
15
|
-
# (ThreadSafe::Cache's lookups have volatile semantics)
|
16
|
-
@@cache[cache_key] || @@digest_monitor.synchronize do
|
17
|
-
@@cache.fetch(cache_key) do # re-check under lock
|
18
|
-
compute_and_store_digest(cache_key, name, format, finder, options)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
def compute_and_store_digest(cache_key, name, format, finder, options) # called under @@digest_monitor lock
|
25
|
-
klass = if options[:partial] || name.include?("/_")
|
26
|
-
# Prevent re-entry or else recursive templates will blow the stack.
|
27
|
-
# There is no need to worry about other threads seeing the +false+ value,
|
28
|
-
# as they will then have to wait for this thread to let go of the @@digest_monitor lock.
|
29
|
-
pre_stored = @@cache.put_if_absent(cache_key, false).nil? # put_if_absent returns nil on insertion
|
30
|
-
PartialDigestor
|
31
|
-
else
|
32
|
-
Digestor
|
33
|
-
end
|
34
|
-
|
35
|
-
digest = klass.new(name, format, finder, options).digest
|
36
|
-
# Store the actual digest if config.cache_template_loading is true
|
37
|
-
@@cache[cache_key] = stored_digest = digest if ActionView::Resolver.caching?
|
38
|
-
digest
|
39
|
-
ensure
|
40
|
-
# something went wrong or ActionView::Resolver.caching? is false, make sure not to corrupt the @@cache
|
41
|
-
@@cache.delete_pair(cache_key, false) if pre_stored && !stored_digest
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
attr_reader :name, :format, :finder, :options
|
46
|
-
|
47
|
-
def initialize(name, format, finder, options={})
|
48
|
-
@name, @format, @finder, @options = name, format, finder, options
|
49
|
-
end
|
50
|
-
|
51
|
-
def digest
|
52
|
-
Digest::MD5.hexdigest("#{source}-#{dependency_digest}").tap do |digest|
|
53
|
-
logger.try :info, "Cache digest for #{name}.#{format}: #{digest}"
|
54
|
-
end
|
55
|
-
rescue ActionView::MissingTemplate
|
56
|
-
logger.try :error, "Couldn't find template for digesting: #{name}.#{format}"
|
57
|
-
''
|
58
|
-
end
|
59
|
-
|
60
|
-
def dependencies
|
61
|
-
DependencyTracker.find_dependencies(name, template)
|
62
|
-
rescue ActionView::MissingTemplate
|
63
|
-
[] # File doesn't exist, so no dependencies
|
64
|
-
end
|
65
|
-
|
66
|
-
def nested_dependencies
|
67
|
-
dependencies.collect do |dependency|
|
68
|
-
dependencies = PartialDigestor.new(dependency, format, finder).nested_dependencies
|
69
|
-
dependencies.any? ? { dependency => dependencies } : dependency
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def logger
|
76
|
-
ActionView::Base.logger
|
77
|
-
end
|
78
|
-
|
79
|
-
def logical_name
|
80
|
-
name.gsub(%r|/_|, "/")
|
81
|
-
end
|
82
|
-
|
83
|
-
def partial?
|
84
|
-
false
|
85
|
-
end
|
86
|
-
|
87
|
-
def template
|
88
|
-
@template ||= finder.find(logical_name, [], partial?, formats: [ format ])
|
89
|
-
end
|
90
|
-
|
91
|
-
def source
|
92
|
-
template.source
|
93
|
-
end
|
94
|
-
|
95
|
-
def dependency_digest
|
96
|
-
template_digests = dependencies.collect do |template_name|
|
97
|
-
Digestor.digest(template_name, format, finder, partial: true)
|
98
|
-
end
|
99
|
-
|
100
|
-
(template_digests + injected_dependencies).join("-")
|
101
|
-
end
|
102
|
-
|
103
|
-
def injected_dependencies
|
104
|
-
Array.wrap(options[:dependencies])
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class PartialDigestor < Digestor # :nodoc:
|
109
|
-
def partial?
|
110
|
-
true
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
data/lib/action_view/flows.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/string/output_safety'
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
class OutputFlow #:nodoc:
|
5
|
-
attr_reader :content
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@content = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new }
|
9
|
-
end
|
10
|
-
|
11
|
-
# Called by _layout_for to read stored values.
|
12
|
-
def get(key)
|
13
|
-
@content[key]
|
14
|
-
end
|
15
|
-
|
16
|
-
# Called by each renderer object to set the layout contents.
|
17
|
-
def set(key, value)
|
18
|
-
@content[key] = value
|
19
|
-
end
|
20
|
-
|
21
|
-
# Called by content_for
|
22
|
-
def append(key, value)
|
23
|
-
@content[key] << value
|
24
|
-
end
|
25
|
-
alias_method :append!, :append
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
class StreamingFlow < OutputFlow #:nodoc:
|
30
|
-
def initialize(view, fiber)
|
31
|
-
@view = view
|
32
|
-
@parent = nil
|
33
|
-
@child = view.output_buffer
|
34
|
-
@content = view.view_flow.content
|
35
|
-
@fiber = fiber
|
36
|
-
@root = Fiber.current.object_id
|
37
|
-
end
|
38
|
-
|
39
|
-
# Try to get an stored content. If the content
|
40
|
-
# is not available and we are inside the layout
|
41
|
-
# fiber, we set that we are waiting for the given
|
42
|
-
# key and yield.
|
43
|
-
def get(key)
|
44
|
-
return super if @content.key?(key)
|
45
|
-
|
46
|
-
if inside_fiber?
|
47
|
-
view = @view
|
48
|
-
|
49
|
-
begin
|
50
|
-
@waiting_for = key
|
51
|
-
view.output_buffer, @parent = @child, view.output_buffer
|
52
|
-
Fiber.yield
|
53
|
-
ensure
|
54
|
-
@waiting_for = nil
|
55
|
-
view.output_buffer, @child = @parent, view.output_buffer
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
super
|
60
|
-
end
|
61
|
-
|
62
|
-
# Appends the contents for the given key. This is called
|
63
|
-
# by provides and resumes back to the fiber if it is
|
64
|
-
# the key it is waiting for.
|
65
|
-
def append!(key, value)
|
66
|
-
super
|
67
|
-
@fiber.resume if @waiting_for == key
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def inside_fiber?
|
73
|
-
Fiber.current.object_id != @root
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/lib/action_view/helpers.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'active_support/benchmarkable'
|
2
|
-
|
3
|
-
module ActionView #:nodoc:
|
4
|
-
module Helpers #:nodoc:
|
5
|
-
extend ActiveSupport::Autoload
|
6
|
-
|
7
|
-
autoload :ActiveModelHelper
|
8
|
-
autoload :AssetTagHelper
|
9
|
-
autoload :AssetUrlHelper
|
10
|
-
autoload :AtomFeedHelper
|
11
|
-
autoload :CacheHelper
|
12
|
-
autoload :CaptureHelper
|
13
|
-
autoload :ControllerHelper
|
14
|
-
autoload :CsrfHelper
|
15
|
-
autoload :DateHelper
|
16
|
-
autoload :DebugHelper
|
17
|
-
autoload :FormHelper
|
18
|
-
autoload :FormOptionsHelper
|
19
|
-
autoload :FormTagHelper
|
20
|
-
autoload :JavaScriptHelper, "action_view/helpers/javascript_helper"
|
21
|
-
autoload :NumberHelper
|
22
|
-
autoload :OutputSafetyHelper
|
23
|
-
autoload :RecordTagHelper
|
24
|
-
autoload :RenderingHelper
|
25
|
-
autoload :SanitizeHelper
|
26
|
-
autoload :TagHelper
|
27
|
-
autoload :TextHelper
|
28
|
-
autoload :TranslationHelper
|
29
|
-
autoload :UrlHelper
|
30
|
-
|
31
|
-
extend ActiveSupport::Concern
|
32
|
-
|
33
|
-
include ActiveSupport::Benchmarkable
|
34
|
-
include ActiveModelHelper
|
35
|
-
include AssetTagHelper
|
36
|
-
include AssetUrlHelper
|
37
|
-
include AtomFeedHelper
|
38
|
-
include CacheHelper
|
39
|
-
include CaptureHelper
|
40
|
-
include ControllerHelper
|
41
|
-
include CsrfHelper
|
42
|
-
include DateHelper
|
43
|
-
include DebugHelper
|
44
|
-
include FormHelper
|
45
|
-
include FormOptionsHelper
|
46
|
-
include FormTagHelper
|
47
|
-
include JavaScriptHelper
|
48
|
-
include NumberHelper
|
49
|
-
include OutputSafetyHelper
|
50
|
-
include RecordTagHelper
|
51
|
-
include RenderingHelper
|
52
|
-
include SanitizeHelper
|
53
|
-
include TagHelper
|
54
|
-
include TextHelper
|
55
|
-
include TranslationHelper
|
56
|
-
include UrlHelper
|
57
|
-
end
|
58
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/class/attribute_accessors'
|
2
|
-
require 'active_support/core_ext/enumerable'
|
3
|
-
|
4
|
-
module ActionView
|
5
|
-
# = Active Model Helpers
|
6
|
-
module Helpers
|
7
|
-
module ActiveModelHelper
|
8
|
-
end
|
9
|
-
|
10
|
-
module ActiveModelInstanceTag
|
11
|
-
def object
|
12
|
-
@active_model_object ||= begin
|
13
|
-
object = super
|
14
|
-
object.respond_to?(:to_model) ? object.to_model : object
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def content_tag(*)
|
19
|
-
error_wrapping(super)
|
20
|
-
end
|
21
|
-
|
22
|
-
def tag(type, options, *)
|
23
|
-
tag_generate_errors?(options) ? error_wrapping(super) : super
|
24
|
-
end
|
25
|
-
|
26
|
-
def error_wrapping(html_tag)
|
27
|
-
if object_has_errors?
|
28
|
-
Base.field_error_proc.call(html_tag, self)
|
29
|
-
else
|
30
|
-
html_tag
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def error_message
|
35
|
-
object.errors[@method_name]
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def object_has_errors?
|
41
|
-
object.respond_to?(:errors) && object.errors.respond_to?(:[]) && error_message.present?
|
42
|
-
end
|
43
|
-
|
44
|
-
def tag_generate_errors?(options)
|
45
|
-
options['type'] != 'hidden'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,320 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/array/extract_options'
|
2
|
-
require 'active_support/core_ext/hash/keys'
|
3
|
-
require 'action_view/helpers/asset_url_helper'
|
4
|
-
require 'action_view/helpers/tag_helper'
|
5
|
-
|
6
|
-
module ActionView
|
7
|
-
# = Action View Asset Tag Helpers
|
8
|
-
module Helpers #:nodoc:
|
9
|
-
# This module provides methods for generating HTML that links views to assets such
|
10
|
-
# as images, javascripts, stylesheets, and feeds. These methods do not verify
|
11
|
-
# the assets exist before linking to them:
|
12
|
-
#
|
13
|
-
# image_tag("rails.png")
|
14
|
-
# # => <img alt="Rails" src="/assets/rails.png" />
|
15
|
-
# stylesheet_link_tag("application")
|
16
|
-
# # => <link href="/assets/application.css?body=1" media="screen" rel="stylesheet" />
|
17
|
-
module AssetTagHelper
|
18
|
-
extend ActiveSupport::Concern
|
19
|
-
|
20
|
-
include AssetUrlHelper
|
21
|
-
include TagHelper
|
22
|
-
|
23
|
-
# Returns an HTML script tag for each of the +sources+ provided.
|
24
|
-
#
|
25
|
-
# Sources may be paths to JavaScript files. Relative paths are assumed to be relative
|
26
|
-
# to <tt>assets/javascripts</tt>, full paths are assumed to be relative to the document
|
27
|
-
# root. Relative paths are idiomatic, use absolute paths only when needed.
|
28
|
-
#
|
29
|
-
# When passing paths, the ".js" extension is optional.
|
30
|
-
#
|
31
|
-
# You can modify the HTML attributes of the script tag by passing a hash as the
|
32
|
-
# last argument.
|
33
|
-
#
|
34
|
-
# When the Asset Pipeline is enabled, you can pass the name of your manifest as
|
35
|
-
# source, and include other JavaScript or CoffeeScript files inside the manifest.
|
36
|
-
#
|
37
|
-
# javascript_include_tag "xmlhr"
|
38
|
-
# # => <script src="/assets/xmlhr.js?1284139606"></script>
|
39
|
-
#
|
40
|
-
# javascript_include_tag "xmlhr.js"
|
41
|
-
# # => <script src="/assets/xmlhr.js?1284139606"></script>
|
42
|
-
#
|
43
|
-
# javascript_include_tag "common.javascript", "/elsewhere/cools"
|
44
|
-
# # => <script src="/assets/common.javascript?1284139606"></script>
|
45
|
-
# # <script src="/elsewhere/cools.js?1423139606"></script>
|
46
|
-
#
|
47
|
-
# javascript_include_tag "http://www.example.com/xmlhr"
|
48
|
-
# # => <script src="http://www.example.com/xmlhr"></script>
|
49
|
-
#
|
50
|
-
# javascript_include_tag "http://www.example.com/xmlhr.js"
|
51
|
-
# # => <script src="http://www.example.com/xmlhr.js"></script>
|
52
|
-
def javascript_include_tag(*sources)
|
53
|
-
options = sources.extract_options!.stringify_keys
|
54
|
-
path_options = options.extract!('protocol').symbolize_keys
|
55
|
-
|
56
|
-
sources.uniq.map { |source|
|
57
|
-
tag_options = {
|
58
|
-
"src" => path_to_javascript(source, path_options)
|
59
|
-
}.merge!(options)
|
60
|
-
content_tag(:script, "", tag_options)
|
61
|
-
}.join("\n").html_safe
|
62
|
-
end
|
63
|
-
|
64
|
-
# Returns a stylesheet link tag for the sources specified as arguments. If
|
65
|
-
# you don't specify an extension, <tt>.css</tt> will be appended automatically.
|
66
|
-
# You can modify the link attributes by passing a hash as the last argument.
|
67
|
-
# For historical reasons, the 'media' attribute will always be present and defaults
|
68
|
-
# to "screen", so you must explicitly set it to "all" for the stylesheet(s) to
|
69
|
-
# apply to all media types.
|
70
|
-
#
|
71
|
-
# stylesheet_link_tag "style"
|
72
|
-
# # => <link href="/assets/style.css" media="screen" rel="stylesheet" />
|
73
|
-
#
|
74
|
-
# stylesheet_link_tag "style.css"
|
75
|
-
# # => <link href="/assets/style.css" media="screen" rel="stylesheet" />
|
76
|
-
#
|
77
|
-
# stylesheet_link_tag "http://www.example.com/style.css"
|
78
|
-
# # => <link href="http://www.example.com/style.css" media="screen" rel="stylesheet" />
|
79
|
-
#
|
80
|
-
# stylesheet_link_tag "style", media: "all"
|
81
|
-
# # => <link href="/assets/style.css" media="all" rel="stylesheet" />
|
82
|
-
#
|
83
|
-
# stylesheet_link_tag "style", media: "print"
|
84
|
-
# # => <link href="/assets/style.css" media="print" rel="stylesheet" />
|
85
|
-
#
|
86
|
-
# stylesheet_link_tag "random.styles", "/css/stylish"
|
87
|
-
# # => <link href="/assets/random.styles" media="screen" rel="stylesheet" />
|
88
|
-
# # <link href="/css/stylish.css" media="screen" rel="stylesheet" />
|
89
|
-
def stylesheet_link_tag(*sources)
|
90
|
-
options = sources.extract_options!.stringify_keys
|
91
|
-
path_options = options.extract!('protocol').symbolize_keys
|
92
|
-
|
93
|
-
sources.uniq.map { |source|
|
94
|
-
tag_options = {
|
95
|
-
"rel" => "stylesheet",
|
96
|
-
"media" => "screen",
|
97
|
-
"href" => path_to_stylesheet(source, path_options)
|
98
|
-
}.merge!(options)
|
99
|
-
tag(:link, tag_options)
|
100
|
-
}.join("\n").html_safe
|
101
|
-
end
|
102
|
-
|
103
|
-
# Returns a link tag that browsers and news readers can use to auto-detect
|
104
|
-
# an RSS or Atom feed. The +type+ can either be <tt>:rss</tt> (default) or
|
105
|
-
# <tt>:atom</tt>. Control the link options in url_for format using the
|
106
|
-
# +url_options+. You can modify the LINK tag itself in +tag_options+.
|
107
|
-
#
|
108
|
-
# ==== Options
|
109
|
-
#
|
110
|
-
# * <tt>:rel</tt> - Specify the relation of this link, defaults to "alternate"
|
111
|
-
# * <tt>:type</tt> - Override the auto-generated mime type
|
112
|
-
# * <tt>:title</tt> - Specify the title of the link, defaults to the +type+
|
113
|
-
#
|
114
|
-
# ==== Examples
|
115
|
-
#
|
116
|
-
# auto_discovery_link_tag
|
117
|
-
# # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/action" />
|
118
|
-
# auto_discovery_link_tag(:atom)
|
119
|
-
# # => <link rel="alternate" type="application/atom+xml" title="ATOM" href="http://www.currenthost.com/controller/action" />
|
120
|
-
# auto_discovery_link_tag(:rss, {action: "feed"})
|
121
|
-
# # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/feed" />
|
122
|
-
# auto_discovery_link_tag(:rss, {action: "feed"}, {title: "My RSS"})
|
123
|
-
# # => <link rel="alternate" type="application/rss+xml" title="My RSS" href="http://www.currenthost.com/controller/feed" />
|
124
|
-
# auto_discovery_link_tag(:rss, {controller: "news", action: "feed"})
|
125
|
-
# # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/news/feed" />
|
126
|
-
# auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {title: "Example RSS"})
|
127
|
-
# # => <link rel="alternate" type="application/rss+xml" title="Example RSS" href="http://www.example.com/feed" />
|
128
|
-
def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
|
129
|
-
if !(type == :rss || type == :atom) && tag_options[:type].blank?
|
130
|
-
message = "You have passed type other than :rss or :atom to auto_discovery_link_tag and haven't supplied " +
|
131
|
-
"the :type option key. This behavior is deprecated and will be remove in Rails 4.1. You should pass " +
|
132
|
-
":type option explicitly if you want to use other types, for example: " +
|
133
|
-
"auto_discovery_link_tag(:xml, '/feed.xml', :type => 'application/xml')"
|
134
|
-
ActiveSupport::Deprecation.warn message
|
135
|
-
end
|
136
|
-
|
137
|
-
tag(
|
138
|
-
"link",
|
139
|
-
"rel" => tag_options[:rel] || "alternate",
|
140
|
-
"type" => tag_options[:type] || Mime::Type.lookup_by_extension(type.to_s).to_s,
|
141
|
-
"title" => tag_options[:title] || type.to_s.upcase,
|
142
|
-
"href" => url_options.is_a?(Hash) ? url_for(url_options.merge(:only_path => false)) : url_options
|
143
|
-
)
|
144
|
-
end
|
145
|
-
|
146
|
-
# Returns a link loading a favicon file. You may specify a different file
|
147
|
-
# in the first argument. The helper accepts an additional options hash where
|
148
|
-
# you can override "rel" and "type".
|
149
|
-
#
|
150
|
-
# ==== Options
|
151
|
-
#
|
152
|
-
# * <tt>:rel</tt> - Specify the relation of this link, defaults to 'shortcut icon'
|
153
|
-
# * <tt>:type</tt> - Override the auto-generated mime type, defaults to 'image/vnd.microsoft.icon'
|
154
|
-
#
|
155
|
-
# ==== Examples
|
156
|
-
#
|
157
|
-
# favicon_link_tag 'myicon.ico'
|
158
|
-
# # => <link href="/assets/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
|
159
|
-
#
|
160
|
-
# Mobile Safari looks for a different <link> tag, pointing to an image that
|
161
|
-
# will be used if you add the page to the home screen of an iPod Touch, iPhone, or iPad.
|
162
|
-
# The following call would generate such a tag:
|
163
|
-
#
|
164
|
-
# favicon_link_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png'
|
165
|
-
# # => <link href="/assets/mb-icon.png" rel="apple-touch-icon" type="image/png" />
|
166
|
-
def favicon_link_tag(source='favicon.ico', options={})
|
167
|
-
tag('link', {
|
168
|
-
:rel => 'shortcut icon',
|
169
|
-
:type => 'image/vnd.microsoft.icon',
|
170
|
-
:href => path_to_image(source)
|
171
|
-
}.merge!(options.symbolize_keys))
|
172
|
-
end
|
173
|
-
|
174
|
-
# Returns an HTML image tag for the +source+. The +source+ can be a full
|
175
|
-
# path or a file.
|
176
|
-
#
|
177
|
-
# ==== Options
|
178
|
-
#
|
179
|
-
# You can add HTML attributes using the +options+. The +options+ supports
|
180
|
-
# three additional keys for convenience and conformance:
|
181
|
-
#
|
182
|
-
# * <tt>:alt</tt> - If no alt text is given, the file name part of the
|
183
|
-
# +source+ is used (capitalized and without the extension)
|
184
|
-
# * <tt>:size</tt> - Supplied as "{Width}x{Height}" or "{Number}", so "30x45" becomes
|
185
|
-
# width="30" and height="45", and "50" becomes width="50" and height="50".
|
186
|
-
# <tt>:size</tt> will be ignored if the value is not in the correct format.
|
187
|
-
#
|
188
|
-
# ==== Examples
|
189
|
-
#
|
190
|
-
# image_tag("icon")
|
191
|
-
# # => <img alt="Icon" src="/assets/icon" />
|
192
|
-
# image_tag("icon.png")
|
193
|
-
# # => <img alt="Icon" src="/assets/icon.png" />
|
194
|
-
# image_tag("icon.png", size: "16x10", alt: "Edit Entry")
|
195
|
-
# # => <img src="/assets/icon.png" width="16" height="10" alt="Edit Entry" />
|
196
|
-
# image_tag("/icons/icon.gif", size: "16")
|
197
|
-
# # => <img src="/icons/icon.gif" width="16" height="16" alt="Icon" />
|
198
|
-
# image_tag("/icons/icon.gif", height: '32', width: '32')
|
199
|
-
# # => <img alt="Icon" height="32" src="/icons/icon.gif" width="32" />
|
200
|
-
# image_tag("/icons/icon.gif", class: "menu_icon")
|
201
|
-
# # => <img alt="Icon" class="menu_icon" src="/icons/icon.gif" />
|
202
|
-
def image_tag(source, options={})
|
203
|
-
options = options.symbolize_keys
|
204
|
-
|
205
|
-
src = options[:src] = path_to_image(source)
|
206
|
-
|
207
|
-
unless src =~ /^(?:cid|data):/ || src.blank?
|
208
|
-
options[:alt] = options.fetch(:alt){ image_alt(src) }
|
209
|
-
end
|
210
|
-
|
211
|
-
if size = options.delete(:size)
|
212
|
-
options[:width], options[:height] = size.split("x") if size =~ %r{\A\d+x\d+\z}
|
213
|
-
options[:width] = options[:height] = size if size =~ %r{\A\d+\z}
|
214
|
-
end
|
215
|
-
|
216
|
-
tag("img", options)
|
217
|
-
end
|
218
|
-
|
219
|
-
# Returns a string suitable for an html image tag alt attribute.
|
220
|
-
# The +src+ argument is meant to be an image file path.
|
221
|
-
# The method removes the basename of the file path and the digest,
|
222
|
-
# if any. It also removes hyphens and underscores from file names and
|
223
|
-
# replaces them with spaces, returning a space-separated, titleized
|
224
|
-
# string.
|
225
|
-
#
|
226
|
-
# ==== Examples
|
227
|
-
#
|
228
|
-
# image_tag('rails.png')
|
229
|
-
# # => <img alt="Rails" src="/assets/rails.png" />
|
230
|
-
#
|
231
|
-
# image_tag('hyphenated-file-name.png')
|
232
|
-
# # => <img alt="Hyphenated file name" src="/assets/hyphenated-file-name.png" />
|
233
|
-
#
|
234
|
-
# image_tag('underscored_file_name.png')
|
235
|
-
# # => <img alt="Underscored file name" src="/assets/underscored_file_name.png" />
|
236
|
-
def image_alt(src)
|
237
|
-
File.basename(src, '.*').sub(/-[[:xdigit:]]{32}\z/, '').tr('-_', ' ').capitalize
|
238
|
-
end
|
239
|
-
|
240
|
-
# Returns an html video tag for the +sources+. If +sources+ is a string,
|
241
|
-
# a single video tag will be returned. If +sources+ is an array, a video
|
242
|
-
# tag with nested source tags for each source will be returned. The
|
243
|
-
# +sources+ can be full paths or files that exists in your public videos
|
244
|
-
# directory.
|
245
|
-
#
|
246
|
-
# ==== Options
|
247
|
-
# You can add HTML attributes using the +options+. The +options+ supports
|
248
|
-
# two additional keys for convenience and conformance:
|
249
|
-
#
|
250
|
-
# * <tt>:poster</tt> - Set an image (like a screenshot) to be shown
|
251
|
-
# before the video loads. The path is calculated like the +src+ of +image_tag+.
|
252
|
-
# * <tt>:size</tt> - Supplied as "{Width}x{Height}", so "30x45" becomes
|
253
|
-
# width="30" and height="45". <tt>:size</tt> will be ignored if the
|
254
|
-
# value is not in the correct format.
|
255
|
-
#
|
256
|
-
# ==== Examples
|
257
|
-
#
|
258
|
-
# video_tag("trailer")
|
259
|
-
# # => <video src="/videos/trailer" />
|
260
|
-
# video_tag("trailer.ogg")
|
261
|
-
# # => <video src="/videos/trailer.ogg" />
|
262
|
-
# video_tag("trailer.ogg", controls: true, autobuffer: true)
|
263
|
-
# # => <video autobuffer="autobuffer" controls="controls" src="/videos/trailer.ogg" />
|
264
|
-
# video_tag("trailer.m4v", size: "16x10", poster: "screenshot.png")
|
265
|
-
# # => <video src="/videos/trailer.m4v" width="16" height="10" poster="/assets/screenshot.png" />
|
266
|
-
# video_tag("/trailers/hd.avi", size: "16x16")
|
267
|
-
# # => <video src="/trailers/hd.avi" width="16" height="16" />
|
268
|
-
# video_tag("/trailers/hd.avi", height: '32', width: '32')
|
269
|
-
# # => <video height="32" src="/trailers/hd.avi" width="32" />
|
270
|
-
# video_tag("trailer.ogg", "trailer.flv")
|
271
|
-
# # => <video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
|
272
|
-
# video_tag(["trailer.ogg", "trailer.flv"])
|
273
|
-
# # => <video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
|
274
|
-
# video_tag(["trailer.ogg", "trailer.flv"], size: "160x120")
|
275
|
-
# # => <video height="120" width="160"><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
|
276
|
-
def video_tag(*sources)
|
277
|
-
multiple_sources_tag('video', sources) do |options|
|
278
|
-
options[:poster] = path_to_image(options[:poster]) if options[:poster]
|
279
|
-
|
280
|
-
if size = options.delete(:size)
|
281
|
-
options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
# Returns an HTML audio tag for the +source+.
|
287
|
-
# The +source+ can be full path or file that exists in
|
288
|
-
# your public audios directory.
|
289
|
-
#
|
290
|
-
# audio_tag("sound")
|
291
|
-
# # => <audio src="/audios/sound" />
|
292
|
-
# audio_tag("sound.wav")
|
293
|
-
# # => <audio src="/audios/sound.wav" />
|
294
|
-
# audio_tag("sound.wav", autoplay: true, controls: true)
|
295
|
-
# # => <audio autoplay="autoplay" controls="controls" src="/audios/sound.wav" />
|
296
|
-
# audio_tag("sound.wav", "sound.mid")
|
297
|
-
# # => <audio><source src="/audios/sound.wav" /><source src="/audios/sound.mid" /></audio>
|
298
|
-
def audio_tag(*sources)
|
299
|
-
multiple_sources_tag('audio', sources)
|
300
|
-
end
|
301
|
-
|
302
|
-
private
|
303
|
-
def multiple_sources_tag(type, sources)
|
304
|
-
options = sources.extract_options!.symbolize_keys
|
305
|
-
sources.flatten!
|
306
|
-
|
307
|
-
yield options if block_given?
|
308
|
-
|
309
|
-
if sources.size > 1
|
310
|
-
content_tag(type, options) do
|
311
|
-
safe_join sources.map { |source| tag("source", :src => send("path_to_#{type}", source)) }
|
312
|
-
end
|
313
|
-
else
|
314
|
-
options[:src] = send("path_to_#{type}", sources.first)
|
315
|
-
content_tag(type, nil, options)
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|