Class: Middleman::CoreExtensions::Data

Inherits:
Extension
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/core_extensions/data.rb

Overview

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

Defined Under Namespace

Classes: DataStore

Constant Summary

Constant Summary

Constants included from Contracts

Contracts::PATH_MATCHER, Contracts::ResourceList

Instance Attribute Summary (collapse)

Attributes inherited from Extension

#app, #options

Instance Method Summary (collapse)

Methods inherited from Extension

activated_extension, #after_build, #after_configuration, after_extension_activated, #after_extension_activated, #before_build, clear_after_extension_callbacks, config, helpers, #initialize, option

Methods included from Contracts

#Contract

Constructor Details

This class inherits a constructor from Middleman::Extension

Instance Attribute Details

- (Object) data_store (readonly)

Returns the value of attribute data_store



10
11
12
# File 'middleman-core/lib/middleman-core/core_extensions/data.rb', line 10

def data_store
  @data_store
end

Instance Method Details

- (Object) before_configuration



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'middleman-core/lib/middleman-core/core_extensions/data.rb', line 12

def before_configuration
  @data_store = DataStore.new(app)
  app.config.define_setting :data_dir, 'data', 'The directory data files are stored in'

  app.add_to_config_context :data, &method(:data_store)

  # The regex which tells Middleman which files are for data
  data_file_matcher = /#{app.config[:data_dir]}\/(.*?)[\w-]+\.(yml|yaml|json)$/

  # Setup data files before anything else so they are available when
  # parsing config.rb
  file_watcher.changed(data_file_matcher, &app.extensions[:data].data_store.method(:touch_file))
  file_watcher.deleted(data_file_matcher, &app.extensions[:data].data_store.method(:remove_file))

  file_watcher.reload_path(app.config[:data_dir])
end