提交 e7c3eb11 编写于 作者: I Iago Pimenta 提交者: John Hawthorn

Use default order of PathResolver::EXTENSIONS for sort templates

上级 4a477c0e
* `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 @@ def find_template_paths_from_details(path, details)
# 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 @@ def test_templates_with_optional_locale_shares_common_object
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!"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册