Class: Radiant::Exporter
- Inherits:
-
Object
- Object
- Radiant::Exporter
- Defined in:
- app/models/radiant/exporter.rb
Constant Summary collapse
- @@exportable_models =
[Radiant::Config, User, Page, PagePart, PageField, Snippet, Layout]
- @@template_models =
[Layout, Snippet, Page, PagePart, PageField]
- @@ignored_template_attributes =
[:lock_version, :created_at, :updated_at, :created_by_id, :updated_by_id]
Class Method Summary collapse
Class Method Details
.export(type = 'yaml') ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/models/radiant/exporter.rb', line 11 def export(type='yaml') if self.respond_to?("export_#{type}") self.send("export_#{type}") else '' end end |
.export_template ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/radiant/exporter.rb', line 27 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 |
.export_yaml ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/models/radiant/exporter.rb', line 19 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 |