Method: StaticCms::Page#generate

Defined in:
lib/static_cms/page.rb

#generateObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/static_cms/page.rb', line 36

def generate
  FileUtils.mkdir_p(@dir)
  FileUtils.chmod(0755, @dir)

  if @visible
    @statics.each{|file| cp_if_new(file)}
    @sources.each{|file| compile(file)}
    template_file = @template_file
  else
    @statics.each{|file| FileUtils.rm_rf(static_target(file))}
    @sources.each{|file| FileUtils.rm_rf(compile_target(file))}
    template_file = 'templates/moved.html.haml'
  end

  html = ::Haml::Engine.new(File.read(template_file)).render(self)
  target = File.join(@dir, 'index.html')
  open(target, 'w'){|io|
    io.write(html)
    io.flush
    io.fsync
  }
end