Fixups for localizable files

This commit is contained in:
Ben Hollis 2013-05-02 22:03:28 -07:00
parent d58acae939
commit 5970333ca2
2 changed files with 18 additions and 21 deletions

View file

@ -229,15 +229,8 @@ module Middleman
# @param [String] path
# @return [String]
def remove_templating_extensions(path)
end_of_the_line = false
while !end_of_the_line
if !::Tilt[path].nil?
path = path.sub(File.extname(path), "")
else
end_of_the_line = true
end
end
# Strip templating extensions as long as Tilt knows them
path = path.sub(File.extname(path), "") while ::Tilt[path]
path
end
@ -246,10 +239,10 @@ module Middleman
# @return [String]
def strip_away_locale(path)
if app.respond_to? :langs
path.match(/([^.\/]+)\.([^.]+)$/) do |m|
if app.langs.include?(m[2].to_sym)
return m[1]
end
path_bits = path.split('.')
lang = path_bits.last
if app.langs.include?(lang.to_sym)
return path_bits[0..-1].join('.')
end
end

View file

@ -118,7 +118,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
path = resource.path.sub(options[:templates_dir], "")
new_resources << build_resource(path, resource.path, page_id, lang)
end
elsif m = result = parse_locale_extension(resource.path)
elsif result = parse_locale_extension(resource.path)
lang, path, page_id = result
new_resources << build_resource(path, resource.path, page_id, lang)
end
@ -130,15 +130,19 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
private
# Parse locale extension filename
# @return [locale, path, basename]
# @return [lang, path, basename]
# will return +nil+ if no locale extension
def parse_locale_extension(path)
path.match(/([^.\/]+)\.([^.]+)$/) do |m|
locale = m[2].to_sym
path = m[1]
basename = File.basename(path)
langs.include?(locale) ? [locale, path, basename] : nil
end
path_bits = path.split('.')
return nil if path_bits.size < 3
lang = path_bits.delete_at(-2).to_sym
return nil unless langs.include?(lang)
path = path_bits.join('.')
basename = File.basename(path_bits[0..-2].join('.'))
[lang, path, basename]
end
def build_resource(path, source_path, page_id, lang)