run file changed for entire app on boot

This commit is contained in:
Thomas Reynolds 2011-11-17 16:02:07 -08:00
parent ffb7611acc
commit fc91179b4a
5 changed files with 34 additions and 23 deletions

View file

@ -34,15 +34,10 @@ module Middleman::CoreExtensions::Data
def initialize(app)
@app = app
@local_data = {}
data_path = File.join(@app.root, @app.data_dir)
local_path = File.join(data_path, "*.{yaml,yml,json}")
Dir[local_path].each do |f|
touch_file(f)
end
end
def touch_file(file)
file = File.expand_path(file, @app.root)
extension = File.extname(file)
basename = File.basename(file, extension)
@ -54,6 +49,7 @@ module Middleman::CoreExtensions::Data
return
end
@app.logger.debug :data_update, Time.now, basename if @app.settings.logging?
@local_data[basename] = recursively_enhance(data)
end

View file

@ -35,6 +35,7 @@ module Middleman::CoreExtensions::Features
def registered(app)
app.set :default_features, []
app.define_hook :after_configuration
app.define_hook :before_configuration
app.extend ClassMethods
end
alias :included :registered
@ -66,6 +67,8 @@ module Middleman::CoreExtensions::Features
# Load features before starting server
def new!
run_hook :before_configuration
# Check for and evaluate local configuration
local_config = File.join(self.root, "config.rb")
if File.exists? local_config

View file

@ -1,8 +1,17 @@
require "find"
module Middleman::CoreExtensions::FileWatcher
class << self
def registered(app)
app.extend ClassMethods
app.send :include, InstanceMethods
app.before_configuration do
Find.find(settings.root) do |path|
next if File.directory?(path)
file_did_change(path.sub("#{settings.root}/", ""))
end
end
end
alias :included :registered
end
@ -19,21 +28,31 @@ module Middleman::CoreExtensions::FileWatcher
@_file_deleted << [block, matcher] if block_given?
@_file_deleted
end
def file_did_change(path)
file_changed.each do |callback, matcher|
next if path.match(%r{^#{build_dir}/})
next if !matcher.nil? && !path.match(matcher)
instance_exec(path, &callback)
end
end
def file_did_delete(path)
file_deleted.each do |callback, matcher|
next if path.match(%r{^#{build_dir}/})
next unless matcher.nil? || path.match(matcher)
instance_exec(path, &callback)
end
end
end
module InstanceMethods
def file_did_change(path)
settings.file_changed.each do |callback, matcher|
next unless matcher.nil? || path.match(matcher)
settings.instance_exec(path, &callback)
end
settings.file_did_change(path)
end
def file_did_delete(path)
settings.file_deleted.each do |callback, matcher|
next unless matcher.nil? || path.match(matcher)
settings.instance_exec(path, &callback)
end
settings.file_did_delete(path)
end
end
end

View file

@ -66,14 +66,6 @@ module Middleman::CoreExtensions::FrontMatter
@app = app
@source ||= File.expand_path(@app.views, @app.root)
@local_data = {}
Dir[File.join(@source, "**/*")].each do |file|
next if file.match(/\/\./) ||
(file.match(/\/_/) && !file.match(/\/__/)) ||
!file.match(self.class.matcher)
touch_file(file.sub(@app.root, "").sub(/^\//, ""))
end
end
def has_data?(path)

View file

@ -49,7 +49,7 @@ module Middleman::CoreExtensions::Sitemap
@generic_paths = false
@proxied_paths = false
build_static_map
# build_static_map
end
# Check to see if we know about a specific path
@ -216,6 +216,7 @@ module Middleman::CoreExtensions::Sitemap
return false if path == "layout" ||
path.match(/^layouts/)
@app.logger.debug :sitemap_update, Time.now, path if @app.settings.logging?
set_path(path)
true