#!/usr/bin/env ruby # require File.expand_path( # File.join(File.dirname(__FILE__), %w[.. lib org-parse])) require 'rubygems' require 'org-parse' require 'optparse' options = {} options_parser = OptionParser.new do |opts| options[:help] = false options[:format] = :html options[:template] = nil opts.banner = "Usage: org-parse [options] " opts.on("-h", "--help", "Show this message") do |v| options[:help] = true end opts.on("-f", "--format FORMAT", [:html, :textile], "Translate the ORG file to the specified format. html(default) or textile") do |v| options[:format] = v end opts.on("-t", "--template TEMPLATE", "Erb template to build the html output.") do |v| options[:template] = v end end begin options_parser.parse! if (ARGV.length == 0) then puts options_parser else data = IO.read(ARGV[0]) opts = {} opts[:default_title] = File.basename(ARGV[0], '.*') parser = OrgParse::StructParser.new(data, opts) root = parser.parse if options[:format] == :html visitor = OrgParse::HtmlVisitor.new(root, options[:template]) elsif visitor = OrgParse::TextileVisitor.new(root) else raise OptionParser::ParseError.new('format error') end puts visitor.build end rescue OptionParser::ParseError puts options_parser end