Posted by Googy on 03/02/07 21:33
def readFile(filename)
return "" if not File.exists?(filename)
contents = ""
begin
file = File.new(filename)
while(line = file.readline)
contents += line
end
rescue EOFError
file.close
end
return contents
end
def gen (infile)
incontents = readFile(infile)
markers = []
incontents.scan(/<<(.*?)>>/) {|filename| markers << filename.to_s}
for filename in markers
markcon = gen(filename)
incontents = incontents.gsub(Regexp.new('<<'+filename+">>"),
markcon) if not markcon.nil?
end
return incontents
end
def process (infile)
outfile =""
infile.scan(/(.*?).tel/){|outname| outfile = outname.to_s+".html"}
puts "Output file: "+outfile
ofile = File.new(outfile, "w")
ofile << gen(infile)
ofile.close
end
Here is simple ruby code that I came up with in 1 hr. It just saved
lot of time for me. It can't handle recursive file includes.
File include syntax "<<include file name>>"
just give the input filename to process function.
Thanks anyways.
Bye.
[Back to original message]
|