Class: ReVIEW::EPUBMaker

Inherits:
Object show all
Includes:
CallHook, Loggable, MakerHelper
Defined in:
lib/review/epubmaker.rb,
lib/review/epubmaker/epubv2.rb,
lib/review/epubmaker/epubv3.rb,
lib/review/epubmaker/content.rb,
lib/review/epubmaker/producer.rb,
lib/review/epubmaker/epubcommon.rb,
lib/review/epubmaker/zip_exporter.rb,
lib/review/epubmaker/reviewheaderlistener.rb

Defined Under Namespace

Classes: Content, EPUBCommon, EPUBv2, EPUBv3, Producer, ReVIEWHeaderListener, ZipExporter

Instance Attribute Summary

Attributes included from Loggable

#logger

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CallHook

#call_hook

Methods included from Loggable

#app_error, #debug, #error, #error!, #warn

Methods included from MakerHelper

copy_images_to_dir, h

Constructor Details

#initializeEPUBMaker

Returns a new instance of EPUBMaker.



39
40
41
42
43
44
45
46
47
# File 'lib/review/epubmaker.rb', line 39

def initialize
  @producer = nil
  @htmltoc = nil
  @buildlogtxt = 'build-log.txt'
  @logger = ReVIEW.logger
  @img_math = nil
  @img_graph = nil
  @basedir = nil
end

Class Method Details

.execute(*args) ⇒ Object



49
50
51
# File 'lib/review/epubmaker.rb', line 49

def self.execute(*args)
  self.new.execute(*args)
end

Instance Method Details

#build_body(basetmpdir, yamlfile) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/review/epubmaker.rb', line 279

def build_body(basetmpdir, yamlfile)
  @precount = 0
  @bodycount = 0
  @postcount = 0

  @manifeststr = ''
  @ncxstr = ''
  @tocdesc = []
  @img_graph = ReVIEW::ImgGraph.new(@config, 'html', path_name: '_review_graph')

  basedir = File.dirname(yamlfile)
  base_path = Pathname.new(basedir)
  book = ReVIEW::Book::Base.new(basedir, config: @config)
  @converter = ReVIEW::Converter.new(book, ReVIEW::HTMLBuilder.new(img_math: @img_math, img_graph: @img_graph))
  @compile_errors = nil

  book.parts.each do |part|
    if part.name.present?
      if part.file?
        build_chap(part, base_path, basetmpdir, true)
      else
        htmlfile = "part_#{part.number}.#{@config['htmlext']}"
        build_part(part, basetmpdir, htmlfile)
        title = ReVIEW::I18n.t('part', part.number)
        if part.name.strip.present?
          title += ReVIEW::I18n.t('chapter_postfix') + part.name.strip
        end
        @htmltoc.add_item(0, htmlfile, title, chaptype: 'part')
        write_buildlogtxt(basetmpdir, htmlfile, '')
      end
    end

    part.chapters.each do |chap|
      build_chap(chap, base_path, basetmpdir, false)
    end
  end
  check_compile_status

  begin
    @img_graph.make_mermaid_images
  rescue ApplicationError => e
    error! e.message
  end
  @img_graph.cleanup_graphimg
end

#build_chap(chap, base_path, basetmpdir, ispart) ⇒ Object



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/review/epubmaker.rb', line 357

def build_chap(chap, base_path, basetmpdir, ispart)
  chaptype = 'body'
  if ispart
    chaptype = 'part'
  elsif chap.on_predef?
    chaptype = 'pre'
  elsif chap.on_appendix?
    chaptype = 'appendix'
  elsif chap.on_postdef?
    chaptype = 'post'
  end

  filename =
    if ispart.present?
      chap.path
    else
      Pathname.new(chap.path).relative_path_from(base_path).to_s
    end

  id = File.basename(filename).sub(/\.re\Z/, '')

  if @config['epubmaker']['rename_for_legacy'] && ispart.nil?
    if chap.on_predef?
      @precount += 1
      id = sprintf('pre%02d', @precount)
    elsif chap.on_appendix?
      @postcount += 1
      id = sprintf('post%02d', @postcount)
    else
      @bodycount += 1
      id = sprintf('chap%02d', @bodycount)
    end
  end

  if @buildonly && !@buildonly.include?(id)
    warn "skip #{id}.re"
    return
  end

  htmlfile = "#{id}.#{@config['htmlext']}"
  write_buildlogtxt(basetmpdir, htmlfile, filename)
  debug("Create #{htmlfile} from #{filename}.")

  if @config['params'].present?
    warn %Q('params:' in config.yml is obsoleted.)
    if /stylesheet=/.match?(@config['params'])
      warn %Q(stylesheets should be defined in 'stylesheet:', not in 'params:')
    end
  end
  begin
    @converter.convert(filename, File.join(basetmpdir, htmlfile))
    write_info_body(basetmpdir, id, htmlfile, ispart, chaptype)
    remove_hidden_title(basetmpdir, htmlfile)
  rescue StandardError => e
    @compile_errors = true
    error "compile error in #{filename} (#{e.class})"
    error e.message
  end
end

#build_part(part, basetmpdir, htmlfile) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/review/epubmaker.rb', line 325

def build_part(part, basetmpdir, htmlfile)
  debug("Create #{htmlfile} from a template.")
  File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
    @part_number = part.number
    @part_title = part.name.strip
    @title = @part_title
    @body = ReVIEW::Template.generate(path: template_name(localfile: '_part_body.html.erb', systemfile: 'html/_part_body.html.erb'), binding: binding)
    @language = @producer.config['language']
    @stylesheets = @producer.config['stylesheet']
    f.write ReVIEW::Template.generate(path: template_name, binding: binding)
  end
end

#build_pathObject



108
109
110
111
112
113
114
115
116
117
# File 'lib/review/epubmaker.rb', line 108

def build_path
  if @config['debug']
    path = File.expand_path("#{@config['bookname']}-epub", Dir.pwd)
    FileUtils.rm_rf(path, secure: true)
    Dir.mkdir(path)
    path
  else
    Dir.mktmpdir("#{@config['bookname']}-epub-")
  end
end

#build_titlepage(basetmpdir, htmlfile) ⇒ Object



570
571
572
573
574
575
576
577
578
579
# File 'lib/review/epubmaker.rb', line 570

def build_titlepage(basetmpdir, htmlfile)
  @title = h(@config.name_of('booktitle'))
  File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
    @body = ReVIEW::Template.generate(path: template_name(localfile: '_titlepage.html.erb', systemfile: 'html/_titlepage.html.erb'), binding: binding)
    @language = @producer.config['language']
    @stylesheets = @producer.config['stylesheet']

    f.write ReVIEW::Template.generate(path: template_name, binding: binding)
  end
end

#check_compile_statusObject



273
274
275
276
277
# File 'lib/review/epubmaker.rb', line 273

def check_compile_status
  return unless @compile_errors

  error! 'compile error, No EPUB file output.'
end

#check_image_size(basetmpdir, maxpixels, allow_exts = nil) ⇒ Object



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'lib/review/epubmaker.rb', line 625

def check_image_size(basetmpdir, maxpixels, allow_exts = nil)
  begin
    require 'image_size'
  rescue LoadError
    return nil
  end
  require 'find'
  allow_exts ||= @config['image_ext']

  pat = '\\.(' + allow_exts.delete_if { |t| %w[ttf woff otf].member?(t.downcase) }.join('|') + ')'
  extre = Regexp.new(pat, Regexp::IGNORECASE)
  Find.find(basetmpdir) do |fname|
    next unless fname.match(extre)

    img = ImageSize.path(fname)
    next if img.width.nil? || img.width * img.height <= maxpixels

    h = Math.sqrt(img.height * maxpixels / img.width)
    w = maxpixels / h
    fname.sub!("#{basetmpdir}/", '')
    warn "#{fname}: #{img.width}x#{img.height} exceeds a limit. suggeted value is #{w.to_i}x#{h.to_i}"
  end

  true
end

#copy_backmatter(basetmpdir) ⇒ Object



581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# File 'lib/review/epubmaker.rb', line 581

def copy_backmatter(basetmpdir)
  if @config['profile']
    copy_static_file('profile', basetmpdir)
    @htmltoc.add_item(1,
                      File.basename(@config['profile']),
                      ReVIEW::I18n.t('profiletitle'),
                      chaptype: 'post')
  end

  if @config['advfile']
    copy_static_file('advfile', basetmpdir)
    @htmltoc.add_item(1,
                      File.basename(@config['advfile']),
                      ReVIEW::I18n.t('advtitle'),
                      chaptype: 'post')
  end

  if @config['colophon']
    if @config['colophon'].is_a?(String)
      copy_static_file('colophon', basetmpdir, destfilename: "colophon.#{@config['htmlext']}") # override pre-built colophon
    end
    @htmltoc.add_item(1,
                      "colophon.#{@config['htmlext']}",
                      ReVIEW::I18n.t('colophontitle'),
                      chaptype: 'post')
  end

  if @config['backcover']
    copy_static_file('backcover', basetmpdir)
    @htmltoc.add_item(1,
                      File.basename(@config['backcover']),
                      ReVIEW::I18n.t('backcovertitle'),
                      chaptype: 'post')
  end

  true
end

#copy_frontmatter(basetmpdir) ⇒ Object



534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/review/epubmaker.rb', line 534

def copy_frontmatter(basetmpdir)
  if @config['cover'].present? && File.exist?(@config['cover'])
    copy_static_file('cover', basetmpdir)
  end

  if @config['titlepage']
    if @config['titlefile'].nil?
      build_titlepage(basetmpdir, "titlepage.#{@config['htmlext']}")
    else
      copy_static_file('titlefile', basetmpdir, destfilename: "titlepage.#{@config['htmlext']}")
    end
    @htmltoc.add_item(1,
                      "titlepage.#{@config['htmlext']}",
                      ReVIEW::I18n.t('titlepagetitle'),
                      chaptype: 'pre')
  end

  if @config['originaltitlefile'].present?
    copy_static_file('originaltitlefile', basetmpdir)
    @htmltoc.add_item(1,
                      File.basename(@config['originaltitlefile']),
                      ReVIEW::I18n.t('originaltitle'),
                      chaptype: 'pre')
  end

  if @config['creditfile'].present?
    copy_static_file('creditfile', basetmpdir)
    @htmltoc.add_item(1,
                      File.basename(@config['creditfile']),
                      ReVIEW::I18n.t('credittitle'),
                      chaptype: 'pre')
  end

  true
end

#copy_images(resdir, destdir, allow_exts = nil) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/review/epubmaker.rb', line 226

def copy_images(resdir, destdir, allow_exts = nil)
  return nil unless File.exist?(resdir)

  allow_exts ||= @config['image_ext']
  FileUtils.mkdir_p(destdir)
  if @config['epubmaker']['verify_target_images'].present?
    @config['epubmaker']['force_include_images'].each do |file|
      unless File.exist?(file)
        unless /\Ahttps?:/.match?(file)
          warn "#{file} is not found, skip."
        end
        next
      end
      basedir = File.dirname(file)
      FileUtils.mkdir_p(File.join(destdir, basedir))
      debug("Copy #{file} to the temporary directory.")
      FileUtils.cp(file, File.join(destdir, basedir), preserve: true)
    end
  else
    recursive_copy_files(resdir, destdir, allow_exts)
  end
end

#copy_resources(resdir, destdir, allow_exts = nil) ⇒ Object



249
250
251
252
253
254
255
# File 'lib/review/epubmaker.rb', line 249

def copy_resources(resdir, destdir, allow_exts = nil)
  return nil unless File.exist?(resdir)

  allow_exts ||= @config['image_ext']
  FileUtils.mkdir_p(destdir)
  recursive_copy_files(resdir, destdir, allow_exts)
end

#copy_static_file(configname, destdir, destfilename: nil) ⇒ Object



525
526
527
528
529
530
531
532
# File 'lib/review/epubmaker.rb', line 525

def copy_static_file(configname, destdir, destfilename: nil)
  destfilename ||= @config[configname]
  unless File.exist?(@config[configname])
    error! "#{configname}: #{@config[configname]} is not found."
  end
  FileUtils.cp(@config[configname],
               File.join(destdir, destfilename), preserve: true)
end

#copy_stylesheet(basetmpdir) ⇒ Object



513
514
515
516
517
518
519
520
521
522
523
# File 'lib/review/epubmaker.rb', line 513

def copy_stylesheet(basetmpdir)
  return if @config['stylesheet'].empty?

  @config['stylesheet'].each do |sfile|
    unless File.exist?(sfile)
      error! "stylesheet: #{sfile} is not found."
    end
    FileUtils.cp(sfile, basetmpdir, preserve: true)
    @producer.contents.push(ReVIEW::EPUBMaker::Content.new(file: sfile))
  end
end

#detect_properties(path) ⇒ Object



428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/review/epubmaker.rb', line 428

def detect_properties(path)
  properties = []
  File.open(path) do |f|
    doc = REXML::Document.new(f)
    if REXML::XPath.first(doc, '//m:math', 'm' => 'http://www.w3.org/1998/Math/MathML')
      properties << 'mathml'
    end
    if REXML::XPath.first(doc, '//s:svg', 's' => 'http://www.w3.org/2000/svg')
      properties << 'svg'
    end
  end
  properties
end

#execute(*args) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/review/epubmaker.rb', line 76

def execute(*args)
  cmd_config, yamlfile, exportfile = parse_opts(args)
  error! "#{yamlfile} not found." unless File.exist?(yamlfile)

  begin
    @config = ReVIEW::Configure.create(maker: 'epubmaker',
                                       yamlfile: yamlfile,
                                       config: cmd_config)
  rescue ReVIEW::ConfigError => e
    error! e.message
  end
  @producer = ReVIEW::EPUBMaker::Producer.new(@config)
  update_log_level
  debug("Loaded yaml file (#{yamlfile}).")
  @basedir = File.absolute_path(File.dirname(yamlfile))

  produce(yamlfile, exportfile)
end

#parse_headlines(path) ⇒ Object



442
443
444
445
446
447
448
449
450
# File 'lib/review/epubmaker.rb', line 442

def parse_headlines(path)
  headlines = []

  File.open(path) do |htmlio|
    REXML::Document.parse_stream(htmlio, ReVIEWHeaderListener.new(headlines))
  end

  headlines
end

#parse_opts(args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/review/epubmaker.rb', line 53

def parse_opts(args)
  cmd_config = {}
  opts = OptionParser.new
  @buildonly = nil

  opts.banner = 'Usage: review-epubmaker [options] configfile [export_filename]'
  opts.version = ReVIEW::VERSION
  opts.on('--help', 'Prints this message and quit.') do
    puts opts.help
    exit 0
  end
  opts.on('--[no-]debug', 'Keep temporary files.') { |debug| cmd_config['debug'] = debug }
  opts.on('-y', '--only file1,file2,...', 'Build only specified files.') { |v| @buildonly = v.split(/\s*,\s*/).map { |m| m.strip.sub(/\.re\Z/, '') } }

  opts.parse!(args)
  if args.size < 1 || args.size > 2
    puts opts.help
    exit 0
  end

  [cmd_config, args[0], args[1]]
end

#produce(yamlfile, bookname = nil) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/review/epubmaker.rb', line 119

def produce(yamlfile, bookname = nil)
  I18n.setup(@config['language'])
  bookname ||= @config['bookname']
  booktmpname = "#{bookname}-epub"

  @img_math = ReVIEW::ImgMath.new(@config)
  begin
    @config.check_version(ReVIEW::VERSION, exception: true)
  rescue ReVIEW::ConfigError => e
    warn e.message
  end
  debug("#{bookname}.epub will be created.")

  FileUtils.rm_f("#{bookname}.epub")
  if @config['debug']
    FileUtils.rm_rf(booktmpname)
  end

  @img_math.cleanup_mathimg

  basetmpdir = build_path
  begin
    debug("Created first temporary directory as #{basetmpdir}.")

    call_hook('hook_beforeprocess', basetmpdir, base_dir: @basedir)

    @htmltoc = ReVIEW::HTMLToc.new(basetmpdir)
    ## copy all files into basetmpdir
    copy_stylesheet(basetmpdir)

    copy_frontmatter(basetmpdir)
    call_hook('hook_afterfrontmatter', basetmpdir, base_dir: @basedir)

    build_body(basetmpdir, yamlfile)
    call_hook('hook_afterbody', basetmpdir, base_dir: @basedir)

    copy_backmatter(basetmpdir)

    if @config['math_format'] == 'imgmath'
      @img_math.make_math_images
    end
    call_hook('hook_afterbackmatter', basetmpdir, base_dir: @basedir)

    ## push contents in basetmpdir into @producer
    push_contents(basetmpdir)

    if @config['epubmaker']['verify_target_images'].present?
      verify_target_images(basetmpdir)
      copy_images(@config['imagedir'], basetmpdir)
    else
      copy_images(@config['imagedir'], File.join(basetmpdir, @config['imagedir']))
    end

    copy_resources('covers', File.join(basetmpdir, @config['imagedir']))
    copy_resources('adv', File.join(basetmpdir, @config['imagedir']))
    copy_resources(@config['fontdir'], File.join(basetmpdir, 'fonts'), @config['font_ext'])

    call_hook('hook_aftercopyimage', basetmpdir, base_dir: @basedir)

    @producer.import_imageinfo(File.join(basetmpdir, @config['imagedir']), basetmpdir)
    @producer.import_imageinfo(File.join(basetmpdir, 'fonts'), basetmpdir, @config['font_ext'])

    check_image_size(basetmpdir, @config['image_maxpixels'], @config['image_ext'])

    epubtmpdir = nil
    if @config['debug'].present?
      epubtmpdir = File.join(basetmpdir, booktmpname)
      Dir.mkdir(epubtmpdir)
    end
    debug('Call ePUB producer.')
    @producer.produce("#{bookname}.epub", basetmpdir, epubtmpdir, base_dir: @basedir)
    debug('Finished.')
    @logger.success("built #{bookname}.epub")
  rescue ApplicationError => e
    raise if @config['debug']

    error! e.message
  ensure
    FileUtils.remove_entry_secure(basetmpdir) unless @config['debug']
  end
end

#push_contents(_basetmpdir) ⇒ Object



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# File 'lib/review/epubmaker.rb', line 490

def push_contents(_basetmpdir)
  @htmltoc.each_item do |level, file, title, args|
    next if level.to_i > @config['toclevel'] && args[:force_include].nil?

    debug("Push #{file} to ePUB contents.")

    params = { file: file,
               level: level.to_i,
               title: title,
               chaptype: args[:chaptype] }
    if args[:id].present?
      params[:id] = args[:id]
    end
    if args[:properties].present?
      params[:properties] = args[:properties].split(' ') # rubocop:disable Style/RedundantArgument
    end
    if args[:notoc].present?
      params[:notoc] = args[:notoc]
    end
    @producer.contents.push(ReVIEW::EPUBMaker::Content.new(**params))
  end
end

#recursive_copy_files(resdir, destdir, allow_exts) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/review/epubmaker.rb', line 257

def recursive_copy_files(resdir, destdir, allow_exts)
  Dir.open(resdir) do |dir|
    dir.each do |fname|
      next if fname.start_with?('.')

      if FileTest.directory?(File.join(resdir, fname))
        recursive_copy_files(File.join(resdir, fname), File.join(destdir, fname), allow_exts)
      elsif /\.(#{allow_exts.join('|')})\Z/i.match?(fname)
        FileUtils.mkdir_p(destdir)
        debug("Copy #{resdir}/#{fname} to the temporary directory.")
        FileUtils.cp(File.join(resdir, fname), destdir, preserve: true)
      end
    end
  end
end

#remove_hidden_title(basetmpdir, htmlfile) ⇒ Object



417
418
419
420
421
422
423
424
425
426
# File 'lib/review/epubmaker.rb', line 417

def remove_hidden_title(basetmpdir, htmlfile)
  File.open(File.join(basetmpdir, htmlfile), 'r+') do |f|
    body = f.read.
           gsub(%r{<h\d .*?hidden=['"]true['"].*?>.*?</h\d>\n}, '').
           gsub(%r{(<h\d .*?)\s*notoc=['"]true['"]\s*(.*?>.*?</h\d>\n)}, '\1\2')
    f.rewind
    f.print body
    f.truncate(f.tell)
  end
end

#template_name(localfile: 'layout.html.erb', systemfile: nil) ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/review/epubmaker.rb', line 338

def template_name(localfile: 'layout.html.erb', systemfile: nil)
  if @basedir
    layoutfile = File.join(@basedir, 'layouts', localfile)
    if File.exist?(layoutfile)
      return layoutfile
    end
  end

  if systemfile
    return systemfile
  end

  if @producer.config['htmlversion'].to_i == 5
    './html/layout-html5.html.erb'
  else
    './html/layout-xhtml1.html.erb'
  end
end

#update_log_levelObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/review/epubmaker.rb', line 95

def update_log_level
  if @config['debug']
    if @logger.ttylogger?
      ReVIEW.logger = nil
      @logger = ReVIEW.logger(level: 'debug')
    else
      @logger.level = Logger::DEBUG
    end
  elsif !@logger.ttylogger?
    @logger.level = Logger::INFO
  end
end

#verify_target_images(basetmpdir) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/review/epubmaker.rb', line 201

def verify_target_images(basetmpdir)
  @producer.contents.each do |content|
    case content.media
    when 'application/xhtml+xml'
      File.open("#{basetmpdir}/#{content.file}") do |f|
        REXML::Document.new(File.new(f)).each_element('//img') do |e|
          @config['epubmaker']['force_include_images'].push(e.attributes['src'])
          if e.attributes['src'] =~ /svg\Z/i
            content.properties.push('svg')
          end
        end
      end
    when 'text/css'
      File.open(File.join(basetmpdir, content.file)) do |f|
        f.each_line do |l|
          l.scan(/url\((.+?)\)/) do |_m|
            @config['epubmaker']['force_include_images'].push($1.strip)
          end
        end
      end
    end
  end
  @config['epubmaker']['force_include_images'] = @config['epubmaker']['force_include_images'].compact.sort.uniq
end

#write_buildlogtxt(basetmpdir, htmlfile, reviewfile) ⇒ Object



619
620
621
622
623
# File 'lib/review/epubmaker.rb', line 619

def write_buildlogtxt(basetmpdir, htmlfile, reviewfile)
  File.open(File.join(basetmpdir, @buildlogtxt), 'a') do |f|
    f.puts "#{htmlfile},#{reviewfile}"
  end
end

#write_info_body(basetmpdir, _id, filename, ispart = nil, chaptype = nil) ⇒ Object



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/review/epubmaker.rb', line 452

def write_info_body(basetmpdir, _id, filename, ispart = nil, chaptype = nil)
  path = File.join(basetmpdir, filename)
  headlines = parse_headlines(path)

  if headlines.empty?
    warn "#{filename} is discarded because there is no heading. Use `=[notoc]' or `=[nodisp]' to exclude headlines from the table of contents."
    return
  end

  properties = detect_properties(path)
  prop_str = if properties.present?
               ',properties=' + properties.join(' ')
             else
               ''
             end
  first = true
  headlines.each do |headline|
    if ispart.present? && headline['level'] == 1
      headline['level'] = 0
    end
    if first.nil?
      @htmltoc.add_item(headline['level'],
                        filename + '#' + headline['id'],
                        headline['title'],
                        { chaptype: chaptype,
                          notoc: headline['notoc'] })
    else
      @htmltoc.add_item(headline['level'],
                        filename,
                        headline['title'],
                        { force_include: true,
                          chaptype: chaptype + prop_str,
                          notoc: headline['notoc'] })
      first = nil
    end
  end
end