begin yaml data store
This commit is contained in:
parent
b29413bcd3
commit
4ae03e6bbb
|
@ -75,6 +75,10 @@ module Middleman::Features
|
||||||
# paragraphs, fake images, names and email addresses.
|
# paragraphs, fake images, names and email addresses.
|
||||||
autoload :Lorem, "middleman/features/lorem"
|
autoload :Lorem, "middleman/features/lorem"
|
||||||
|
|
||||||
|
# Data looks at the data/ folder for YAML files and makes them available
|
||||||
|
# to dynamic requests.
|
||||||
|
autoload :Data, "middleman/features/data"
|
||||||
|
|
||||||
# LiveReload will auto-reload browsers with the live reload extension installed after changes
|
# LiveReload will auto-reload browsers with the live reload extension installed after changes
|
||||||
# Currently disabled and untested.
|
# Currently disabled and untested.
|
||||||
#autoload :LiveReload, "middleman/features/live_reload"
|
#autoload :LiveReload, "middleman/features/live_reload"
|
||||||
|
|
45
lib/middleman/features/data.rb
Executable file
45
lib/middleman/features/data.rb
Executable file
|
@ -0,0 +1,45 @@
|
||||||
|
# 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
|
|
@ -40,6 +40,9 @@ module Middleman
|
||||||
# Activate built-in helpers
|
# Activate built-in helpers
|
||||||
register Middleman::Features::DefaultHelpers
|
register Middleman::Features::DefaultHelpers
|
||||||
|
|
||||||
|
# Activate Yaml Data package
|
||||||
|
register Middleman::Features::Data
|
||||||
|
|
||||||
# Activate Lorem helpers
|
# Activate Lorem helpers
|
||||||
register Middleman::Features::Lorem
|
register Middleman::Features::Lorem
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ Gem::Specification.new do |s|
|
||||||
s.add_runtime_dependency("compass-slickmap", ["~> 0.4.0"])
|
s.add_runtime_dependency("compass-slickmap", ["~> 0.4.0"])
|
||||||
s.add_runtime_dependency("coffee-script", ["~> 2.1.0"])
|
s.add_runtime_dependency("coffee-script", ["~> 2.1.0"])
|
||||||
s.add_runtime_dependency("less", ["~> 1.2.0"])
|
s.add_runtime_dependency("less", ["~> 1.2.0"])
|
||||||
|
# s.add_runtime_dependency("fssm", ["~> 0.2.0"])
|
||||||
s.add_development_dependency("cucumber", ["~> 0.10.0"])
|
s.add_development_dependency("cucumber", ["~> 0.10.0"])
|
||||||
s.add_development_dependency("rspec", [">= 0"])
|
s.add_development_dependency("rspec", [">= 0"])
|
||||||
s.add_development_dependency("rocco", [">= 0"]) unless defined?(JRUBY_VERSION)
|
s.add_development_dependency("rocco", [">= 0"]) unless defined?(JRUBY_VERSION)
|
||||||
|
|
Loading…
Reference in a new issue