1 # $Id: writer.rb,v 1.3 2011/12/02 04:30:18 machan Exp $
2
3 require 'tmdoc/tmstd'
4 require 'tmdoc/constant'
5 require 'tmdoc/environment'
6 require 'tmdoc/model/document'
7 require 'tmdoc/writer/docbook/writer'
8
9
10 module TmDoc
11
12 module Writer
13 def self.write(mb_store, dir_name, env, &logger)
14 ASSERT.kind_of mb_store, MB::Store
15 ASSERT.kind_of dir_name, String
16 ASSERT.kind_of env, ENV::Environment
17 ASSERT.opt_kind_of logger, Proc
18
19 Writer::DocBook.write mb_store, dir_name, env, &logger
20 end
21
22
23 def self.write_to_file(file_path, &block)
24 ASSERT.kind_of file_path, String
25 ASSERT.kind_of block, Proc
26
27 begin
28 outs = File.open file_path, 'w'
29 outs.sync = false
30 rescue SystemCallError => exception
31 LOG::Fatal.log(
32 "System call error in opening file\n" + "\t%s (%s)",
33 exception.to_s, exception.class.to_s
34 )
35 raise Exception::OutputError
36 rescue IOError => exception
37 LOG::Fatal.log(
38 "I/O error in opening file: '%s'", expand_file_name
39 )
40 raise Exception::OutputError
41 end
42
43 begin
44 block.call outs
45 rescue SystemCallError => exception
46 LOG::Fatal.log(
47 "System call error in writing file\n" + "%s (%s)",
48 exception.to_s, exception.class.to_s
49 )
50 outs.close
51 raise Exception::OutputError
52 rescue IOError => exception
53 LOG::Fatal.log(
54 "I/O error in writing file: '%s'", expand_file_name
55 )
56 outs.close
57 raise Exception::OutputError
58 end
59
60 outs.close
61 end
62 end
63
64 end # TmDoc