#!/usr/bin/env ruby # Usage: reverse_adoc [FILE]... # Usage: cat FILE | reverse_adoc require "rubygems" require "bundler/setup" require "reverse_adoc" require "optparse" require "fileutils" OptionParser.new do |opts| opts.banner = "Usage: reverse_adoc [options] " opts.on("-m", "--mathml2asciimath", "Convert MathML to AsciiMath") do |_v| ReverseAdoc.config.mathml2asciimath = true end opts.on("-oFILENAME", "--output=FILENAME", "Output file to write to") do |v| ReverseAdoc.config.destination = File.expand_path(v) # puts "output goes to #{ReverseAdoc.config.destination}" end opts.on("-e", "--external-images", "Export images if data URI") do |_v| ReverseAdoc.config.external_images = true end opts.on("-u", "--unknown_tags [pass_through, drop, bypass, raise]", "Unknown tag handling (default: pass_through)") do |v| ReverseAdoc.config.unknown_tags = v end opts.on("-v", "--version", "Version information") do |_v| puts "reverse_adoc: v#{ReverseAdoc::VERSION}" exit end opts.on("-h", "--help", "Prints this help") do puts opts exit end end.parse! if filename = ARGV.pop input_content = IO.read(filename) ReverseAdoc.config.sourcedir = File.dirname(File.expand_path(filename)) else if ReverseAdoc.config.external_images raise "The -e | --external-images feature cannot be used with STDIN input. Exiting." end input_content = ARGF.read end if ReverseAdoc.config.external_images && ReverseAdoc.config.destination.nil? raise "The -e | --external-images feature must be used with -o | --output. Exiting." end # Read from STDIN adoc_content = ReverseAdoc.convert(input_content) # Print to STDOUT unless ReverseAdoc.config.destination puts adoc_content exit end # Write output to ReverseAdoc.config.destination FileUtils.mkdir_p(File.dirname(ReverseAdoc.config.destination)) File.open(ReverseAdoc.config.destination, "w") do |file| file.write(adoc_content) end