Created
January 28, 2009 13:57
-
-
Save jfahrenkrug/53953 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2009, Johannes Fahrenkrug, http://springenwerk.com | |
# Licence: use it however you want. | |
# make sure we at least have the input file as an argument | |
if ARGV.size != 2 | |
puts "Usage: ruby inliner.rb inputfile outputfile" | |
else | |
inputfile = ARGV[0] | |
outputfile = ARGV[1] | |
puts "Input file: #{inputfile}" | |
puts "Output file: #{outputfile}" | |
File.open(outputfile, 'w') do |outfile| | |
File.open(inputfile).readlines.each do |line| | |
if line.strip.match(/^###inline/) | |
# ok, we found an inline marker | |
keyvalue = line.strip.split("=") | |
if keyvalue.size != 2 | |
puts "ERROR: invalid inline marker: '#{line.strip}'" | |
else | |
file = keyvalue[1] | |
puts "Inlining #{file}" | |
outfile.puts "/* Inlined from #{file} */" | |
File.open(file).readlines.each do |insert_line| | |
outfile.puts insert_line | |
end | |
end | |
else | |
# put a normal line from the original file into the new one | |
outfile.puts line | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment