Planning applications tracker for InLinkUK from BT kiosks. https://kiosks.adrianshort.org/
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

61 lignes
1.8 KiB

  1. require 'haml'
  2. require 'csv'
  3. require 'logger'
  4. class Petrify
  5. @@output_dir = '_site'
  6. @@working_dir = File.join(Dir.pwd, @@output_dir)
  7. @@views_dir = 'views'
  8. @@layout_fn = File.join(@@views_dir, 'layout.haml')
  9. # https://stackoverflow.com/questions/917566/ruby-share-logger-instance-among-module-classes#6768164
  10. @@log = Logger.new($stdout)
  11. @@log.level = Logger::INFO
  12. def self.write_page(path_items, template, locals = {})
  13. dir = create_path(path_items)
  14. fn = File.join(dir, 'index.html')
  15. # https://stackoverflow.com/questions/6125265/using-layouts-in-haml-files-independently-of-rails
  16. html = Haml::Engine.new(File.read(@@layout_fn)).render do
  17. Haml::Engine.new(File.read(File.join(@@views_dir, "#{template}.haml"))).render(Object.new, locals)
  18. end
  19. File.write(fn, html)
  20. @@log.info fn
  21. # TODO - add page to sitemap.xml or sitemap.txt
  22. # https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190
  23. end
  24. def self.write_csv(path_items, filename, data)
  25. dir = create_path(path_items)
  26. fn = File.join(dir, filename + '.csv')
  27. csv_string = CSV.generate do |csv|
  28. csv << data.first.keys # header row
  29. data.each { |row| csv << row.values }
  30. end
  31. File.write(fn, csv_string)
  32. @@log.info fn
  33. end
  34. def self.setup
  35. # Recursively delete working directory to ensure no redundant files are left behind from previous builds.
  36. # FileUtils.rm_rf(@working_dir)
  37. Dir.mkdir(@@working_dir) unless File.directory?(@@working_dir)
  38. # Dir.chdir(@working_dir)
  39. # Copy `public` dir to output dir
  40. FileUtils.copy_entry('public', @@working_dir)
  41. end
  42. def self.create_path(path_items)
  43. dir = File.join(@@output_dir, path_items)
  44. FileUtils.mkdir_p(dir)
  45. @@log.debug dir
  46. dir
  47. end
  48. end