mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use default order of PathResolver::EXTENSIONS for sort templates
This commit is contained in:
parent
4a477c0e4d
commit
e7c3eb11e0
3 changed files with 26 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
* `OptimizedFileSystemResolver` prefers template details in order of locale,
|
||||
formats, variants, handlers.
|
||||
|
||||
*Iago Pimenta*
|
||||
|
||||
* Added `class_names` helper to create a CSS class value with conditional classes.
|
||||
|
||||
*Joel Hawksley*, *Aaron Patterson*
|
||||
|
|
|
@ -335,7 +335,7 @@ module ActionView
|
|||
# We can use the matches found by the regex and sort by their index in
|
||||
# details.
|
||||
match = filename.match(regex)
|
||||
EXTENSIONS.keys.reverse.map do |ext|
|
||||
EXTENSIONS.keys.map do |ext|
|
||||
if ext == :variants && details[ext] == :any
|
||||
match[ext].nil? ? 0 : 1
|
||||
elsif match[ext].nil?
|
||||
|
|
|
@ -146,6 +146,26 @@ module ResolverSharedTests
|
|||
assert_same en[0], fr[1]
|
||||
end
|
||||
|
||||
def test_templates_sort_by_formats_json_first
|
||||
with_file "test/hello_world.html.erb", "Hello HTML!"
|
||||
with_file "test/hello_world.json.jbuilder", "Hello JSON!"
|
||||
|
||||
templates = resolver.find_all("hello_world", "test", false, locale: [], formats: [:json, :html], variants: :any, handlers: [:erb, :jbuilder])
|
||||
|
||||
assert_equal 2, templates.size
|
||||
assert_equal "Hello JSON!", templates[0].source
|
||||
end
|
||||
|
||||
def test_templates_sort_by_formats_html_first
|
||||
with_file "test/hello_world.html.erb", "Hello HTML!"
|
||||
with_file "test/hello_world.json.jbuilder", "Hello JSON!"
|
||||
|
||||
templates = resolver.find_all("hello_world", "test", false, locale: [], formats: [:html, :json], variants: :any, handlers: [:erb, :jbuilder])
|
||||
|
||||
assert_equal 2, templates.size
|
||||
assert_equal "Hello HTML!", templates[0].source
|
||||
end
|
||||
|
||||
def test_virtual_path_is_preserved_with_dot
|
||||
with_file "test/hello_world.html.erb", "Hello html!"
|
||||
|
||||
|
|
Loading…
Reference in a new issue