Progress towards making localizable pages work
This commit is contained in:
parent
1345ae6e90
commit
d58acae939
3 changed files with 75 additions and 53 deletions
|
@ -187,39 +187,7 @@ module Middleman
|
|||
path = remove_templating_extensions(path)
|
||||
|
||||
# If there is no extension, look for one
|
||||
path = find_extension(path, file) if File.extname(path).empty?
|
||||
path
|
||||
end
|
||||
|
||||
# Removes the templating extensions, while keeping the others
|
||||
# @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
|
||||
|
||||
path
|
||||
end
|
||||
|
||||
# Finds an extension for path according to file's extension
|
||||
# @param [String] path without extension
|
||||
# @param [String] file path with original extensions
|
||||
def find_extension(path, file)
|
||||
input_ext = File.extname(file)
|
||||
|
||||
if !input_ext.empty?
|
||||
input_ext = input_ext.split(".").last.to_sym
|
||||
if @app.template_extensions.has_key?(input_ext)
|
||||
path << ".#{@app.template_extensions[input_ext]}"
|
||||
end
|
||||
end
|
||||
|
||||
path = find_extension(path, file) if File.extname(strip_away_locale(path)).empty?
|
||||
path
|
||||
end
|
||||
|
||||
|
@ -256,6 +224,53 @@ module Middleman
|
|||
@_lookup_by_destination_path = {}
|
||||
}
|
||||
end
|
||||
|
||||
# Removes the templating extensions, while keeping the others
|
||||
# @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
|
||||
|
||||
path
|
||||
end
|
||||
|
||||
# Remove the locale token from the end of the path
|
||||
# @param [String] path
|
||||
# @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
|
||||
end
|
||||
end
|
||||
|
||||
path
|
||||
end
|
||||
|
||||
# Finds an extension for path according to file's extension
|
||||
# @param [String] path without extension
|
||||
# @param [String] file path with original extensions
|
||||
def find_extension(path, file)
|
||||
input_ext = File.extname(file)
|
||||
|
||||
if !input_ext.empty?
|
||||
input_ext = input_ext.split(".").last.to_sym
|
||||
if @app.template_extensions.has_key?(input_ext)
|
||||
path << ".#{@app.template_extensions[input_ext]}"
|
||||
end
|
||||
end
|
||||
|
||||
path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue