little cleanups

This commit is contained in:
Thomas Reynolds 2011-11-08 10:35:27 -08:00
parent e8d50ad204
commit 19e566f6a5
4 changed files with 35 additions and 43 deletions

View file

@ -79,7 +79,7 @@ module Middleman::Base
app.set :default_features, [
:lorem,
:sitemap_tree
#:sitemap_tree
]
# Default layout name

View file

@ -63,16 +63,6 @@ module Middleman::CoreExtensions::Features
register feature
end
# Add a block/proc to be run after features have been setup
def before_configuration(&block)
@run_before_features ||= []
@run_before_features << block
end
def run_before_features
@run_before_features || []
end
# Add a block/proc to be run after features have been setup
def after_configuration(&block)
@run_after_features ||= []
@ -85,8 +75,6 @@ module Middleman::CoreExtensions::Features
# Load features before starting server
def new
run_before_features.each { |block| class_eval(&block) }
# Check for and evaluate local configuration
local_config = File.join(self.root, "config.rb")
if File.exists? local_config

View file

@ -1,6 +1,9 @@
module Middleman::CoreExtensions::FileWatcher
class << self
def registered(app)
app.set :run_after_file_change, []
app.set :run_after_file_delete, []
app.extend ClassMethods
end
alias :included :registered
@ -8,23 +11,19 @@ module Middleman::CoreExtensions::FileWatcher
module ClassMethods
def file_did_change(path)
@run_after_file_change ||= []
@run_after_file_change.each { |block| block.call(path) }
settings.run_after_file_change.each { |block| block.call(path) }
end
def on_file_change(&block)
@run_after_file_change ||= []
@run_after_file_change << block
settings.run_after_file_change << block
end
def file_did_delete(path)
@run_after_file_delete ||= []
@run_after_file_delete.each { |block| block.call(path) }
settings.run_after_file_delete.each { |block| block.call(path) }
end
def on_file_delete(&block)
@run_after_file_delete ||= []
@run_after_file_delete << block
settings.run_after_file_delete << block
end
end
end

View file

@ -4,10 +4,6 @@ module Middleman::CoreExtensions::Sitemap
class << self
def registered(app)
app.set :sitemap, SitemapStore.new(app)
app.before_configuration do
app.sitemap.setup
end
end
alias :included :registered
end
@ -19,11 +15,6 @@ module Middleman::CoreExtensions::Sitemap
@ignored_paths = false
@generic_paths = false
@proxied_paths = false
end
def setup
@source = File.expand_path(@app.views, @app.root)
build_static_map
@app.on_file_change do |file|
touch_file(file)
@ -32,6 +23,16 @@ module Middleman::CoreExtensions::Sitemap
@app.on_file_delete do |file|
remove_file(file)
end
setup
# @app.after_configuration do
# sitemap.setup
# end
end
def setup
@source = File.expand_path(@app.views, @app.root)
build_static_map
end
# Check to see if we know about a specific path
@ -126,15 +127,12 @@ module Middleman::CoreExtensions::Sitemap
end
def touch_file(file)
touch_path(file_to_path(file))
end
def touch_path(path)
set_path(path) unless path_exists?(path)
add_file(file)
end
def remove_file(file)
remove_path(file_to_path(file))
path = file_to_path(file)
remove_path(path) if path
end
def remove_path(path)
@ -150,13 +148,18 @@ module Middleman::CoreExtensions::Sitemap
end
def file_to_path(file)
path = file.sub(@source + "/", "")
@source ||= File.expand_path(@app.views, @app.root)
file = File.expand_path(file, @app.root)
prefix = @source + "/"
return false unless file.include?(prefix)
path = file.sub(prefix, "")
end_of_the_line = false
while !end_of_the_line
file_extension = File.extname(path)
# TODO: Loop and continue popping Tilt-aware extensions
if ::Tilt.mappings.has_key?(file_extension.gsub(/^\./, ""))
path = path.sub(file_extension, "")
else
@ -173,7 +176,9 @@ module Middleman::CoreExtensions::Sitemap
(file.match(/\/_/) && !file.match(/\/__/)) ||
File.directory?(file)
add_path(file_to_path(file))
path = file_to_path(file)
add_path(path) if path && !path_exists?(path)
end
def add_path(path)