Skip to content

Instantly share code, notes, and snippets.

@jfahrenkrug
Created January 28, 2009 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfahrenkrug/53953 to your computer and use it in GitHub Desktop.
Save jfahrenkrug/53953 to your computer and use it in GitHub Desktop.
# 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