queue sitemap changes until after first run

This commit is contained in:
Thomas Reynolds 2011-11-08 16:04:53 -08:00
parent d72200dc5e
commit 36df6300cd
2 changed files with 30 additions and 2 deletions

View file

@ -47,7 +47,7 @@ module Middleman::CoreExtensions::Routing
options[:layout] = layout if options[:layout].nil?
if options.has_key?(:proxy)
sitemap.set_path(url, options[:proxy])
reroute(url, options[:proxy])
if options.has_key?(:ignore) && options[:ignore]
ignore(options[:proxy])

View file

@ -1,4 +1,5 @@
require 'find'
require 'hooks'
module Middleman::CoreExtensions::Sitemap
class << self
@ -27,16 +28,36 @@ module Middleman::CoreExtensions::Sitemap
module ClassMethods
# Keep a path from building
def ignore(path)
sitemap.ignore_path(path)
action = Proc.new { ignore_path(path) }
if sitemap.setup?
action.call
else
sitemap.class.after_setup(&action)
end
end
def reroute(url, target)
action = Proc.new { set_path(url, target) }
if sitemap.setup?
action.call
else
sitemap.class.after_setup(&action)
end
end
end
class SitemapStore
include ::Hooks
define_hook :after_setup
def initialize
@map = {}
@ignored_paths = false
@generic_paths = false
@proxied_paths = false
@is_setup = false
end
def setup(app)
@ -44,6 +65,13 @@ module Middleman::CoreExtensions::Sitemap
@source = File.expand_path(@app.views, @app.root)
build_static_map
run_hook :after_setup
@is_setup = true
end
def setup?
@is_setup
end
# Check to see if we know about a specific path