Sha256: 623b8e259c3d03e25ce8efec334fa2aa04ee749eecffb50acec824ca7dca0bb8

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

#!/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] <file>"

  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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
org-parse-0.1.2 bin/org-parse