# $WordDic: worddic/ToHTML.rb,v 1.4 2002/12/05 05:44:23 tshiozak Exp $ # Copyright (c) 2002 Takuya SHIOZAKI, # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. =begin HTML output. TBD =end require 'DicRecords' require 'Converter' module WordDic class DefaultLineFormatter def format(rec) ""+ rec.name+"\n"+ rec.contents+"\n" end def reset end end class ToHTML attr_accessor :header attr_accessor :footer attr_accessor :converter attr_accessor :lineFormatter # write to file def put_headfoot(fh, inp) if inp.is_a? String then fh.write @converter.convert(inp) elsif inp.is_a? IO then inp.each { |line| fh.write @converter.convert(line) } else raise TypeError end end def write(file, dic) @lineFormatter.reset if file.is_a? IO then fh = file else fh = File.new(file, "w") end begin put_headfoot(fh, @header) dic.each { |rec| fh.write @lineFormatter.format(rec) } put_headfoot(fh, @footer) ensure fh.close end end # def initialize @header="" @footer="" @lineFormatter = DefaultLineFormatter.new @converter = NullConverter.new end end end