routing cleanup
This commit is contained in:
parent
45f18a6580
commit
553be5762c
|
@ -79,9 +79,10 @@ module Middleman
|
|||
end
|
||||
|
||||
module CoreExtensions
|
||||
# Guard Proxy
|
||||
# File Change Notifier
|
||||
autoload :FileWatcher, "middleman/core_extensions/file_watcher"
|
||||
|
||||
# In-memory Sitemap
|
||||
autoload :Sitemap, "middleman/core_extensions/sitemap"
|
||||
|
||||
# Add Builder callbacks
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# require 'sinatra/synchrony'
|
||||
|
||||
require "i18n"
|
||||
require "hooks"
|
||||
|
||||
|
@ -12,6 +10,7 @@ module Middleman::Base
|
|||
def registered(app)
|
||||
app.send :include, ::Hooks
|
||||
app.define_hook :initialized
|
||||
|
||||
app.extend ClassMethods
|
||||
app.send :include, InstanceMethods
|
||||
|
||||
|
|
|
@ -2,13 +2,6 @@ module Middleman::CoreExtensions::Routing
|
|||
class << self
|
||||
def registered(app)
|
||||
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
|
||||
alias :included :registered
|
||||
end
|
||||
|
@ -17,7 +10,7 @@ module Middleman::CoreExtensions::Routing
|
|||
def path_to_index(path)
|
||||
parts = path ? path.split('/') : []
|
||||
if parts.last.nil? || parts.last.split('.').length == 1
|
||||
path = File.join(path, settings.index_file)
|
||||
path = File.join(path, index_file)
|
||||
end
|
||||
path.gsub(%r{^/}, '')
|
||||
end
|
||||
|
@ -28,7 +21,7 @@ module Middleman::CoreExtensions::Routing
|
|||
# page "/admin/login.html"
|
||||
# end
|
||||
def with_layout(layout_name, &block)
|
||||
old_layout = settings.layout
|
||||
old_layout = layout
|
||||
|
||||
set :layout, layout_name
|
||||
class_eval(&block) if block_given?
|
||||
|
@ -37,7 +30,7 @@ module Middleman::CoreExtensions::Routing
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
paths = [url]
|
||||
|
@ -46,27 +39,22 @@ module Middleman::CoreExtensions::Routing
|
|||
paths
|
||||
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
|
||||
# page "/about.html", :layout => false
|
||||
# page "/", :layout => :homepage_layout
|
||||
def page(url, options={}, &block)
|
||||
has_block = block_given?
|
||||
options[:layout] = settings.layout if options[:layout].nil?
|
||||
options[:layout] = layout if options[:layout].nil?
|
||||
|
||||
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]
|
||||
settings.ignore(options[:proxy])
|
||||
ignore(options[:proxy])
|
||||
end
|
||||
else
|
||||
if options.has_key?(:ignore) && options[:ignore]
|
||||
settings.ignore(url)
|
||||
ignore(url)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -18,10 +18,19 @@ module Middleman::CoreExtensions::Sitemap
|
|||
app.file_deleted do |file|
|
||||
sm.remove_file(file)
|
||||
end
|
||||
|
||||
app.extend ClassMethods
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Keep a path from building
|
||||
def ignore(path)
|
||||
sitemap.ignore_path(path)
|
||||
end
|
||||
end
|
||||
|
||||
class SitemapStore
|
||||
def initialize
|
||||
@map = {}
|
||||
|
|
Loading…
Reference in a new issue