From 23b6efbb06bea0db484e9b70b8e3d8e5f0527f7f Mon Sep 17 00:00:00 2001 From: Jonathan Allard Date: Fri, 15 Mar 2013 11:04:14 -0400 Subject: [PATCH] Store#extensionless_path: Change implementation to make overrides easier --- .../lib/middleman-core/sitemap/store.rb | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index 935e051b..4f6831c2 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -184,7 +184,17 @@ module Middleman # @return [String] def extensionless_path(file) 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 while !end_of_the_line if !::Tilt[path].nil? @@ -194,15 +204,19 @@ module Middleman end end - # If there is no extension, look for one - if File.extname(path).empty? - input_ext = File.extname(file) + path + end - 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 + # 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