class ReVIEW::EWBBuilder
Constants
- LI
- NAKAGURO
- Z_SPACE
Public Class Methods
new(chap)
click to toggle source
Calls superclass method
ReVIEW::Builder.new
# File lib/review/ewbbuilder.rb, line 11 def initialize(chap) super @footnote_buf = [] @index_buffer = [] end
Public Instance Methods
add_index(str)
click to toggle source
# File lib/review/ewbbuilder.rb, line 367 def add_index(str) @index_buffer.push str "//in#{index_number(@index_buffer.size)}" end
cascade(f)
click to toggle source
# File lib/review/ewbbuilder.rb, line 196 def cascade(f) # FIXME end
chapter_id()
click to toggle source
# File lib/review/ewbbuilder.rb, line 326 def chapter_id File.basename(@filename, '.rd') end
chapter_name(key)
click to toggle source
# File lib/review/ewbbuilder.rb, line 351 def chapter_name(key) '『' + text(@chapter_table.title(key)) + '』' end
chapter_number(key)
click to toggle source
# File lib/review/ewbbuilder.rb, line 334 def chapter_number(key) curr = @chapter_table.number(chapter_id) dest = @chapter_table.number(key) case chapter_id when /\.ewb\z/, 'tmp', 'temp' return '第' + dest + '章' end if dest == curr + 1 '次章' elsif dest == curr - 1 '前章' else "第#{dest}章" end end
chapter_prefix()
click to toggle source
# File lib/review/ewbbuilder.rb, line 330 def chapter_prefix sprintf('%02d', @chapter_table.number(chapter_id)) end
char_length(str)
click to toggle source
# File lib/review/ewbbuilder.rb, line 314 def char_length(str) str.gsub(/./, '.').length end
cmd(lines, caption = nil)
click to toggle source
ReVIEW::Compiler.defsyntax(:cmd, :block, 0..1) {|args|
if args[0] and not args[0] == 'noescape' raise SyntaxError, "unknown //cmd option: #{args[0]}" end
}
# File lib/review/ewbbuilder.rb, line 57 def cmd(lines, caption = nil) puts puts caption puts '//sc1{' lines.each do |line| if noescape puts detab(line) elsif /\AC:.*?>(.+)/ =~ line # DOS prompt hack prompt, cmd = *line.split('>', 2) puts "#{escape(prompt)}>//command{#{escape(cmd)}}//}" else puts escape(detab(line)) end end puts '//}' puts end
emlist(lines, caption = nil)
click to toggle source
ReVIEW::Compiler.defsyntax(:emlist, :block, 0..1) {|args|
if args[0] and not args[0] == 'noescape' raise SyntaxError, "unknown //emlist option: #{args[0]}" end
}
# File lib/review/ewbbuilder.rb, line 35 def emlist(lines, caption = nil) # firstline = f.lineno puts puts caption puts '//lst1' lines.each do |line| if noescape puts detab(line) else puts escape(detab(line)) end end puts '//}' puts end
escape(str)
click to toggle source
# File lib/review/ewbbuilder.rb, line 376 def escape(str) str.gsub(%r{//}, '////') end
figure_filename(key)
click to toggle source
# File lib/review/ewbbuilder.rb, line 218 def figure_filename(key) if ext = key.slice(/\.\w+\z/) base = key.sub(/\.\w+\z/, '') else base = key ext = '.eps' end currname = "images/ch_#{chapter_id}_#{base}#{ext}" destname = "images/fig#{figure_number(base)}#{ext}" unless File.exist? currname # error "image file not exist: #{currname}" end destname end
figure_number(key)
click to toggle source
# File lib/review/ewbbuilder.rb, line 359 def figure_number(key) sprintf(chapter_prefix + '%02d0', @figure_table.number(key)) end
footnote_number(key)
click to toggle source
# File lib/review/ewbbuilder.rb, line 363 def footnote_number(key) sprintf('%02d', @footnote_index.number(key) * 5) end
generate_index()
click to toggle source
# File lib/review/ewbbuilder.rb, line 17 def generate_index @index_buffer.each_with_index do |str, n| printf "%d\t%s\n", index_number(n + 1), str end end
headline(level, caption)
click to toggle source
# File lib/review/ewbbuilder.rb, line 23 def headline(level, caption) puts unless level == 1 puts "//#{'i' * level} #{caption}" puts end
image_dummy()
click to toggle source
# File lib/review/ewbbuilder.rb, line 100 def image_dummy puts '//lst1{' puts '---- dummy figure ----' print dummy puts '//}' puts end
image_header(file, caption)
click to toggle source
# File lib/review/ewbbuilder.rb, line 92 def image_header(file, caption) if /\.png\z/ =~ file and !FileTest.exist?('images/' + file) warn "image file not exist: #{file}" end id = file.sub(/\.\w+\z/, '') puts "//f#{figure_number(id)} #{text(caption)} file=#{file}" if id end
image_label(str)
click to toggle source
# File lib/review/ewbbuilder.rb, line 233 def image_label(str) "#{chapter_id}:#{str}" end
index_number(n)
click to toggle source
# File lib/review/ewbbuilder.rb, line 372 def index_number(n) 900_000 + @chapter_index.number(chapter_id) * 1000 + n end
inline_bou(str)
click to toggle source
# File lib/review/ewbbuilder.rb, line 310 def inline_bou(str) "//ruby{#{escape(str)},#{NAKAGURO * char_length(str)}//}" end
inline_chap(id)
click to toggle source
# File lib/review/ewbbuilder.rb, line 278 def inline_chap(id) chapter_number(arg) end
inline_chapname(id)
click to toggle source
# File lib/review/ewbbuilder.rb, line 286 def inline_chapname(id) chapter_name(arg) end
inline_chapref(id)
click to toggle source
# File lib/review/ewbbuilder.rb, line 282 def inline_chapref(id) chapter_number(arg) + chapter_name(arg) end
inline_em(str)
click to toggle source
# File lib/review/ewbbuilder.rb, line 318 def inline_em(str) "//g{#{arg}//}" end
inline_footnote(id)
click to toggle source
# File lib/review/ewbbuilder.rb, line 299 def inline_footnote(id) '//ky' + footnote_number(id) end
inline_img(arg)
click to toggle source
# File lib/review/ewbbuilder.rb, line 294 def inline_img(arg) error "wrong image label: #{arg}" if /[^a-zA-Z\d\-]/ =~ arg '//f' + figure_number(arg) end
inline_keytop(arg)
click to toggle source
# File lib/review/ewbbuilder.rb, line 274 def inline_keytop(arg) "//keytop{#{arg}//}" end
inline_kw(arg)
click to toggle source
# File lib/review/ewbbuilder.rb, line 260 def inline_kw(arg) word, eng, abbr = arg.split(/,/).map {|s| s.strip } if abbr add_index(word) + "//g{#{word}//}" + add_index(abbr) + "(#{abbr}, " + add_index(eng) + "#{eng})" elsif eng add_index(word) + "//g{#{word}//}" + add_index(eng) + "(#{eng})" else add_index(word) + "//g{#{word}//}" end end
inline_list(arg)
click to toggle source
# File lib/review/ewbbuilder.rb, line 290 def inline_list(arg) '//l' + list_number(arg) end
inline_math(arg)
click to toggle source
# File lib/review/ewbbuilder.rb, line 322 def inline_math(arg) "//LaTeX{ $#{arg}$ //}" end
inline_ruby(arg)
click to toggle source
# File lib/review/ewbbuilder.rb, line 303 def inline_ruby(arg) error 'wrong number of arg: @<ruby>' unless arg.count(',') == 1 "//ruby{#{arg}//}" end
list(lines, id, caption)
click to toggle source
ReVIEW::Compiler.defsyntax(:list, :block, 0..1) {|args|
if args[0] and not args[0] == 'noescape' raise SyntaxError, "unknown //list option: #{args[0]}" end
}
# File lib/review/ewbbuilder.rb, line 81 def list(lines, id, caption) puts puts "//l#{list_number(id)} " + caption puts '//lst2{' lines.each do |line| puts escape(detab(line)) end puts '//}' puts end
list_number(key)
click to toggle source
# File lib/review/ewbbuilder.rb, line 355 def list_number(key) sprintf(chapter_prefix + '%02d0', @list_table.number(key)) end
noindent()
click to toggle source
# File lib/review/ewbbuilder.rb, line 169 def noindent @noindent = true end
note(f, caption)
click to toggle source
# File lib/review/ewbbuilder.rb, line 187 def note(f, caption) puts puts '//note{' puts "//cg{#{caption}//}" puts '//h' cascade f puts '//}' end
ol_begin()
click to toggle source
# File lib/review/ewbbuilder.rb, line 143 def ol_begin output.puts output.puts '//k2{' end
ol_end()
click to toggle source
# File lib/review/ewbbuilder.rb, line 152 def ol_end puts '//}' end
ol_item(num, lines)
click to toggle source
# File lib/review/ewbbuilder.rb, line 148 def ol_item(num, lines) print "#{num}//|" + lines.join('') end
paragraph(lines)
click to toggle source
# File lib/review/ewbbuilder.rb, line 202 def paragraph(lines) if @noindent @noindent = false else print Z_SPACE end prev = '' lines.each do |line| if /[a-zA-Z0-9]\z/ =~ prev and /\A[a-zA-Z0-9]/ =~ line print ' ' end print line end puts end
point(f)
click to toggle source
# File lib/review/ewbbuilder.rb, line 180 def point(f) puts puts '//point{' cascade f puts '//}' end
quote(lines)
click to toggle source
# File lib/review/ewbbuilder.rb, line 156 def quote(lines) puts '//c1{' lines.each do |line| puts text(line) end puts '//}' end
refer(f)
click to toggle source
# File lib/review/ewbbuilder.rb, line 173 def refer(f) puts puts '//refer{' cascade f puts '//}' end
table()
click to toggle source
# File lib/review/ewbbuilder.rb, line 108 def table # %r<\A//table\[(\w+)\]> spec = $1 buf = [] while line = f.gets break if %r[\A//\}] === line buf.push line.strip.split(/\t+/).map {|s| s == '.' ? '' : s } end table_type = 'tabm' output.puts "//#{table_type}[" + spec + ']{' buf.each_with_index do |col, idx| if /----/ === col[0] output.puts '//kb' else output.puts col.map {|s| text(s) }.join("\t") end end output.puts '//}' end
text(str)
click to toggle source
# File lib/review/ewbbuilder.rb, line 237 def text(str) str = str.gsub(/\t/, ' ') str.gsub(/([^@^]+)|\^(.*?)\^|@<(\w+)>\{(.*?)\}|@\{(.*?)\}|([@^])/) do if normal = $1 escape(normal) elsif tt = $2 '//tt{' + escape(tt) + '//}' elsif inline = $3 compile_inline(inline, $4) elsif index = $5 error 'index not implemented' text(index) + index_command(index) elsif char = $6 escape(char) else error "unknown inline: #{str.inspect}" end end rescue DocumentError => e error e.message return 'ERROR' end
ul_begin()
click to toggle source
# File lib/review/ewbbuilder.rb, line 130 def ul_begin puts puts '//k1{' end
ul_end()
click to toggle source
# File lib/review/ewbbuilder.rb, line 139 def ul_end puts '//}' end
ul_item(lines)
click to toggle source
# File lib/review/ewbbuilder.rb, line 135 def ul_item(lines) puts "#{LI}//|" + lines.join('') end
vspace()
click to toggle source
# File lib/review/ewbbuilder.rb, line 164 def vspace print %Q( //h) end