Sha256: 7074e6e1b2f9ff032ad58e3d40834cefb0e0d7de7d4529d41c5c0ee7c69d2823
Contents?: true
Size: 1.82 KB
Versions: 4
Compression:
Stored size: 1.82 KB
Contents
#!/usr/bin/env ruby require "htmlbeautifier" require "optparse" require "fileutils" def beautify(name, input, output, options) output.puts HtmlBeautifier.beautify(input, options) rescue => e raise "Error parsing #{name}: #{e}" end executable = File.basename(__FILE__) options = { indent: " " } parser = OptionParser.new do |opts| opts.banner = "Usage: #{executable} [options] [file ...]" opts.separator <<END #{executable} has two modes of operation: 1. If no files are listed, it will read from standard input and write to standard output. 2. If files are listed, it will modify each file in place, overwriting it with the beautified output. The following options are available: END opts.on( "-t", "--tab-stops NUMBER", Integer, "Set number of spaces per indent (default #{options[:tab_stops]})" ) do |num| options[:indent] = " " * num end opts.on( "-T", "--tab", "Indent using tabs" ) do options[:indent] = "\t" end opts.on( "-i", "--indent-by NUMBER", Integer, "Indent the output by NUMBER steps (default 0)." ) do |num| options[:initial_level] = num end opts.on( "-e", "--stop-on-errors", "Stop when invalid nesting is encountered in the input" ) do |num| options[:stop_on_errors] = num end opts.on( "-b", "--keep-blank-lines NUMBER", Integer, "Set number of consecutive blank lines" ) do |num| options[:keep_blank_lines] = num end opts.on( "-h", "--help", "Display this help message and exit" ) do puts opts exit end end parser.parse! if ARGV.any? ARGV.each do |path| input = File.read(path) temppath = path + ".tmp" File.open(temppath, "w") do |output| beautify path, input, output, options end FileUtils.mv temppath, path end else beautify "standard input", $stdin.read, $stdout, options end
Version data entries
4 entries across 4 versions & 2 rubygems