|
- require 'haml'
- require 'csv'
- require 'logger'
- require "petrify/version"
-
- module Petrify
- @@output_dir = '_site'
- @@working_dir = File.join(Dir.pwd, @@output_dir)
- @@views_dir = 'views'
- @@layout_fn = File.join(@@views_dir, 'layout.haml')
-
-
- @@log = Logger.new($stdout)
- @@log.level = Logger::INFO
-
- def self.page(path_items, template, locals = {})
- dir = create_path(path_items)
- fn = File.join(dir, 'index.html')
-
-
- html = Haml::Engine.new(File.read(@@layout_fn)).render(Object.new, locals) do
- Haml::Engine.new(File.read(File.join(@@views_dir, "#{template}.haml"))).render(Object.new, locals)
- end
-
- File.write(fn, html)
- @@log.info fn
-
-
- end
-
- def self.csv(path_items, filename, data)
- dir = create_path(path_items)
- fn = File.join(dir, filename + '.csv')
-
- csv_string = CSV.generate do |csv|
- csv << data.first.keys
- data.each { |row| csv << row.values }
- end
-
- File.write(fn, csv_string)
- @@log.info fn
- end
-
- def self.setup
-
-
- FileUtils.rm_r(Dir.glob(File.join(@@working_dir, '*')))
- Dir.mkdir(@@working_dir) unless File.directory?(@@working_dir)
-
-
- FileUtils.copy_entry('public', @@working_dir)
- end
-
- def self.create_path(path_items)
- dir = File.join(@@output_dir, path_items)
- FileUtils.mkdir_p(dir)
- @@log.debug dir
- dir
- end
- end
|