Class: Md2site::HTMLUtils
- Inherits:
-
Object
- Object
- Md2site::HTMLUtils
- Defined in:
- lib/md2site/htmlutils0.rb,
lib/md2site/htmlutils.rb
Overview
HTMLファイル分割クラス
Instance Method Summary collapse
-
#divide_html ⇒ Array
HTMLファイル分割.
-
#initialize(htmlfname, mes) ⇒ void
constructor
初期化.
-
#parse_line(state, line) ⇒ Symbol
1行解析.
Constructor Details
#initialize(htmlfname, mes) ⇒ void
初期化
13 14 15 16 |
# File 'lib/md2site/htmlutils0.rb', line 13 def initialize(htmlfname, mes) @htmlfname = htmlfname @mes = mes end |
Instance Method Details
#divide_html ⇒ Array
HTMLファイル分割
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/md2site/htmlutils0.rb', line 50 def divide_html part_struct = Struct.new(:lines, :status) @part0 = part_struct.new([], false) @part1 = part_struct.new([], false) @part2 = part_struct.new([], false) encoding = Nkfguess.guess_file(@htmlfname, @mes) mode = "r:#{encoding}" f = @mes.exc_file_gets(@htmlfname) { File.open(@htmlfname, mode) } @lines = [] @lineno = 0 state = :IN_PART0 while (line = @mes.exc_file_gets(@htmlfname) { f.gets }) state = parse_line(state, line) end @part2.lines << @lines @mes.exc_file_close(@htmlfname) { f.close } [@part0.lines.flatten.join("\n"), @part1.lines.flatten.join("\n"), @part2.lines.flatten.join("\n")] end |
#parse_line(state, line) ⇒ Symbol
1行解析
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/md2site/htmlutils0.rb', line 24 def parse_line(state, line) event = get_event(line) @mes.output_debug("#{@lineno}|#{state}|#{event}|#{line}") case state when :IN_PART0 next_state = state_in_part0(event, line) when :IN_PART1 next_state = state_in_part1(event, line) when :IN_PART2 next_state = state_in_part2(event, line) else @mes.output_fatal("state=#{state}") @mes.output_fatal("event=#{event}") raise end next_state end |