sitegen.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. class Layout < Erector::Widget
  2. class << self
  3. def inherited(page_class)
  4. puts page_class
  5. (@@page_classes ||= []) << page_class
  6. end
  7. def generate_site
  8. FileUtils.mkdir_p(site_dir)
  9. @@page_classes.each do |page_class|
  10. page_class.generate_html unless page_class.abstract?
  11. puts page_class
  12. end
  13. end
  14. def generate_html
  15. File.open(absolute_path, 'w') do |file|
  16. file.write(new.to_html)
  17. end
  18. end
  19. def absolute_path
  20. absolutize(relative_path)
  21. end
  22. def relative_path
  23. "#{name.gsub('::', '_').underscore}.html"
  24. end
  25. def absolutize(relative_path)
  26. File.join(site_dir, relative_path)
  27. end
  28. def abstract
  29. @abstract = true
  30. end
  31. def abstract?
  32. @abstract
  33. end
  34. def site_dir
  35. File.join(File.dirname(__FILE__), "site")
  36. end
  37. end
  38. def bluecloth(relative_path)
  39. File.open(File.join(File.dirname(__FILE__), relative_path)) do |file|
  40. rawtext BlueCloth.new(file.read).to_html
  41. end
  42. end
  43. def absolutize(relative_path)
  44. self.class.absolutize(relative_path)
  45. end
  46. def link_to(link_text, page_class, section_class=nil)
  47. if instance_of?(page_class) || section_class && is_a?(section_class)
  48. text link_text
  49. else
  50. a link_text, :href => page_class.relative_path
  51. end
  52. end
  53. end