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



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/comfortable_mexican_sofa/fixture/page.rb', line 91

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,
        'page_workflow' => {status_id: page.page_workflow.status_id, published_date: page.page_workflow.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.warn("[FIXTURES] Exported Page \t #{page.full_path}")
  end
end