Sha256: a2c3ef9eefb237137affdab21f8d5309f01c8d0d3cc177726b3e27d5e15a3aae
Contents?: true
Size: 1.54 KB
Versions: 1
Compression:
Stored size: 1.54 KB
Contents
if RUBY_VERSION > "1.9" require "yaml" YAML::ENGINE.yamler = "syck" end module Radiant class Exporter cattr_accessor :exportable_models @@exportable_models = [Radiant::Config, User, Page, PagePart, PageField, Layout] cattr_accessor :template_models @@template_models = [Layout, Page, PagePart, PageField] cattr_accessor :ignored_template_attributes @@ignored_template_attributes = [:lock_version, :created_at, :updated_at, :created_by_id, :updated_by_id] class << self def export(type='yaml') if self.respond_to?("export_#{type}") self.send("export_#{type}") else '' end end def export_yaml hash = ActiveSupport::OrderedHash.new @@exportable_models.each do |klass| hash[klass.name.pluralize] = klass.find(:all).inject(ActiveSupport::OrderedHash.new) { |h, record| h[record.id.to_i] = record.attributes; h } end hash.to_yaml end def export_template hash = ActiveSupport::OrderedHash.new hash['name'] = hash['description'] = "Exported Template #{Time.zone.now.to_i}" records = hash['records'] = ActiveSupport::OrderedHash.new @@template_models.each do |klass| records[klass.name.pluralize] = klass.find(:all).inject(ActiveSupport::OrderedHash.new) { |h, record| h[record.id.to_i] = record.attributes.delete_if{|att| @@ignored_template_attributes.include?(att[0].to_sym) }; h } end hash.to_yaml end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
radiant-exporter-extension-1.1.0 | app/models/radiant/exporter.rb |