routing cleanup

This commit is contained in:
Thomas Reynolds 2011-11-08 15:38:15 -08:00
parent 45f18a6580
commit 553be5762c
4 changed files with 21 additions and 24 deletions

View file

@ -79,9 +79,10 @@ module Middleman
end end
module CoreExtensions module CoreExtensions
# Guard Proxy # File Change Notifier
autoload :FileWatcher, "middleman/core_extensions/file_watcher" autoload :FileWatcher, "middleman/core_extensions/file_watcher"
# In-memory Sitemap
autoload :Sitemap, "middleman/core_extensions/sitemap" autoload :Sitemap, "middleman/core_extensions/sitemap"
# Add Builder callbacks # Add Builder callbacks

View file

@ -1,5 +1,3 @@
# require 'sinatra/synchrony'
require "i18n" require "i18n"
require "hooks" require "hooks"
@ -12,6 +10,7 @@ module Middleman::Base
def registered(app) def registered(app)
app.send :include, ::Hooks app.send :include, ::Hooks
app.define_hook :initialized app.define_hook :initialized
app.extend ClassMethods app.extend ClassMethods
app.send :include, InstanceMethods app.send :include, InstanceMethods

View file

@ -2,13 +2,6 @@ module Middleman::CoreExtensions::Routing
class << self class << self
def registered(app) def registered(app)
app.extend ClassMethods app.extend ClassMethods
app.set :proxied_paths, {}
app.set :excluded_paths, []
app.build_reroute do |destination, request_path|
throw if app.settings.excluded_paths.include?(request_path)
end
end end
alias :included :registered alias :included :registered
end end
@ -17,7 +10,7 @@ module Middleman::CoreExtensions::Routing
def path_to_index(path) def path_to_index(path)
parts = path ? path.split('/') : [] parts = path ? path.split('/') : []
if parts.last.nil? || parts.last.split('.').length == 1 if parts.last.nil? || parts.last.split('.').length == 1
path = File.join(path, settings.index_file) path = File.join(path, index_file)
end end
path.gsub(%r{^/}, '') path.gsub(%r{^/}, '')
end end
@ -28,7 +21,7 @@ module Middleman::CoreExtensions::Routing
# page "/admin/login.html" # page "/admin/login.html"
# end # end
def with_layout(layout_name, &block) def with_layout(layout_name, &block)
old_layout = settings.layout old_layout = layout
set :layout, layout_name set :layout, layout_name
class_eval(&block) if block_given? class_eval(&block) if block_given?
@ -37,7 +30,7 @@ module Middleman::CoreExtensions::Routing
end end
def paths_for_url(url) def paths_for_url(url)
url = url.gsub(%r{\/#{settings.index_file}$}, "") url = url.gsub(%r{\/#{index_file}$}, "")
url = url.gsub(%r{(\/)$}, "") if url.length > 1 url = url.gsub(%r{(\/)$}, "") if url.length > 1
paths = [url] paths = [url]
@ -46,27 +39,22 @@ module Middleman::CoreExtensions::Routing
paths paths
end end
# Keep a path from building
def ignore(path)
settings.sitemap.ignore_path(path)
end
# The page method allows the layout to be set on a specific path # The page method allows the layout to be set on a specific path
# page "/about.html", :layout => false # page "/about.html", :layout => false
# page "/", :layout => :homepage_layout # page "/", :layout => :homepage_layout
def page(url, options={}, &block) def page(url, options={}, &block)
has_block = block_given? has_block = block_given?
options[:layout] = settings.layout if options[:layout].nil? options[:layout] = layout if options[:layout].nil?
if options.has_key?(:proxy) if options.has_key?(:proxy)
settings.sitemap.set_path(url, options[:proxy]) sitemap.set_path(url, options[:proxy])
if options.has_key?(:ignore) && options[:ignore] if options.has_key?(:ignore) && options[:ignore]
settings.ignore(options[:proxy]) ignore(options[:proxy])
end end
else else
if options.has_key?(:ignore) && options[:ignore] if options.has_key?(:ignore) && options[:ignore]
settings.ignore(url) ignore(url)
end end
end end

View file

@ -18,10 +18,19 @@ module Middleman::CoreExtensions::Sitemap
app.file_deleted do |file| app.file_deleted do |file|
sm.remove_file(file) sm.remove_file(file)
end end
app.extend ClassMethods
end end
alias :included :registered alias :included :registered
end end
module ClassMethods
# Keep a path from building
def ignore(path)
sitemap.ignore_path(path)
end
end
class SitemapStore class SitemapStore
def initialize def initialize
@map = {} @map = {}