Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XXX_header, XXX_bodyのリファクタリング #1359

Merged
merged 3 commits into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ def talk(lines)

def texequation(lines, id = nil, caption = '')
if id
puts %Q(<div id="#{normalize_id(id)}" class="caption-equation">)
texequation_header(id, caption)
end

Expand All @@ -551,7 +552,6 @@ def texequation(lines, id = nil, caption = '')
end

def texequation_header(id, caption)
puts %Q(<div id="#{normalize_id(id)}" class="caption-equation">)
if get_chap
puts %Q(<p class="caption">#{I18n.t('equation')}#{I18n.t('format_number_header', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>)
else
Expand Down
39 changes: 33 additions & 6 deletions lib/review/idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ def inline_list(id)
end

def list_header(id, caption, _lang)
puts '<codelist>'
return true unless caption.present?
if get_chap.nil?
puts %Q(<caption>#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}</caption>)
Expand All @@ -296,10 +295,21 @@ def codelines_body(lines)
end
end

def list(lines, id, caption, lang = nil)
puts '<codelist>'
begin
list_header(id, caption, lang)
rescue KeyError
error "no such list: #{id}"
end
list_body(id, lines, lang)
puts '</codelist>'
end

def list_body(_id, lines, _lang)
print '<pre>'
codelines_body(lines)
puts '</pre></codelist>'
print '</pre>'
end

def emlist(lines, caption = nil, _lang = nil)
Expand All @@ -315,6 +325,17 @@ def emlistnum(lines, caption = nil, _lang = nil)
quotedlist(lines2, 'emlistnum', caption)
end

def listnum(lines, id, caption, lang = nil)
puts '<codelist>'
begin
list_header(id, caption, lang)
rescue KeyError
error "no such list: #{id}"
end
listnum_body(lines, lang)
puts '</codelist>'
end

def listnum_body(lines, _lang)
print '<pre>'
no = 1
Expand All @@ -331,7 +352,7 @@ def listnum_body(lines, _lang)
print '</listinfo>' if @book.config['listinfo']
no += 1
end
puts '</pre></codelist>'
print '</pre>'
end

def cmd(lines, caption = nil)
Expand Down Expand Up @@ -1134,25 +1155,31 @@ def inline_title(id)
error "unknown chapter: #{id}"
end

def source_header(caption)
def source(lines, caption, lang = nil)
puts '<source>'
source_header(caption)
source_body(lines, lang)
puts '</source>'
end

def source_header(caption)
puts %Q(<caption>#{compile_inline(caption)}</caption>) if caption.present?
end

def source_body(lines, _lang)
puts '<pre>'
codelines_body(lines)
puts '</pre></source>'
print '</pre>'
end

def bibpaper(lines, id, caption)
puts %Q(<bibitem id="bib-#{id}">)
bibpaper_header(id, caption)
bibpaper_bibpaper(id, caption, lines) unless lines.empty?
puts '</bibitem>'
end

def bibpaper_header(id, caption)
puts %Q(<bibitem id="bib-#{id}">)
puts "<caption><span type='bibno'>[#{@chapter.bibpaper(id).number}] </span>#{compile_inline(caption)}</caption>" if caption.present?
end

Expand Down
48 changes: 28 additions & 20 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def builder_init_file
@blank_needed = false
@latex_tsize = nil
@tsize = nil
@table_caption = nil
@cellwidth = nil
@ol_num = nil
@first_line_num = nil
Expand Down Expand Up @@ -606,6 +605,30 @@ def indepimage(lines, id, caption = nil, metric = nil)

alias_method :numberlessimage, :indepimage

def table(lines, id = nil, caption = nil)
if caption.present?
if @book.config.check_version('2', exception: false)
puts "\\begin{table}[h]%%#{id}"
else
puts "\\begin{table}%%#{id}"
end
end

sepidx, rows = parse_table_rows(lines)
begin
table_header(id, caption) if caption.present?
rescue KeyError
error "no such table: #{id}"
end
table_begin(rows.first.size)
table_rows(sepidx, rows)
table_end
if caption.present?
puts '\end{table}'
end
blank
end

def table_rows(sepidx, rows)
if sepidx
sepidx.times do
Expand Down Expand Up @@ -638,25 +661,13 @@ def table_rows(sepidx, rows)
def table_header(id, caption)
if id.nil?
if caption.present?
@table_caption = true
@doc_status[:caption] = true
if @book.config.check_version('2', exception: false)
puts "\\begin{table}[h]%%#{id}"
else
puts "\\begin{table}%%#{id}"
end
puts macro('reviewtablecaption*', compile_inline(caption))
@doc_status[:caption] = nil
end
else
if caption.present?
@table_caption = true
@doc_status[:caption] = true
if @book.config.check_version('2', exception: false)
puts "\\begin{table}[h]%%#{id}"
else
puts "\\begin{table}%%#{id}"
end
puts macro('reviewtablecaption', compile_inline(caption))
@doc_status[:caption] = nil
end
Expand Down Expand Up @@ -759,12 +770,9 @@ def tr(rows)

def table_end
puts macro('end', 'reviewtable')
puts '\end{table}' if @table_caption
@table_caption = nil
@tsize = nil
@latex_tsize = nil
@cellwidth = nil
blank
end

def emtable(lines, caption = nil)
Expand All @@ -780,9 +788,8 @@ def imgtable(lines, id, caption = nil, metric = nil)

begin
if caption.present?
@table_caption = true
@doc_status[:caption] = true
puts "\\begin{table}[h]%%#{id}"
@doc_status[:caption] = true
puts macro('reviewimgtablecaption', compile_inline(caption))
@doc_status[:caption] = nil
end
Expand All @@ -792,8 +799,9 @@ def imgtable(lines, id, caption = nil, metric = nil)
end
imgtable_image(id, caption, metric)

puts '\end{table}' if @table_caption
@table_caption = nil
if caption.present?
puts '\end{table}'
end
blank
end

Expand Down
22 changes: 14 additions & 8 deletions lib/review/markdownbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,26 @@ def noindent
@noindent = true
end

def list_header(id, caption, lang)
def list_header(id, caption, _lang)
if get_chap.nil?
print %Q(リスト#{@chapter.list(id).number} #{compile_inline(caption)}\n\n)
else
print %Q(リスト#{get_chap}.#{@chapter.list(id).number} #{compile_inline(caption)}\n\n)
end
lang ||= ''
puts "```#{lang}"
end

def list_body(_id, lines, _lang)
def list_body(_id, lines, lang)
lang ||= ''
puts "```#{lang}"
lines.each do |line|
puts detab(line)
end
puts '```'
end

def listnum_body(lines, _lang)
def listnum_body(lines, lang)
lang ||= ''
puts "```#{lang}"
lines.each_with_index do |line, i|
puts((i + 1).to_s.rjust(2) + ": #{detab(line)}")
end
Expand Down Expand Up @@ -136,9 +138,9 @@ def dl_end

def emlist(lines, caption = nil, lang = nil)
blank
if caption
if caption.present?
puts caption
print "\n"
blank
end
lang ||= ''
puts "```#{lang}"
Expand Down Expand Up @@ -238,7 +240,11 @@ def image_ext
'jpg'
end

def cmd(lines)
def cmd(lines, caption = nil)
if caption.present?
puts caption
blank
end
puts '```shell-session'
lines.each do |line|
puts detab(line)
Expand Down
4 changes: 1 addition & 3 deletions lib/review/md2inaobuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def paragraph(lines)
puts "\n"
end

def list_header(id, caption, lang)
lang ||= ''
puts "```#{lang}"
def list_header(id, caption, _lang)
print %Q(●リスト#{@chapter.list(id).number}::#{compile_inline(caption)}\n\n)
end

Expand Down
39 changes: 31 additions & 8 deletions lib/review/plaintextbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,30 @@ def read(lines)

alias_method :lead, :read

def list_header(id, caption, _lang)
def list(lines, id, caption, lang = nil)
blank
begin
list_header(id, caption, lang)
rescue KeyError
error "no such list: #{id}"
end
blank
list_body(id, lines, lang)
blank
end

def list_header(id, caption, _lang)
if get_chap
puts %Q(#{I18n.t('list')}#{I18n.t('format_number', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)})
else
puts %Q(#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)})
end
blank
end

def list_body(_id, lines, _lang)
lines.each do |line|
puts detab(line)
end
blank
end

def base_block(_type, lines, caption = nil)
Expand Down Expand Up @@ -181,11 +190,22 @@ def emlistnum(lines, caption = nil, _lang = nil)
blank
end

def listnum(lines, id, caption, lang = nil)
blank
begin
list_header(id, caption, lang)
rescue KeyError
error "no such list: #{id}"
end
blank
listnum_body(lines, lang)
blank
end

def listnum_body(lines, _lang)
lines.each_with_index do |line, i|
puts((i + 1).to_s.rjust(2) + ": #{line}")
end
blank
end

def cmd(lines, caption = nil)
Expand All @@ -207,17 +227,20 @@ def image(_lines, id, caption, _metric = nil)
end

def texequation(lines, id = nil, caption = '')
blank
texequation_header(id, caption)
puts lines.join("\n")
blank
end

def texequation_header(id, caption)
if id
blank
if get_chap
puts "#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
else
puts "#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
end
end

puts lines.join("\n")
blank
end

def table(lines, id = nil, caption = nil, noblank = nil)
Expand Down
Loading