Class: Occams::Seeds::Layout::Exporter

Inherits:
Exporter
  • Object
show all
Defined in:
lib/occams/seeds/layout/exporter.rb

Instance Attribute Summary

Attributes inherited from Exporter

#from, #path, #site, #to

Instance Method Summary collapse

Constructor Details

#initialize(from, to = from) ⇒ Exporter

Returns a new instance of Exporter.



5
6
7
8
# File 'lib/occams/seeds/layout/exporter.rb', line 5

def initialize(from, to = from)
  super
  self.path = ::File.join(Occams.config.seeds_path, to, 'layouts/')
end

Instance Method Details

#export!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/occams/seeds/layout/exporter.rb', line 10

def export!
  prepare_folder!(path)

  site.layouts.each do |layout|
    layout_path = File.join(path, layout.ancestors.reverse.collect(&:identifier), layout.identifier)
    FileUtils.mkdir_p(layout_path)

    path = ::File.join(layout_path, 'content.html')
    data = []

    attrs = {
      'label' => layout.label,
      'app_layout' => layout.app_layout,
      'position' => layout.position
    }.to_yaml

    data << { header: 'attributes',  content: attrs }
    data << { header: 'content',     content: layout.content }
    data << { header: 'js',          content: layout.js }
    data << { header: 'css',         content: layout.css }

    write_file_content(path, data)

    message = "[CMS SEEDS] Exported Layout \t #{layout.identifier}"
    Occams.logger.info(message)
  end
end