aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorthedarkone <thedarkone2@gmail.com>2009-03-24 10:48:47 -0500
committerJoshua Peek <josh@joshpeek.com>2009-03-24 10:54:18 -0500
commitae9f258e03c9fd5088da12c1c6cd216cc89a01f7 (patch)
treef9abd9c79ba8d8697712f58049abf655a1cf1e51 /actionpack/lib/action_view
parente3b166aab37ddc2fbab030b146eb61713b91bf55 (diff)
downloadrails-ae9f258e03c9fd5088da12c1c6cd216cc89a01f7.tar.gz
rails-ae9f258e03c9fd5088da12c1c6cd216cc89a01f7.tar.bz2
rails-ae9f258e03c9fd5088da12c1c6cd216cc89a01f7.zip
Fix template extension parsing. [#2315 state:resolved] [#2284 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/template.rb44
1 files changed, 14 insertions, 30 deletions
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index 4497c4ac32..a974f2652b 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -217,46 +217,30 @@ module ActionView #:nodoc:
end
def valid_locale?(locale)
- I18n.available_locales.include?(locale.to_sym)
+ locale && I18n.available_locales.include?(locale.to_sym)
end
# Returns file split into an array
# [base_path, name, locale, format, extension]
def split(file)
if m = file.to_s.match(/^(.*\/)?([^\.]+)\.(.*)$/)
- base_path = m[1]
- name = m[2]
- extensions = m[3]
- else
- return
+ [m[1], m[2], *parse_extensions(m[3])]
end
+ end
- locale = nil
- format = nil
- extension = nil
-
- if m = extensions.split(".")
- if valid_locale?(m[0]) && m[1] && valid_extension?(m[2]) # All three
- locale = m[0]
- format = m[1]
- extension = m[2]
- elsif m[0] && m[1] && valid_extension?(m[2]) # Multipart formats
- format = "#{m[0]}.#{m[1]}"
- extension = m[2]
- elsif valid_locale?(m[0]) && valid_extension?(m[1]) # locale and extension
- locale = m[0]
- extension = m[1]
- elsif valid_extension?(m[1]) # format and extension
- format = m[0]
- extension = m[1]
- elsif valid_extension?(m[0]) # Just extension
- extension = m[0]
- else # No extension
- format = m[0]
- end
+ # returns parsed extensions as an array
+ # [locale, format, extension]
+ def parse_extensions(extensions)
+ exts = extensions.split(".")
+
+ if extension = valid_extension?(exts.last) && exts.pop || nil
+ locale = valid_locale?(exts.first) && exts.shift || nil
+ format = exts.join('.') if exts.any? # join('.') is needed for multipart templates
+ else # no extension, just format
+ format = exts.last
end
- [base_path, name, locale, format, extension]
+ [locale, format, extension]
end
end
end