Method: PDF::TechBook#techbook_parse

Defined in:
lib/extensions/pdf-writer/pdf/techbook.rb

#techbook_parse(document, progress = nil) ⇒ Object



517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
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
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/extensions/pdf-writer/pdf/techbook.rb', line 517

def techbook_parse(document, progress = nil)
  @table_of_contents = []

  @toc_title          = "Table of Contents"
  @gen_toc            = false
  @techbook_code      = ""
  @techbook_para      = ""
  @techbook_fontsize  = 12
  @techbook_textopt   = { :justification => :full }
  @techbook_lastmode  = @techbook_mode = :normal

  @techbook_textfont  = "Times-Roman"
  @techbook_codefont  = "Courier"

  @blist_info         = []

  @techbook_line__    = 0

  __build_xref_table(document)

  document.each do |line|
  begin
    progress.inc if progress
    @techbook_line__ += 1

    next if line =~ %r{^#}o

    directive, args = techbook_find_directive(line)
    if directive
        # Just try to call the method/directive. It will be far more
        # common to *find* the method than not to.
      res = __send__("techbook_directive_#{directive}", args) rescue nil
      break if :break == res 
      next
    end

    case @techbook_mode
    when :eval
      @techbook_code << line << "\n"
      next
    when :code
      techbook_text(line)
      next
    when :blist
      line = "<C:#{@blist_info[-1][:style]}/>#{line}"
      techbook_text(line)
      next
    end

    next if techbook_heading(line)

    if :preserved == @techbook_mode
      techbook_text(line)
      next
    end

    line.chomp!

    if line.empty?
      __render_paragraph
      techbook_text("\n")
    else
      @techbook_para << " " unless @techbook_para.empty?
      @techbook_para << line
    end
  rescue Exception => ex
    $stderr.puts PDF::Writer::Lang[:techbook_exception] % [ ex, @techbook_line ]
    raise
  end
  end
end