actionview 4.2.10 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionview might be problematic. Click here for more details.

Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +141 -272
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +2 -3
  5. data/lib/action_view/base.rb +33 -21
  6. data/lib/action_view/buffers.rb +1 -1
  7. data/lib/action_view/context.rb +1 -1
  8. data/lib/action_view/dependency_tracker.rb +52 -20
  9. data/lib/action_view/digestor.rb +86 -83
  10. data/lib/action_view/flows.rb +9 -11
  11. data/lib/action_view/gem_version.rb +3 -3
  12. data/lib/action_view/helpers/active_model_helper.rb +8 -8
  13. data/lib/action_view/helpers/asset_tag_helper.rb +74 -38
  14. data/lib/action_view/helpers/asset_url_helper.rb +160 -59
  15. data/lib/action_view/helpers/atom_feed_helper.rb +16 -16
  16. data/lib/action_view/helpers/cache_helper.rb +90 -35
  17. data/lib/action_view/helpers/capture_helper.rb +7 -6
  18. data/lib/action_view/helpers/controller_helper.rb +3 -2
  19. data/lib/action_view/helpers/csrf_helper.rb +3 -3
  20. data/lib/action_view/helpers/date_helper.rb +156 -108
  21. data/lib/action_view/helpers/debug_helper.rb +3 -4
  22. data/lib/action_view/helpers/form_helper.rb +475 -94
  23. data/lib/action_view/helpers/form_options_helper.rb +87 -47
  24. data/lib/action_view/helpers/form_tag_helper.rb +88 -57
  25. data/lib/action_view/helpers/javascript_helper.rb +10 -10
  26. data/lib/action_view/helpers/number_helper.rb +76 -59
  27. data/lib/action_view/helpers/output_safety_helper.rb +34 -4
  28. data/lib/action_view/helpers/record_tag_helper.rb +12 -99
  29. data/lib/action_view/helpers/rendering_helper.rb +3 -3
  30. data/lib/action_view/helpers/sanitize_helper.rb +17 -14
  31. data/lib/action_view/helpers/tag_helper.rb +198 -73
  32. data/lib/action_view/helpers/tags/base.rb +132 -97
  33. data/lib/action_view/helpers/tags/check_box.rb +17 -17
  34. data/lib/action_view/helpers/tags/collection_check_boxes.rb +9 -33
  35. data/lib/action_view/helpers/tags/collection_helpers.rb +68 -36
  36. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +3 -11
  37. data/lib/action_view/helpers/tags/collection_select.rb +2 -2
  38. data/lib/action_view/helpers/tags/date_select.rb +36 -36
  39. data/lib/action_view/helpers/tags/datetime_field.rb +1 -1
  40. data/lib/action_view/helpers/tags/grouped_collection_select.rb +2 -2
  41. data/lib/action_view/helpers/tags/label.rb +5 -1
  42. data/lib/action_view/helpers/tags/password_field.rb +1 -1
  43. data/lib/action_view/helpers/tags/placeholderable.rb +1 -1
  44. data/lib/action_view/helpers/tags/radio_button.rb +4 -4
  45. data/lib/action_view/helpers/tags/search_field.rb +12 -9
  46. data/lib/action_view/helpers/tags/select.rb +9 -9
  47. data/lib/action_view/helpers/tags/text_area.rb +1 -1
  48. data/lib/action_view/helpers/tags/text_field.rb +5 -6
  49. data/lib/action_view/helpers/tags/translator.rb +15 -13
  50. data/lib/action_view/helpers/text_helper.rb +47 -30
  51. data/lib/action_view/helpers/translation_helper.rb +60 -30
  52. data/lib/action_view/helpers/url_helper.rb +132 -104
  53. data/lib/action_view/helpers.rb +1 -1
  54. data/lib/action_view/layouts.rb +59 -54
  55. data/lib/action_view/log_subscriber.rb +56 -7
  56. data/lib/action_view/lookup_context.rb +76 -61
  57. data/lib/action_view/model_naming.rb +1 -1
  58. data/lib/action_view/path_set.rb +28 -19
  59. data/lib/action_view/railtie.rb +30 -6
  60. data/lib/action_view/record_identifier.rb +51 -25
  61. data/lib/action_view/renderer/abstract_renderer.rb +19 -15
  62. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +55 -0
  63. data/lib/action_view/renderer/partial_renderer.rb +208 -206
  64. data/lib/action_view/renderer/renderer.rb +2 -6
  65. data/lib/action_view/renderer/streaming_template_renderer.rb +46 -48
  66. data/lib/action_view/renderer/template_renderer.rb +65 -66
  67. data/lib/action_view/rendering.rb +16 -9
  68. data/lib/action_view/routing_url_for.rb +25 -17
  69. data/lib/action_view/tasks/cache_digests.rake +23 -0
  70. data/lib/action_view/template/error.rb +14 -13
  71. data/lib/action_view/template/handlers/builder.rb +7 -7
  72. data/lib/action_view/template/handlers/erb/deprecated_erubis.rb +9 -0
  73. data/lib/action_view/template/handlers/erb/erubi.rb +81 -0
  74. data/lib/action_view/template/handlers/erb/erubis.rb +81 -0
  75. data/lib/action_view/template/handlers/erb.rb +9 -76
  76. data/lib/action_view/template/handlers/html.rb +9 -0
  77. data/lib/action_view/template/handlers/raw.rb +1 -3
  78. data/lib/action_view/template/handlers.rb +8 -6
  79. data/lib/action_view/template/html.rb +2 -4
  80. data/lib/action_view/template/resolver.rb +133 -109
  81. data/lib/action_view/template/text.rb +5 -8
  82. data/lib/action_view/template/types.rb +15 -17
  83. data/lib/action_view/template.rb +51 -28
  84. data/lib/action_view/test_case.rb +32 -27
  85. data/lib/action_view/testing/resolvers.rb +29 -31
  86. data/lib/action_view/version.rb +1 -1
  87. data/lib/action_view/view_paths.rb +26 -32
  88. data/lib/action_view.rb +5 -5
  89. data/lib/assets/compiled/rails-ujs.js +685 -0
  90. metadata +23 -23
  91. data/lib/action_view/tasks/dependencies.rake +0 -23
@@ -4,19 +4,16 @@ module ActionView #:nodoc:
4
4
  class Text #:nodoc:
5
5
  attr_accessor :type
6
6
 
7
- def initialize(string, type = nil)
7
+ def initialize(string)
8
8
  @string = string.to_s
9
- @type = Types[type] || type if type
10
- @type ||= Types[:text]
9
+ @type = Types[:text]
11
10
  end
12
11
 
13
12
  def identifier
14
- 'text template'
13
+ "text template"
15
14
  end
16
15
 
17
- def inspect
18
- 'text template'
19
- end
16
+ alias_method :inspect, :identifier
20
17
 
21
18
  def to_str
22
19
  @string
@@ -27,7 +24,7 @@ module ActionView #:nodoc:
27
24
  end
28
25
 
29
26
  def formats
30
- [@type.respond_to?(:ref) ? @type.ref : @type.to_s]
27
+ [@type.ref]
31
28
  end
32
29
  end
33
30
  end
@@ -1,23 +1,15 @@
1
- require 'set'
2
- require 'active_support/core_ext/module/attribute_accessors'
1
+ require "active_support/core_ext/module/attribute_accessors"
3
2
 
4
3
  module ActionView
5
4
  class Template
6
5
  class Types
7
6
  class Type
8
- cattr_accessor :types
9
- self.types = Set.new
10
-
11
- def self.register(*t)
12
- types.merge(t.map { |type| type.to_s })
13
- end
14
-
15
- register :html, :text, :js, :css, :xml, :json
7
+ SET = Struct.new(:symbols).new([ :html, :text, :js, :css, :xml, :json ])
16
8
 
17
9
  def self.[](type)
18
- return type if type.is_a?(self)
19
-
20
- if type.is_a?(Symbol) || types.member?(type.to_s)
10
+ if type.is_a?(self)
11
+ type
12
+ else
21
13
  new(type)
22
14
  end
23
15
  end
@@ -28,16 +20,18 @@ module ActionView
28
20
  @symbol = symbol.to_sym
29
21
  end
30
22
 
31
- delegate :to_s, :to_sym, :to => :symbol
23
+ def to_s
24
+ @symbol.to_s
25
+ end
32
26
  alias to_str to_s
33
27
 
34
28
  def ref
35
- to_sym || to_s
29
+ @symbol
36
30
  end
31
+ alias to_sym ref
37
32
 
38
33
  def ==(type)
39
- return false if type.blank?
40
- symbol.to_sym == type.to_sym
34
+ @symbol == type.to_sym unless type.blank?
41
35
  end
42
36
  end
43
37
 
@@ -52,6 +46,10 @@ module ActionView
52
46
  def self.[](type)
53
47
  type_klass[type]
54
48
  end
49
+
50
+ def self.symbols
51
+ type_klass::SET.symbols
52
+ end
55
53
  end
56
54
  end
57
55
  end
@@ -1,6 +1,6 @@
1
- require 'active_support/core_ext/object/try'
2
- require 'active_support/core_ext/kernel/singleton_class'
3
- require 'thread'
1
+ require "active_support/core_ext/object/try"
2
+ require "active_support/core_ext/kernel/singleton_class"
3
+ require "thread"
4
4
 
5
5
  module ActionView
6
6
  # = Action View Template
@@ -65,8 +65,7 @@ module ActionView
65
65
  # If you want to provide an alternate mechanism for
66
66
  # specifying encodings (like ERB does via <%# encoding: ... %>),
67
67
  # you may indicate that you will handle encodings yourself
68
- # by implementing <tt>self.handles_encoding?</tt>
69
- # on your handler.
68
+ # by implementing <tt>handles_encoding?</tt> on your handler.
70
69
  #
71
70
  # If you do, Rails will not try to encode the String
72
71
  # into the default_internal, passing you the unaltered
@@ -87,6 +86,19 @@ module ActionView
87
86
  # expected_encoding
88
87
  # )
89
88
 
89
+ ##
90
+ # :method: local_assigns
91
+ #
92
+ # Returns a hash with the defined local variables.
93
+ #
94
+ # Given this sub template rendering:
95
+ #
96
+ # <%= render "shared/header", { headline: "Welcome", person: person } %>
97
+ #
98
+ # You can use +local_assigns+ in the sub templates to access the local variables:
99
+ #
100
+ # local_assigns[:headline] # => "Welcome"
101
+
90
102
  eager_autoload do
91
103
  autoload :Error
92
104
  autoload :Handlers
@@ -103,7 +115,7 @@ module ActionView
103
115
 
104
116
  # This finalizer is needed (and exactly with a proc inside another proc)
105
117
  # otherwise templates leak in development.
106
- Finalizer = proc do |method_name, mod|
118
+ Finalizer = proc do |method_name, mod| # :nodoc:
107
119
  proc do
108
120
  mod.module_eval do
109
121
  remove_possible_method method_name
@@ -127,8 +139,8 @@ module ActionView
127
139
  @compile_mutex = Mutex.new
128
140
  end
129
141
 
130
- # Returns if the underlying handler supports streaming. If so,
131
- # a streaming buffer *may* be passed when it start rendering.
142
+ # Returns whether the underlying handler supports streaming. If so,
143
+ # a streaming buffer *may* be passed when it starts rendering.
132
144
  def supports_streaming?
133
145
  handler.respond_to?(:supports_streaming?) && handler.supports_streaming?
134
146
  end
@@ -139,8 +151,8 @@ module ActionView
139
151
  # This method is instrumented as "!render_template.action_view". Notice that
140
152
  # we use a bang in this instrumentation because you don't want to
141
153
  # consume this in production. This is only slow if it's being listened to.
142
- def render(view, locals, buffer=nil, &block)
143
- instrument("!render_template") do
154
+ def render(view, locals, buffer = nil, &block)
155
+ instrument_render_template do
144
156
  compile!(view)
145
157
  view.send(method_name, locals, buffer, &block)
146
158
  end
@@ -167,12 +179,12 @@ module ActionView
167
179
  name = pieces.pop
168
180
  partial = !!name.sub!(/^_/, "")
169
181
  lookup.disable_cache do
170
- lookup.find_template(name, [ pieces.join('/') ], partial, @locals)
182
+ lookup.find_template(name, [ pieces.join("/") ], partial, @locals)
171
183
  end
172
184
  end
173
185
 
174
186
  def inspect
175
- @inspect ||= defined?(Rails.root) ? identifier.sub("#{Rails.root}/", '') : identifier
187
+ @inspect ||= defined?(Rails.root) ? identifier.sub("#{Rails.root}/", "".freeze) : identifier
176
188
  end
177
189
 
178
190
  # This method is responsible for properly setting the encoding of the
@@ -191,7 +203,7 @@ module ActionView
191
203
  # Look for # encoding: *. If we find one, we'll encode the
192
204
  # String in that encoding, otherwise, we'll use the
193
205
  # default external encoding.
194
- if source.sub!(/\A#{ENCODING_FLAG}/, '')
206
+ if source.sub!(/\A#{ENCODING_FLAG}/, "")
195
207
  encoding = magic_encoding = $1
196
208
  else
197
209
  encoding = Encoding.default_external
@@ -219,11 +231,11 @@ module ActionView
219
231
  end
220
232
  end
221
233
 
222
- protected
234
+ private
223
235
 
224
236
  # Compile a template. This method ensures a template is compiled
225
237
  # just once and removes the source after it is compiled.
226
- def compile!(view) #:nodoc:
238
+ def compile!(view)
227
239
  return if @compiled
228
240
 
229
241
  # Templates can be used concurrently in threaded environments
@@ -264,9 +276,8 @@ module ActionView
264
276
  # encode the source into <tt>Encoding.default_internal</tt>.
265
277
  # In general, this means that templates will be UTF-8 inside of Rails,
266
278
  # regardless of the original source encoding.
267
- def compile(mod) #:nodoc:
279
+ def compile(mod)
268
280
  encode!
269
- method_name = self.method_name
270
281
  code = @handler.call(self)
271
282
 
272
283
  # Make sure that the resulting String to be eval'd is in the
@@ -297,7 +308,7 @@ module ActionView
297
308
  ObjectSpace.define_finalizer(self, Finalizer[method_name, mod])
298
309
  end
299
310
 
300
- def handle_render_error(view, e) #:nodoc:
311
+ def handle_render_error(view, e)
301
312
  if e.is_a?(Template::Error)
302
313
  e.sub_template_of(self)
303
314
  raise e
@@ -307,30 +318,42 @@ module ActionView
307
318
  template = refresh(view)
308
319
  template.encode!
309
320
  end
310
- raise Template::Error.new(template, e)
321
+ raise Template::Error.new(template)
311
322
  end
312
323
  end
313
324
 
314
- def locals_code #:nodoc:
325
+ def locals_code
326
+ # Only locals with valid variable names get set directly. Others will
327
+ # still be available in local_assigns.
328
+ locals = @locals - Module::RUBY_RESERVED_KEYWORDS
329
+ locals = locals.grep(/\A@?(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
330
+
315
331
  # Double assign to suppress the dreaded 'assigned but unused variable' warning
316
- @locals.each_with_object('') { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" }
332
+ locals.each_with_object("") { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" }
317
333
  end
318
334
 
319
- def method_name #:nodoc:
335
+ def method_name
320
336
  @method_name ||= begin
321
337
  m = "_#{identifier_method_name}__#{@identifier.hash}_#{__id__}"
322
- m.tr!('-', '_')
338
+ m.tr!("-".freeze, "_".freeze)
323
339
  m
324
340
  end
325
341
  end
326
342
 
327
- def identifier_method_name #:nodoc:
328
- inspect.tr('^a-z_', '_')
343
+ def identifier_method_name
344
+ inspect.tr("^a-z_".freeze, "_".freeze)
345
+ end
346
+
347
+ def instrument(action, &block) # :doc:
348
+ ActiveSupport::Notifications.instrument("#{action}.action_view", instrument_payload, &block)
349
+ end
350
+
351
+ def instrument_render_template(&block)
352
+ ActiveSupport::Notifications.instrument("!render_template.action_view".freeze, instrument_payload, &block)
329
353
  end
330
354
 
331
- def instrument(action, &block)
332
- payload = { virtual_path: @virtual_path, identifier: @identifier }
333
- ActiveSupport::Notifications.instrument("#{action}.action_view", payload, &block)
355
+ def instrument_payload
356
+ { virtual_path: @virtual_path, identifier: @identifier }
334
357
  end
335
358
  end
336
359
  end
@@ -1,9 +1,9 @@
1
- require 'active_support/core_ext/module/remove_method'
2
- require 'action_controller'
3
- require 'action_controller/test_case'
4
- require 'action_view'
1
+ require "active_support/core_ext/module/remove_method"
2
+ require "action_controller"
3
+ require "action_controller/test_case"
4
+ require "action_view"
5
5
 
6
- require 'rails-dom-testing'
6
+ require "rails-dom-testing"
7
7
 
8
8
  module ActionView
9
9
  # = Action View Test Case
@@ -18,17 +18,17 @@ module ActionView
18
18
  end
19
19
 
20
20
  def controller_path=(path)
21
- self.class.controller_path=(path)
21
+ self.class.controller_path = (path)
22
22
  end
23
23
 
24
24
  def initialize
25
25
  super
26
26
  self.class.controller_path = ""
27
- @request = ActionController::TestRequest.new
28
- @response = ActionController::TestResponse.new
27
+ @request = ActionController::TestRequest.create(self.class)
28
+ @response = ActionDispatch::TestResponse.new
29
29
 
30
- @request.env.delete('PATH_INFO')
31
- @params = {}
30
+ @request.env.delete("PATH_INFO")
31
+ @params = ActionController::Parameters.new
32
32
  end
33
33
  end
34
34
 
@@ -49,7 +49,7 @@ module ActionView
49
49
 
50
50
  include ActiveSupport::Testing::ConstantLookup
51
51
 
52
- delegate :lookup_context, :to => :controller
52
+ delegate :lookup_context, to: :controller
53
53
  attr_accessor :controller, :output_buffer, :rendered
54
54
 
55
55
  module ClassMethods
@@ -96,7 +96,6 @@ module ActionView
96
96
  helper(helper_class) if helper_class
97
97
  include _helpers
98
98
  end
99
-
100
99
  end
101
100
 
102
101
  def setup_with_controller
@@ -104,8 +103,8 @@ module ActionView
104
103
  @request = @controller.request
105
104
  # empty string ensures buffer has UTF-8 encoding as
106
105
  # new without arguments returns ASCII-8BIT encoded buffer like String#new
107
- @output_buffer = ActiveSupport::SafeBuffer.new ''
108
- @rendered = ''
106
+ @output_buffer = ActiveSupport::SafeBuffer.new ""
107
+ @rendered = ""
109
108
 
110
109
  make_test_case_available_to_view!
111
110
  say_no_to_protect_against_forgery!
@@ -125,6 +124,10 @@ module ActionView
125
124
  @_rendered_views ||= RenderedViewsCollection.new
126
125
  end
127
126
 
127
+ def _routes
128
+ @controller._routes if @controller.respond_to?(:_routes)
129
+ end
130
+
128
131
  # Need to experiment if this priority is the best one: rendered => output_buffer
129
132
  class RenderedViewsCollection
130
133
  def initialize
@@ -146,13 +149,14 @@ module ActionView
146
149
 
147
150
  def view_rendered?(view, expected_locals)
148
151
  locals_for(view).any? do |actual_locals|
149
- expected_locals.all? {|key, value| value == actual_locals[key] }
152
+ expected_locals.all? { |key, value| value == actual_locals[key] }
150
153
  end
151
154
  end
152
155
  end
153
156
 
154
157
  included do
155
158
  setup :setup_with_controller
159
+ ActiveSupport.run_load_hooks(:action_view_test_case, self)
156
160
  end
157
161
 
158
162
  private
@@ -204,10 +208,10 @@ module ActionView
204
208
  def view
205
209
  @view ||= begin
206
210
  view = @controller.view_context
207
- view.singleton_class.send :include, _helpers
211
+ view.singleton_class.include(_helpers)
208
212
  view.extend(Locals)
209
- view.rendered_views = self.rendered_views
210
- view.output_buffer = self.output_buffer
213
+ view.rendered_views = rendered_views
214
+ view.output_buffer = output_buffer
211
215
  view
212
216
  end
213
217
  end
@@ -241,8 +245,7 @@ module ActionView
241
245
  :@view,
242
246
  :@view_context_class,
243
247
  :@_subscribers,
244
- :@html_document,
245
- :@html_scanner_document
248
+ :@html_document
246
249
  ]
247
250
 
248
251
  def _user_defined_ivars
@@ -259,14 +262,16 @@ module ActionView
259
262
  end]
260
263
  end
261
264
 
262
- def _routes
263
- @controller._routes if @controller.respond_to?(:_routes)
264
- end
265
-
266
265
  def method_missing(selector, *args)
267
- if @controller.respond_to?(:_routes) &&
268
- ( @controller._routes.named_routes.route_defined?(selector) ||
269
- @controller._routes.mounted_helpers.method_defined?(selector) )
266
+ begin
267
+ routes = @controller.respond_to?(:_routes) && @controller._routes
268
+ rescue
269
+ # Dont call routes, if there is an error on _routes call
270
+ end
271
+
272
+ if routes &&
273
+ (routes.named_routes.route_defined?(selector) ||
274
+ routes.mounted_helpers.method_defined?(selector))
270
275
  @controller.__send__(selector, *args)
271
276
  else
272
277
  super
@@ -1,4 +1,4 @@
1
- require 'action_view/template/resolver'
1
+ require "action_view/template/resolver"
2
2
 
3
3
  module ActionView #:nodoc:
4
4
  # Use FixtureResolver in your tests to simulate the presence of files on the
@@ -8,47 +8,45 @@ module ActionView #:nodoc:
8
8
  class FixtureResolver < PathResolver
9
9
  attr_reader :hash
10
10
 
11
- def initialize(hash = {}, pattern=nil)
11
+ def initialize(hash = {}, pattern = nil)
12
12
  super(pattern)
13
13
  @hash = hash
14
14
  end
15
15
 
16
16
  def to_s
17
- @hash.keys.join(', ')
17
+ @hash.keys.join(", ")
18
18
  end
19
19
 
20
- private
21
-
22
- def query(path, exts, formats, _)
23
- query = ""
24
- EXTENSIONS.each_key do |ext|
25
- query << '(' << exts[ext].map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)'
26
- end
27
- query = /^(#{Regexp.escape(path)})#{query}$/
28
-
29
- templates = []
30
- @hash.each do |_path, array|
31
- source, updated_at = array
32
- next unless _path =~ query
33
- handler, format, variant = extract_handler_and_format_and_variant(_path, formats)
34
- templates << Template.new(source, _path, handler,
35
- :virtual_path => path.virtual,
36
- :format => format,
37
- :variant => variant,
38
- :updated_at => updated_at
39
- )
20
+ private
21
+
22
+ def query(path, exts, _, _)
23
+ query = ""
24
+ EXTENSIONS.each_key do |ext|
25
+ query << "(" << exts[ext].map { |e| e && Regexp.escape(".#{e}") }.join("|") << "|)"
26
+ end
27
+ query = /^(#{Regexp.escape(path)})#{query}$/
28
+
29
+ templates = []
30
+ @hash.each do |_path, array|
31
+ source, updated_at = array
32
+ next unless query.match?(_path)
33
+ handler, format, variant = extract_handler_and_format_and_variant(_path)
34
+ templates << Template.new(source, _path, handler,
35
+ virtual_path: path.virtual,
36
+ format: format,
37
+ variant: variant,
38
+ updated_at: updated_at
39
+ )
40
+ end
41
+
42
+ templates.sort_by { |t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
40
43
  end
41
-
42
- templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
43
- end
44
44
  end
45
45
 
46
46
  class NullResolver < PathResolver
47
- def query(path, exts, formats, _)
48
- handler, format, variant = extract_handler_and_format_and_variant(path, formats)
49
- [ActionView::Template.new("Template generated by Null Resolver", path, handler, :virtual_path => path, :format => format, :variant => variant)]
47
+ def query(path, exts, _, _)
48
+ handler, format, variant = extract_handler_and_format_and_variant(path)
49
+ [ActionView::Template.new("Template generated by Null Resolver", path.virtual, handler, virtual_path: path.virtual, format: format, variant: variant)]
50
50
  end
51
51
  end
52
-
53
52
  end
54
-
@@ -1,4 +1,4 @@
1
- require_relative 'gem_version'
1
+ require_relative "gem_version"
2
2
 
3
3
  module ActionView
4
4
  # Returns the version of the currently loaded ActionView as a <tt>Gem::Version</tt>
@@ -1,5 +1,3 @@
1
- require 'action_view/base'
2
-
3
1
  module ActionView
4
2
  module ViewPaths
5
3
  extend ActiveSupport::Concern
@@ -7,44 +5,28 @@ module ActionView
7
5
  included do
8
6
  class_attribute :_view_paths
9
7
  self._view_paths = ActionView::PathSet.new
10
- self._view_paths.freeze
8
+ _view_paths.freeze
11
9
  end
12
10
 
13
- delegate :template_exists?, :view_paths, :formats, :formats=,
14
- :locale, :locale=, :to => :lookup_context
11
+ delegate :template_exists?, :any_templates?, :view_paths, :formats, :formats=,
12
+ :locale, :locale=, to: :lookup_context
15
13
 
16
14
  module ClassMethods
17
15
  def _prefixes # :nodoc:
18
16
  @_prefixes ||= begin
19
- deprecated_prefixes = handle_deprecated_parent_prefixes
20
- if deprecated_prefixes
21
- deprecated_prefixes
22
- else
23
- return local_prefixes if superclass.abstract?
17
+ return local_prefixes if superclass.abstract?
24
18
 
25
- local_prefixes + superclass._prefixes
26
- end
19
+ local_prefixes + superclass._prefixes
27
20
  end
28
21
  end
29
22
 
30
23
  private
31
24
 
32
- # Override this method in your controller if you want to change paths prefixes for finding views.
33
- # Prefixes defined here will still be added to parents' <tt>._prefixes</tt>.
34
- def local_prefixes
35
- [controller_path]
36
- end
37
-
38
- def handle_deprecated_parent_prefixes # TODO: remove in 4.3/5.0.
39
- return unless respond_to?(:parent_prefixes)
40
-
41
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
42
- Overriding `ActionController::Base::parent_prefixes` is deprecated,
43
- override `.local_prefixes` instead.
44
- MSG
45
-
46
- local_prefixes + parent_prefixes
47
- end
25
+ # Override this method in your controller if you want to change paths prefixes for finding views.
26
+ # Prefixes defined here will still be added to parents' <tt>._prefixes</tt>.
27
+ def local_prefixes
28
+ [controller_path]
29
+ end
48
30
  end
49
31
 
50
32
  # The prefixes used in render "foo" shortcuts.
@@ -52,22 +34,34 @@ module ActionView
52
34
  self.class._prefixes
53
35
  end
54
36
 
55
- # LookupContext is the object responsible to hold all information required to lookup
56
- # templates, i.e. view paths and details. Check ActionView::LookupContext for more
57
- # information.
37
+ # <tt>LookupContext</tt> is the object responsible for holding all
38
+ # information required for looking up templates, i.e. view paths and
39
+ # details. Check <tt>ActionView::LookupContext</tt> for more information.
58
40
  def lookup_context
59
41
  @_lookup_context ||=
60
42
  ActionView::LookupContext.new(self.class._view_paths, details_for_lookup, _prefixes)
61
43
  end
62
44
 
63
45
  def details_for_lookup
64
- { }
46
+ {}
65
47
  end
66
48
 
49
+ # Append a path to the list of view paths for the current <tt>LookupContext</tt>.
50
+ #
51
+ # ==== Parameters
52
+ # * <tt>path</tt> - If a String is provided, it gets converted into
53
+ # the default view path. You may also provide a custom view path
54
+ # (see ActionView::PathSet for more information)
67
55
  def append_view_path(path)
68
56
  lookup_context.view_paths.push(*path)
69
57
  end
70
58
 
59
+ # Prepend a path to the list of view paths for the current <tt>LookupContext</tt>.
60
+ #
61
+ # ==== Parameters
62
+ # * <tt>path</tt> - If a String is provided, it gets converted into
63
+ # the default view path. You may also provide a custom view path
64
+ # (see ActionView::PathSet for more information)
71
65
  def prepend_view_path(path)
72
66
  lookup_context.view_paths.unshift(*path)
73
67
  end
data/lib/action_view.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2004-2014 David Heinemeier Hansson
2
+ # Copyright (c) 2004-2017 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -21,9 +21,9 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- require 'active_support'
25
- require 'active_support/rails'
26
- require 'action_view/version'
24
+ require "active_support"
25
+ require "active_support/rails"
26
+ require "action_view/version"
27
27
 
28
28
  module ActionView
29
29
  extend ActiveSupport::Autoload
@@ -89,7 +89,7 @@ module ActionView
89
89
  end
90
90
  end
91
91
 
92
- require 'active_support/core_ext/string/output_safety'
92
+ require "active_support/core_ext/string/output_safety"
93
93
 
94
94
  ActiveSupport.on_load(:i18n) do
95
95
  I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"