Sha256: 83e0c60447b40d9285230c7374035ceceedcf26785a958efd0c097de0c1c7480

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

#!/usr/bin/env ruby

NAGORO_PATH = File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
$LOAD_PATH.unshift(NAGORO_PATH)

require 'nagoro/version'

require 'optparse'
options = {}

optp = OptionParser.new{|opt|
  ruby_version = "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
  nagoro_version = "Nagoro #{Nagoro::VERSION}, on #{ruby_version}"

  opt.banner = "Usage: nagoro [options] file1.xhtml file2.xhtml ..."
  opt.define_head nagoro_version

  opt.separator ''
  opt.separator 'General Options:'

  opt.on('-v', '--version', 'Show Version') do |v|
    puts nagoro_version
    exit
  end
  opt.on('-h', '--help', 'Show this help') do |h|
    puts opt
    exit
  end
  opt.on('-I', '--include PATH', 'Additional path for $LOAD_PATH') do |r|
    options[:include] = r
  end
}
optp.parse!
puts optp if ARGV.empty?

if rexml = options[:include]
  $LOAD_PATH.unshift(rexml)
end

begin
  require 'rexml/formatters/pretty'
  options[:pretty_available] = true

  # TODO:
  # * Happy monkeypatching a bug in REXML, gotta inform dev.
  module REXML
    module Formatters
      class Default
        unless defined?(old_write)
          alias old_write write

          WRITE_ARITY = new.method(:write).arity

          def write(*args)
            old_write(*args[0...WRITE_ARITY])
          end
        end
      end
    end
  end
rescue LoadError => ex
end

require 'nagoro'
require 'rexml/document'

ARGV.each do |arg|
  if File.file?(arg)
    xhtml = Nagoro.render(arg, :binding => binding)
    doc = REXML::Document.new(xhtml)

    if options[:pretty_available]
      pretty = REXML::Formatters::Pretty.new(2, ie_hack = true)
      # pretty.width = 73
      pretty.compact = true
      out = ''
      pretty.write(doc, out)
      print out
    else
      doc.write($stdout, indent = 1, transitive = false, ie_hack = true)
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
manveru-nagoro-2009.03.21 bin/nagoro
manveru-nagoro-2009.03.28 bin/nagoro
manveru-nagoro-2009.05 bin/nagoro
nagoro-2013.03 bin/nagoro
nagoro-2009.05 bin/nagoro