Store#extensionless_path: Change implementation to make overrides easier

This commit is contained in:
Jonathan Allard 2013-03-15 11:04:14 -04:00 committed by Ben Hollis
parent 0211114ecb
commit 23b6efbb06

View file

@ -184,7 +184,17 @@ module Middleman
# @return [String] # @return [String]
def extensionless_path(file) def extensionless_path(file)
path = file.dup path = file.dup
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 end_of_the_line = false
while !end_of_the_line while !end_of_the_line
if !::Tilt[path].nil? if !::Tilt[path].nil?
@ -194,8 +204,13 @@ module Middleman
end end
end end
# If there is no extension, look for one path
if File.extname(path).empty? 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) input_ext = File.extname(file)
if !input_ext.empty? if !input_ext.empty?
@ -204,7 +219,6 @@ module Middleman
path << ".#{@app.template_extensions[input_ext]}" path << ".#{@app.template_extensions[input_ext]}"
end end
end end
end
path path
end end