class Sew
Constants
- BUILD_DIR
- FILE_REGEX
- PATH_MAP
- VERSION
Public Class Methods
build()
click to toggle source
# File lib/sew.rb, line 20 def self.build clean pages = Dir["[^_]*.mote"].map do |template| Hash.new.tap do |page| parts = File.basename(template, ".mote").split(".") page[:locale] = parts.pop.intern page[:id] = parts.join(".") frontmatter, page[:body] = File.read(template).match(FILE_REGEX)[1..2] page.merge!(YAML.load(frontmatter)) page[:path] = PATH_MAP[(page.delete("path") || page[:id])] page[:destination_dir] = ("./%s/%s" % [BUILD_DIR, page[:locale]]) + page[:path] page[:destination] = page[:destination_dir] + "index.html" end end data = Hash.new.tap do |dat| Dir["*.yml"].map do |file| dat[File.basename(file, ".yml")] = YAML.load_file(file) end end site = OpenStruct.new(JSON.parse({ pages: pages, data: data }.to_json, object_class: OpenStruct)) context = Context.new(site) site.pages.map(&:destination_dir).uniq.each(&FileUtils.method(:mkpath)) site.pages.each do |page| File.open(page.destination, "w") do |file| file.write context.render(page) end end context.after_build end
clean()
click to toggle source
# File lib/sew.rb, line 50 def self.clean FileUtils.rm_rf(BUILD_DIR) end
serve()
click to toggle source
# File lib/sew.rb, line 54 def self.serve build root = File.expand_path(BUILD_DIR) server = WEBrick::HTTPServer.new(:Port => 4567, :DocumentRoot => root) trap('INT') { server.shutdown } server.start end
version()
click to toggle source
# File lib/sew.rb, line 16 def self.version puts VERSION end