Skip to content

Instantly share code, notes, and snippets.

@adamvduke
Forked from anonymous/snippet.rb
Created April 17, 2011 05:34
Show Gist options
  • Save adamvduke/923777 to your computer and use it in GitHub Desktop.
Save adamvduke/923777 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Seems a bit silly to have a script to run redcloth considering you can just run
# $ redcloth inputfile.textile > outputfile.html
# but whatever
class Textilize
require 'rubygems'
require 'redcloth'
def run(input_path, output_path)
input_content = ''
input_file = File.new(input_path, 'r')
input_file.each_line do |line|
input_content += line
end
input_file.close
output_content = RedCloth.new(input_content).to_html
output_file = File.new(output_path, 'w')
output_file.write(output_content)
output_file.close
end
end
def usage
puts ""
puts " Takes in a file written in textile markup and writes the corresponding html"
puts ""
puts " usage: ruby textilize.rb infile.textile outfile.html"
puts ""
end
# if you don't pass an input file and an output file, print usage
if (([nil].include? ARGV[0]) || ([nil].include? ARGV[1]))
usage()
else
# TODO: should probably make sure that ARGV[0] exists, and if ARGV[1] exists that it's ok to over-write
Textilize.new.run(ARGV[0], ARGV[1])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment