Fixups for localizable files
This commit is contained in:
parent
d58acae939
commit
5970333ca2
|
@ -229,15 +229,8 @@ module Middleman
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def remove_templating_extensions(path)
|
def remove_templating_extensions(path)
|
||||||
end_of_the_line = false
|
# Strip templating extensions as long as Tilt knows them
|
||||||
while !end_of_the_line
|
path = path.sub(File.extname(path), "") while ::Tilt[path]
|
||||||
if !::Tilt[path].nil?
|
|
||||||
path = path.sub(File.extname(path), "")
|
|
||||||
else
|
|
||||||
end_of_the_line = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -246,10 +239,10 @@ module Middleman
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def strip_away_locale(path)
|
def strip_away_locale(path)
|
||||||
if app.respond_to? :langs
|
if app.respond_to? :langs
|
||||||
path.match(/([^.\/]+)\.([^.]+)$/) do |m|
|
path_bits = path.split('.')
|
||||||
if app.langs.include?(m[2].to_sym)
|
lang = path_bits.last
|
||||||
return m[1]
|
if app.langs.include?(lang.to_sym)
|
||||||
end
|
return path_bits[0..-1].join('.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
path = resource.path.sub(options[:templates_dir], "")
|
path = resource.path.sub(options[:templates_dir], "")
|
||||||
new_resources << build_resource(path, resource.path, page_id, lang)
|
new_resources << build_resource(path, resource.path, page_id, lang)
|
||||||
end
|
end
|
||||||
elsif m = result = parse_locale_extension(resource.path)
|
elsif result = parse_locale_extension(resource.path)
|
||||||
lang, path, page_id = result
|
lang, path, page_id = result
|
||||||
new_resources << build_resource(path, resource.path, page_id, lang)
|
new_resources << build_resource(path, resource.path, page_id, lang)
|
||||||
end
|
end
|
||||||
|
@ -130,15 +130,19 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
private
|
private
|
||||||
|
|
||||||
# Parse locale extension filename
|
# Parse locale extension filename
|
||||||
# @return [locale, path, basename]
|
# @return [lang, path, basename]
|
||||||
# will return +nil+ if no locale extension
|
# will return +nil+ if no locale extension
|
||||||
def parse_locale_extension(path)
|
def parse_locale_extension(path)
|
||||||
path.match(/([^.\/]+)\.([^.]+)$/) do |m|
|
path_bits = path.split('.')
|
||||||
locale = m[2].to_sym
|
return nil if path_bits.size < 3
|
||||||
path = m[1]
|
|
||||||
basename = File.basename(path)
|
lang = path_bits.delete_at(-2).to_sym
|
||||||
langs.include?(locale) ? [locale, path, basename] : nil
|
return nil unless langs.include?(lang)
|
||||||
end
|
|
||||||
|
path = path_bits.join('.')
|
||||||
|
basename = File.basename(path_bits[0..-2].join('.'))
|
||||||
|
|
||||||
|
[lang, path, basename]
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_resource(path, source_path, page_id, lang)
|
def build_resource(path, source_path, page_id, lang)
|
||||||
|
|
Loading…
Reference in a new issue