Class: ComfortableMexicanSofa::Fixture::Page::Exporter

Inherits:
Exporter
  • Object
show all
Defined in:
lib/comfortable_mexican_sofa/fixture/page.rb

Instance Method Summary collapse

Instance Method Details

#export!Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/comfortable_mexican_sofa/fixture/page.rb', line 103

def export!
  prepare_folder!(self.path)
  
  self.site.pages.each do |page|
    page.slug = 'index' if page.slug.blank?
    page_path = File.join(path, page.ancestors.reverse.collect{|p| p.slug.blank?? 'index' : p.slug}, page.slug)
    FileUtils.mkdir_p(page_path)

    open(File.join(page_path, 'attributes.yml'), 'w') do |f|
      f.write({
        'label'         => page.label,
        'layout'        => page.layout.try(:identifier),
        'parent'        => page.parent && (page.parent.slug.present?? page.parent.slug : 'index'),
        'target_page'   => page.target_page.try(:full_path),
        'categories'    => page.categories.map{|c| c.label},
        'is_published'  => page.is_published,
        'position'      => page.position,
        'cached_timeout' => page.cached_timeout,
        'aasm_state' => page.aasm_state,
        'published_date' => page.published_date
      }.to_yaml)
    end
    page.blocks_attributes.each do |block|
      open(File.join(page_path, "#{block[:identifier]}.html"), 'w') do |f|
        f.write(block[:content])
      end
    end
    
    ComfortableMexicanSofa.logger.info("[FIXTURES] Exported Page \t #{page.full_path}")
  end
end