Sitemap refactor

This commit is contained in:
Thomas Reynolds 2012-04-04 18:26:07 +01:00
parent db0febe2f0
commit d935aedd59
26 changed files with 907 additions and 730 deletions

View file

@ -95,16 +95,16 @@ module Middleman::Cli
# Ignore following method
desc "", "", :hide => true
# Render a page to a file.
# Render a resource to a file.
#
# @param [Middleman::Sitemap::Page] page
# @param [Middleman::Sitemap::Resource] resource
# @return [String] The full path of the file that was written
def render_to_file(page)
def render_to_file(resource)
build_dir = self.class.shared_instance.build_dir
output_file = File.join(build_dir, page.destination_path)
output_file = File.join(build_dir, resource.destination_path)
begin
response = self.class.shared_rack.get(page.request_path.gsub(/\s/, "%20"))
response = self.class.shared_rack.get(resource.destination_path.gsub(/\s/, "%20"))
if response.status == 200
create_file(output_file, response.body, { :force => true })
else
@ -196,10 +196,10 @@ module Middleman::Cli
sort_order = %w(.png .jpeg .jpg .gif .bmp .svg .svgz .ico .woff .otf .ttf .eot .js .css)
# Pre-request CSS to give Compass a chance to build sprites
@app.sitemap.pages.select do |p|
p.ext == ".css"
end.each do |p|
Middleman::Cli::Build.shared_rack.get(p.request_path.gsub(/\s/, "%20"))
@app.sitemap.resources.select do |resource|
resource.ext == ".css"
end.each do |resource|
Middleman::Cli::Build.shared_rack.get(resource.destination_path.gsub(/\s/, "%20"))
end
# Double-check for compass sprites
@ -209,7 +209,7 @@ module Middleman::Cli
# find files in the build folder when it needs to generate sprites for the
# css files
pages = @app.sitemap.pages.sort do |a, b|
resources = @app.sitemap.resources.sort do |a, b|
a_idx = sort_order.index(a.ext) || 100
b_idx = sort_order.index(b.ext) || 100
@ -217,11 +217,10 @@ module Middleman::Cli
end
# Loop over all the paths and build them.
pages.each do |page|
next if page.ignored?
next if @config[:glob] && !File.fnmatch(@config[:glob], page.path)
resources.each do |resource|
next if @config[:glob] && !File.fnmatch(@config[:glob], resource.destination_path)
output_path = base.render_to_file(page)
output_path = base.render_to_file(resource)
@cleaning_queue.delete(Pathname.new(output_path).realpath) if cleaning?
end