class Middleman::CoreExtensions::Data
and makes them available to ‘config.rb`, templates and extensions
The data extension parses YAML and JSON files in the `data/` directory
def after_configuration
def after_configuration return unless @original_data_dir != app.config[:data_dir] @watcher.update_path(app.config[:data_dir]) end
def data
def data extensions[:data].data_store end
def initialize(app, config={}, &block)
def initialize(app, config={}, &block) super @data_store = DataStore.new(app, DATA_FILE_MATCHER) app.config.define_setting :data_dir, 'data', 'The directory data files are stored in' app.add_to_instance(:data, &method(:data_store)) app.add_to_config_context(:data, &method(:data_store)) start_watching(app.config[:data_dir]) end
def start_watching(dir)
def start_watching(dir) @original_data_dir = dir # Tell the file watcher to observe the :data_dir @watcher = app.files.watch :data, path: File.join(app.root, dir), ignore: proc { |f| !DATA_FILE_MATCHER.match(f[:relative_path]) } # Setup data files before anything else so they are available when # parsing config.rb app.files.on_change(:data, &@data_store.method(:update_files)) end