Standardize exposing methods inside extensions to the outside world
This commit is contained in:
parent
33cb9b3ba9
commit
82b84668b0
15 changed files with 172 additions and 62 deletions
|
@ -9,6 +9,12 @@ module Middleman
|
|||
class Data < Extension
|
||||
attr_reader :data_store
|
||||
|
||||
# Make the internal `data_store` method available as `app.data`
|
||||
expose_to_application data: :data_store
|
||||
|
||||
# Exposes `data` to templates
|
||||
expose_to_template data: :data_store
|
||||
|
||||
# The regex which tells Middleman which files are for data
|
||||
DATA_FILE_MATCHER = /^(.*?)[\w-]+\.(yml|yaml|json)$/
|
||||
|
||||
|
@ -18,8 +24,6 @@ module Middleman
|
|||
@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))
|
||||
|
||||
start_watching(app.config[:data_dir])
|
||||
end
|
||||
|
||||
|
@ -42,12 +46,6 @@ module Middleman
|
|||
@watcher.update_path(app.config[:data_dir])
|
||||
end
|
||||
|
||||
helpers do
|
||||
def data
|
||||
extensions[:data].data_store
|
||||
end
|
||||
end
|
||||
|
||||
# The core logic behind the data extension.
|
||||
class DataStore
|
||||
include Contracts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue