run file changed for entire app on boot
This commit is contained in:
parent
ffb7611acc
commit
fc91179b4a
5 changed files with 34 additions and 23 deletions
|
@ -34,15 +34,10 @@ module Middleman::CoreExtensions::Data
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
@local_data = {}
|
@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
|
end
|
||||||
|
|
||||||
def touch_file(file)
|
def touch_file(file)
|
||||||
|
file = File.expand_path(file, @app.root)
|
||||||
extension = File.extname(file)
|
extension = File.extname(file)
|
||||||
basename = File.basename(file, extension)
|
basename = File.basename(file, extension)
|
||||||
|
|
||||||
|
@ -54,6 +49,7 @@ module Middleman::CoreExtensions::Data
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@app.logger.debug :data_update, Time.now, basename if @app.settings.logging?
|
||||||
@local_data[basename] = recursively_enhance(data)
|
@local_data[basename] = recursively_enhance(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ module Middleman::CoreExtensions::Features
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.set :default_features, []
|
app.set :default_features, []
|
||||||
app.define_hook :after_configuration
|
app.define_hook :after_configuration
|
||||||
|
app.define_hook :before_configuration
|
||||||
app.extend ClassMethods
|
app.extend ClassMethods
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
|
@ -66,6 +67,8 @@ module Middleman::CoreExtensions::Features
|
||||||
|
|
||||||
# Load features before starting server
|
# Load features before starting server
|
||||||
def new!
|
def new!
|
||||||
|
run_hook :before_configuration
|
||||||
|
|
||||||
# Check for and evaluate local configuration
|
# Check for and evaluate local configuration
|
||||||
local_config = File.join(self.root, "config.rb")
|
local_config = File.join(self.root, "config.rb")
|
||||||
if File.exists? local_config
|
if File.exists? local_config
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
|
require "find"
|
||||||
|
|
||||||
module Middleman::CoreExtensions::FileWatcher
|
module Middleman::CoreExtensions::FileWatcher
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.extend ClassMethods
|
app.extend ClassMethods
|
||||||
app.send :include, InstanceMethods
|
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
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
@ -19,21 +28,31 @@ module Middleman::CoreExtensions::FileWatcher
|
||||||
@_file_deleted << [block, matcher] if block_given?
|
@_file_deleted << [block, matcher] if block_given?
|
||||||
@_file_deleted
|
@_file_deleted
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
def file_did_change(path)
|
def file_did_change(path)
|
||||||
settings.file_changed.each do |callback, matcher|
|
file_changed.each do |callback, matcher|
|
||||||
next unless matcher.nil? || path.match(matcher)
|
next if path.match(%r{^#{build_dir}/})
|
||||||
settings.instance_exec(path, &callback)
|
next if !matcher.nil? && !path.match(matcher)
|
||||||
|
instance_exec(path, &callback)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_did_delete(path)
|
def file_did_delete(path)
|
||||||
settings.file_deleted.each do |callback, matcher|
|
file_deleted.each do |callback, matcher|
|
||||||
|
next if path.match(%r{^#{build_dir}/})
|
||||||
next unless matcher.nil? || path.match(matcher)
|
next unless matcher.nil? || path.match(matcher)
|
||||||
settings.instance_exec(path, &callback)
|
instance_exec(path, &callback)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module InstanceMethods
|
||||||
|
def file_did_change(path)
|
||||||
|
settings.file_did_change(path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_did_delete(path)
|
||||||
|
settings.file_did_delete(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -66,14 +66,6 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
@app = app
|
@app = app
|
||||||
@source ||= File.expand_path(@app.views, @app.root)
|
@source ||= File.expand_path(@app.views, @app.root)
|
||||||
@local_data = {}
|
@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
|
end
|
||||||
|
|
||||||
def has_data?(path)
|
def has_data?(path)
|
||||||
|
|
|
@ -49,7 +49,7 @@ module Middleman::CoreExtensions::Sitemap
|
||||||
@generic_paths = false
|
@generic_paths = false
|
||||||
@proxied_paths = false
|
@proxied_paths = false
|
||||||
|
|
||||||
build_static_map
|
# build_static_map
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check to see if we know about a specific path
|
# Check to see if we know about a specific path
|
||||||
|
@ -216,6 +216,7 @@ module Middleman::CoreExtensions::Sitemap
|
||||||
return false if path == "layout" ||
|
return false if path == "layout" ||
|
||||||
path.match(/^layouts/)
|
path.match(/^layouts/)
|
||||||
|
|
||||||
|
@app.logger.debug :sitemap_update, Time.now, path if @app.settings.logging?
|
||||||
set_path(path)
|
set_path(path)
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
Loading…
Reference in a new issue