class Middleman::CoreExtensions::Data::DataObject

def self.add_source(name, json_url)

def self.add_source(name, json_url)
  @@remote_sources ||= {}
  @@remote_sources[name.to_s] = json_url
end

def self.data_content(name, content)

def self.data_content(name, content)
  @@local_sources ||= {}
  @@local_sources[name.to_s] = content
end

def initialize(app)

def initialize(app)
  @app = app
end

def method_missing(path)

def method_missing(path)
  response = nil
  
  @@local_sources ||= {}
  @@remote_sources ||= {}
  
  if @@local_sources.has_key?(path.to_s)
    response = @@local_sources[path.to_s]
  elsif @@remote_sources.has_key?(path.to_s)
    response = HTTParty.get(@@remote_sources[path.to_s]).parsed_response
  else
    file_path = File.join(@app.class.root, @app.class.data_dir, "#{path}.yml")
    if File.exists? file_path
      response = YAML.load_file(file_path)
    end
  end
  
  if response
    recursively_enhance(response)
  end
end

def recursively_enhance(data)

def recursively_enhance(data)
  if data.is_a? Hash
    data = Thor::CoreExt::HashWithIndifferentAccess.new(data)
    data.each do |key, val|
      data[key] = recursively_enhance(val)
    end
    data
  elsif data.is_a? Array
    data.each_with_index do |val, i|
      data[i] = recursively_enhance(val)
    end
    data
  else
    data
  end
end