Convert FileWatcher to a real extension
This commit is contained in:
parent
67bb394852
commit
e649bc2809
3 changed files with 27 additions and 31 deletions
|
@ -142,9 +142,6 @@ module Middleman
|
|||
# Handle exceptions
|
||||
include Middleman::CoreExtensions::ShowExceptions
|
||||
|
||||
# Add Watcher Callbacks
|
||||
include Middleman::CoreExtensions::FileWatcher
|
||||
|
||||
# Activate Data package
|
||||
include Middleman::CoreExtensions::Data
|
||||
|
||||
|
@ -191,6 +188,7 @@ module Middleman
|
|||
# Parse YAML from templates. Must be before sitemap so sitemap
|
||||
# extensions see updated frontmatter!
|
||||
activate :front_matter
|
||||
activate :file_watcher
|
||||
|
||||
# Initialize the Sitemap
|
||||
@sitemap = ::Middleman::Sitemap::Store.new(self)
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# File Change Notifier
|
||||
require 'middleman-core/core_extensions/file_watcher'
|
||||
Middleman::Extensions.register :file_watcher do
|
||||
require 'middleman-core/core_extensions/file_watcher'
|
||||
Middleman::CoreExtensions::FileWatcher
|
||||
end
|
||||
|
||||
# Data looks at the data/ folder for YAML files and makes them available
|
||||
# to dynamic requests.
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
# API for watching file change events
|
||||
require 'pathname'
|
||||
require 'set'
|
||||
|
||||
module Middleman
|
||||
module CoreExtensions
|
||||
module FileWatcher
|
||||
# API for watching file change events
|
||||
class FileWatcher < Extension
|
||||
# Regexes in this list will filter out filenames of files that shouldn't cause file change notifications.
|
||||
IGNORE_LIST = [
|
||||
/^bin(\/|$)/,
|
||||
/^\.bundle(\/|$)/,
|
||||
|
@ -20,39 +24,30 @@ module Middleman
|
|||
/^tmp\//
|
||||
]
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
# Once registered
|
||||
def included(app)
|
||||
require 'pathname'
|
||||
require 'set'
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
app.send :include, InstanceMethods
|
||||
app.config.define_setting :file_watcher_ignore, IGNORE_LIST, 'Regexes for paths that should be ignored when they change.'
|
||||
|
||||
app.config.define_setting :file_watcher_ignore, IGNORE_LIST, 'Regexes for paths that should be ignored when they change.'
|
||||
|
||||
# Before parsing config, load the data/ directory
|
||||
app.before_configuration do
|
||||
files.reload_path(config[:data_dir])
|
||||
end
|
||||
|
||||
app.after_configuration do
|
||||
config[:file_watcher_ignore] << %r{^#{config[:build_dir]}(\/|$)}
|
||||
end
|
||||
|
||||
# After config, load everything else
|
||||
app.ready do
|
||||
files.reload_path('.')
|
||||
end
|
||||
end
|
||||
# Directly include the #files method instead of using helpers so that this is available immediately
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
|
||||
# Before parsing config, load the data/ directory
|
||||
def before_configuration
|
||||
app.files.reload_path(app.config[:data_dir])
|
||||
end
|
||||
|
||||
def after_configuration
|
||||
app.config[:file_watcher_ignore] << %r{^#{app.config[:build_dir]}(\/|$)}
|
||||
app.files.reload_path('.')
|
||||
end
|
||||
|
||||
# Instance methods
|
||||
module InstanceMethods
|
||||
# Access the file api
|
||||
# @return [Middleman::CoreExtensions::FileWatcher::API]
|
||||
def files
|
||||
@_files_api ||= API.new(self)
|
||||
@files_api ||= API.new(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue