require 'yaml' S5_HEAD = %{ &title;
} S5_TAIL = %{
} module Codex class Pressie def self.process new.process end def process metadata_name = ARGV.shift || usage("Missing metadata file name") load_metadata(metadata_name) input_name = ARGV.shift || usage("Missing input file name") content = Content.new(File.read(input_name)) rescue usage($!.message) header = substitute_metadata_into(S5_HEAD) puts header, content.to_html, S5_TAIL end private def usage(msg = nil) STDERR.puts "pressie.rb " if msg STDERR.puts STDERR.puts msg end exit 1 end def load_metadata(file_name) @metadata = YAML.load_file(file_name) end def substitute_metadata_into(text) text = text.dup %w{author company organization date copyright title}.each do |key| text.gsub!(/&#{key};/, @metadata[key]) if @metadata.has_key?(key) end text end end end