class Middleman::CoreExtensions::Data::Stores::LocalFileDataStore
JSON and YAML files in the data/ directory
def initialize(app)
def initialize(app) super() @app = app @local_data = {} end
def remove_file(file)
def remove_file(file) data_path = file[:relative_path] extension = File.extname(data_path) basename = File.basename(data_path, extension) data_branch = @local_data path = data_path.to_s.split(File::SEPARATOR)[0..-2] path.each do |dir| data_branch = data_branch[dir.to_sym] end data_branch.delete(basename.to_sym) if data_branch.key?(basename.to_sym) end
def touch_file(file)
def touch_file(file) data_path = file[:relative_path] extension = File.extname(data_path) basename = File.basename(data_path, extension) return unless ALL_EXTS.include?(extension) if YAML_EXTS.include?(extension) data, postscript = ::Middleman::Util::Data.parse(file, @app.config[:frontmatter_delims], :yaml) data[:postscript] = postscript if !postscript.nil? && data.is_a?(Hash) elsif JSON_EXTS.include?(extension) data, _postscript = ::Middleman::Util::Data.parse(file, @app.config[:frontmatter_delims], :json) end data_branch = @local_data paths = data_path.to_s.split(File::SEPARATOR)[0..-2] paths.each do |dir| data_branch[dir.to_sym] ||= {} data_branch = data_branch[dir.to_sym] end data_branch[basename.to_sym] = data end
def update_files(updated_files, removed_files)
def update_files(updated_files, removed_files) updated_files.each(&method(:touch_file)) removed_files.each(&method(:remove_file)) @app.sitemap.rebuild_resource_list!(:touched_data_file) end