middleman/lib/middleman/features/data.rb

30 lines
582 B
Ruby
Raw Normal View History

2011-04-15 00:35:41 +02:00
require "yaml"
module Middleman::Features::Data
class << self
def registered(app)
2011-04-15 18:57:45 +02:00
app.helpers Middleman::Features::Data::Helpers
2011-04-15 00:35:41 +02:00
end
2011-04-15 18:57:45 +02:00
alias :included :registered
end
module Helpers
def data
@@data ||= Middleman::Features::Data::DataObject.new(self)
end
end
class DataObject
def initialize(app)
@app = app
2011-04-15 00:35:41 +02:00
end
2011-04-15 18:57:45 +02:00
def method_missing(path)
file_path = File.join(@app.class.root, "data", "#{path}.yml")
if File.exists? file_path
return YAML.load_file(file_path)
end
end
2011-04-15 00:35:41 +02:00
end
2011-04-15 18:57:45 +02:00
2011-04-15 00:35:41 +02:00
end