Module: Clayoven
- Defined in:
- lib/clayoven.rb,
lib/clayoven/httpd.rb,
lib/clayoven/imapd.rb,
lib/clayoven/config.rb
Defined Under Namespace
Modules: Httpd, Imapd Classes: ConfigData, ContentPage, IndexPage, Page
Class Method Summary collapse
Class Method Details
.main ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/clayoven.rb', line 67 def self.main abort "error: index file not found; aborting" if not File.exists? "index" config = Clayoven::ConfigData.new all_files = (Dir.entries(".") - [".", "..", ".clayoven", "design"]).reject do |entry| config.ignore.any? { |pattern| %r{#{pattern}} =~ entry } end # We must have a "design" directory. I don't plan on making this # a configuration variable. if not Dir.entries("design").include? "template.slim" abort "error: design/template.slim file not found; aborting" end # index_files are files ending in ".index" and "index" # content_files are all other files (we've already applied ignore) # topics is the list of topics. We need it for the sidebar index_files = ["index"] + all_files.select { |file| /\.index$/ =~ file } content_files = all_files - index_files topics = index_files.map { |file| file.split(".index")[0] } # Look for stray files. All content_files that don't have a valid # topic before ":" (or don't have ";" in their filename at all) (content_files.reject { |file| topics.include? (file.split(":", 2)[0]) }) .each do |stray_entry| content_files = content_files - [stray_entry] puts "warning: #{stray_entry} is a stray file or directory; ignored" end # Turn index_files and content_files into objects index_pages = index_files.map { |filename| IndexPage.new(filename) } content_pages = content_files.map { |filename| ContentPage.new(filename) } # Fill in page.title and page.body by reading the file (index_pages + content_pages).each do |page| page.title, page.body = (IO.read page.filename).split("\n\n", 2) end # Compute the indexfill for indexes topics.each do |topic| topic_index = index_pages.select { |page| page.topic == topic }[0] topic_index.indexfill = content_pages.select { |page| page.topic == topic }.sort { |a, b| b. <=> a. } end (index_pages + content_pages).each { |page| page.render topics } end |