1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/lib/middleman/features/data.rb

45 lines
1.1 KiB
Ruby
Raw Normal View History

2011-04-14 18:35:41 -04:00
# require "fssm"
require "yaml"
module Middleman::Features::Data
class << self
def registered(app)
@@app = app
@@data_structure = {}
Dir[File.join(app.root, 'data/*.yml')].each do |d|
handle_update(d)
end
# FSSM.monitor(app.root, 'data/*.yml') do
# update do |base, relative|
# handle_update(File.join(base, relative))
# end
#
# create do |base, relative|
# handle_update(File.join(base, relative))
# end
#
# delete do |base, relative|
# handle_delete(File.join(base, relative))
# end
# end
end
def handle_update(path)
data_name = File.basename(path).split(".").first
data = YAML.load_file(path)
@@data_structure[data_name] = data
@@app.set :data, @@data_structure
end
# def handle_delete(path)
# data_name = File.basename(path).split(".").first
# @@data_structure.delete(data_name) if @@data_structure.has_key? data_name
# @@app.set :data, @@data_structure
# end
alias :included :registered
end
end