Class: Middleman::CoreExtensions::Data::DataExtension
- 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
Constant Summary collapse
- DATA_FILE_MATCHER =
The regex which tells Middleman which files are for data
/^(.*?)[\w-]+\.(yml|yaml|json|toml)$/.freeze
Constants included from Contracts
Instance Attribute Summary collapse
-
#data_store ⇒ Object
readonly
Returns the value of attribute data_store.
Attributes inherited from Extension
Instance Method Summary collapse
- #after_configuration ⇒ Object
-
#initialize(app, options_hash = ::Middleman::EMPTY_HASH, &block) ⇒ DataExtension
constructor
A new instance of DataExtension.
- #start_watching(dir) ⇒ Object
Methods inherited from Extension
activated_extension, #add_exposed_to_context, #after_build, after_extension_activated, #after_extension_activated, #before_build, #before_configuration, clear_after_extension_callbacks, config, define_setting, expose_to_application, expose_to_config, expose_to_template, global_config, helpers, #manipulate_resource_list, option, #ready, resources
Methods included from Contracts
Constructor Details
#initialize(app, options_hash = ::Middleman::EMPTY_HASH, &block) ⇒ DataExtension
Returns a new instance of DataExtension.
27 28 29 30 31 32 33 |
# File 'middleman-core/lib/middleman-core/core_extensions/data.rb', line 27 def initialize(app, = ::Middleman::EMPTY_HASH, &block) super @data_store = DataStoreController.new(app, app.config[:track_data_access]) start_watching(app.config[:data_dir]) end |
Instance Attribute Details
#data_store ⇒ Object (readonly)
Returns the value of attribute data_store.
12 13 14 |
# File 'middleman-core/lib/middleman-core/core_extensions/data.rb', line 12 def data_store @data_store end |
Instance Method Details
#after_configuration ⇒ Object
50 51 52 53 54 55 56 |
# File 'middleman-core/lib/middleman-core/core_extensions/data.rb', line 50 def after_configuration @watcher.update_path(app.config[:data_dir]) if @original_data_dir != app.config[:data_dir] app.files.watch :reload, path: File.(@watcher.directory, app.root), only: DATA_FILE_MATCHER end |
#start_watching(dir) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'middleman-core/lib/middleman-core/core_extensions/data.rb', line 36 def start_watching(dir) @original_data_dir = dir # Tell the file watcher to observe the :data_dir @watcher = app.files.watch :data, path: File.(dir, app.root), 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 |