Class: ComfortableMexicanSofa::Fixture::Snippet::Exporter

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

Instance Attribute Summary

Attributes inherited from Exporter

#from, #path, #site, #to

Instance Method Summary collapse

Methods inherited from Exporter

#initialize, #prepare_folder!

Constructor Details

This class inherits a constructor from ComfortableMexicanSofa::Fixture::Exporter

Instance Method Details

#export!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/comfortable_mexican_sofa/fixture/snippet.rb', line 51

def export!
  prepare_folder!(self.path)
  
  self.site.snippets.each do |snippet|
    snippet_path = File.join(self.path, snippet.identifier)
    FileUtils.mkdir_p(snippet_path)
    
    # writing attributes
    open(File.join(snippet_path, 'attributes.yml'), 'w') do |f|
      f.write({
        'label'       => snippet.label,
        'categories'  => snippet.categories.map{|c| c.label}
      }.to_yaml)
    end
    
    # writing content
    open(File.join(snippet_path, 'content.html'), 'w') do |f|
      f.write(snippet.content)
    end
    
    ComfortableMexicanSofa.logger.info("[FIXTURES] Exported Snippet \t #{snippet.identifier}")
  end
end