class Middleman::CoreExtensions::Data

The data extension parses YAML and JSON files in the `data/` directory and makes them available to `config.rb`, templates and extensions

Constants

DATA_FILE_MATCHER

The regex which tells Middleman which files are for data

Attributes

data_store[R]

Public Class Methods

new(app, config={}, &block) click to toggle source
Calls superclass method
# File lib/middleman-core/core_extensions/data.rb, line 22
def initialize(app, config={}, &block)
  super

  @data_store = DataStore.new(app, DATA_FILE_MATCHER)

  start_watching(app.config[:data_dir])
end

Public Instance Methods

after_configuration() click to toggle source
# File lib/middleman-core/core_extensions/data.rb, line 43
def after_configuration
  return unless @original_data_dir != app.config[:data_dir]

  @watcher.update_path(app.config[:data_dir])
end
start_watching(dir) click to toggle source
# File lib/middleman-core/core_extensions/data.rb, line 30
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),
                             only: DATA_FILE_MATCHER

  # 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