diff --git a/Gemfile b/Gemfile index 91f2896..ce284bc 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,4 @@ source 'https://rubygems.org' ruby '2.3.1' gem 'scraperwiki', :git => 'https://github.com/openaustralia/scraperwiki-ruby/', :branch => 'morph_defaults' -gem 'haml' +gem 'petrify', :git => 'https://github.com/adrianshort/petrify/' diff --git a/Gemfile.lock b/Gemfile.lock index 6ac0484..1b00954 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/adrianshort/petrify/ + revision: 4f949558e20767fc88acd18e523c2e95a4173475 + specs: + petrify (0.1.0) + haml + GIT remote: https://github.com/openaustralia/scraperwiki-ruby/ revision: fc50176812505e463077d5c673d504a6a234aa78 @@ -24,7 +31,7 @@ PLATFORMS ruby DEPENDENCIES - haml + petrify! scraperwiki! RUBY VERSION diff --git a/bin/petrify b/bin/petrify index dc7564d..3e95f4f 100755 --- a/bin/petrify +++ b/bin/petrify @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require_relative '../lib/helpers' -require_relative '../lib/petrify' require_relative '../lib/site' Petrify.setup diff --git a/lib/petrify.rb b/lib/petrify.rb deleted file mode 100644 index a295f57..0000000 --- a/lib/petrify.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'haml' -require 'csv' -require 'logger' - -class Petrify - @@output_dir = '_site' - @@working_dir = File.join(Dir.pwd, @@output_dir) - @@views_dir = 'views' - @@layout_fn = File.join(@@views_dir, 'layout.haml') - - # https://stackoverflow.com/questions/917566/ruby-share-logger-instance-among-module-classes#6768164 - @@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') - - # https://stackoverflow.com/questions/6125265/using-layouts-in-haml-files-independently-of-rails - html = Haml::Engine.new(File.read(@@layout_fn)).render do - Haml::Engine.new(File.read(File.join(@@views_dir, "#{template}.haml"))).render(Object.new, locals) - end - - File.write(fn, html) - @@log.info fn - # TODO - add page to sitemap.xml or sitemap.txt - # https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190 - 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 # header row - data.each { |row| csv << row.values } - end - - File.write(fn, csv_string) - @@log.info fn - end - - def self.setup - # Recursively delete working directory to ensure no redundant files are left behind from previous builds. - # FileUtils.rm_rf(@working_dir) - Dir.mkdir(@@working_dir) unless File.directory?(@@working_dir) - # Dir.chdir(@working_dir) - - # Copy `public` dir to output 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 - diff --git a/lib/site.rb b/lib/site.rb index 7f510d3..9e9fba0 100644 --- a/lib/site.rb +++ b/lib/site.rb @@ -1,4 +1,5 @@ require 'scraperwiki' +require 'petrify' class Site def self.generate