Sha256: 06ea0fe7723015d09e0dd8866fbff162bd2486e80dfafda04b54af273d75e761

Contents?: true

Size: 831 Bytes

Versions: 1

Compression:

Stored size: 831 Bytes

Contents

#!/usr/bin/env ruby

require 'hikidoc'
require 'optparse'
require 'erb'

HTML_TEMPLATE = <<EOS
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title><%=title%></title>
</head>
<body>
<%=body%>
</body>
</html>
EOS

opt = {}
ARGV.options do |o|
  o.banner = "Usage: #$0 [OPTIONS] FILE"

  # fragment mode
  o.on('--fragment', '-f',
          'Output HTML fragments only') do
    opt[:fragment] = true
  end
  o.on('--template=VAL', '-t',
          'Specify a HTML template file') do |v|
    opt[:template] = File.read(v)
  end

  o.parse!
end

opt[:template] ||= HTML_TEMPLATE

case ARGV.size
when 0
  title, txt = '-', $stdin.read
when 1
  title, txt = ARGV[0], File.read(ARGV[0])
else
  usage
end

body = HikiDoc.to_html(txt)

if opt[:fragment]
  puts body
else
  puts ERB.new(opt[:template]).result(binding)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hikidoc-0.0.1 bin/hikidoc