Skip to content

Commit

Permalink
Merge pull request #937 from kmuto/hintid
Browse files Browse the repository at this point in the history
フック処理に備え、table/imageにコメントでIDを記載しておく
  • Loading branch information
kmuto authored Feb 28, 2018
2 parents fb18784 + ce08ee4 commit 7171e1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def result_metric(array)
def image_image(id, caption, metric)
metrics = parse_metric('latex', metric)
# image is always bound here
puts '\begin{reviewimage}'
puts "\\begin{reviewimage}%%#{id}"
if metrics.present?
puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
else
Expand Down Expand Up @@ -484,7 +484,7 @@ def indepimage(lines, id, caption = nil, metric = nil)
metrics = parse_metric('latex', metric)

if @chapter.image(id).path
puts '\begin{reviewimage}'
puts "\\begin{reviewimage}%%#{id}"
if metrics.present?
puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
else
Expand Down Expand Up @@ -554,15 +554,15 @@ def table_header(id, caption)
if caption.present?
@table_caption = true
@doc_status[:caption] = true
puts '\begin{table}[h]'
puts "\\begin{table}[h]%%#{id}"
puts macro('reviewtablecaption*', compile_inline(caption))
@doc_status[:caption] = nil
end
else
if caption.present?
@table_caption = true
@doc_status[:caption] = true
puts '\begin{table}[h]'
puts "\\begin{table}[h]%%#{id}"
puts macro('reviewtablecaption', compile_inline(caption))
@doc_status[:caption] = nil
end
Expand Down Expand Up @@ -637,7 +637,7 @@ def imgtable(lines, id, caption = nil, metric = nil)
if caption.present?
@table_caption = true
@doc_status[:caption] = true
puts '\begin{table}[h]'
puts "\\begin{table}[h]%%#{id}"
puts macro('reviewimgtablecaption', compile_inline(caption))
@doc_status[:caption] = nil
end
Expand All @@ -655,7 +655,7 @@ def imgtable(lines, id, caption = nil, metric = nil)
def imgtable_image(id, _caption, metric)
metrics = parse_metric('latex', metric)
# image is always bound here
puts '\begin{reviewimage}'
puts "\\begin{reviewimage}%%#{id}"
if metrics.present?
puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
else
Expand Down
32 changes: 16 additions & 16 deletions test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def @chapter.image(_id)
end

actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
end

def test_image_with_metric
Expand All @@ -434,7 +434,7 @@ def @chapter.image(_id)
end

actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
end

def test_image_with_metric_width
Expand All @@ -446,7 +446,7 @@ def @chapter.image(_id)

@config['image_scale2width'] = true
actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
end

def test_image_with_metric2
Expand All @@ -457,7 +457,7 @@ def @chapter.image(_id)
end

actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
end

def test_image_with_metric2_width
Expand All @@ -469,7 +469,7 @@ def @chapter.image(_id)

@config['image_scale2width'] = true
actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=1.2\\maxwidth,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n), actual
end

def test_indepimage
Expand All @@ -480,7 +480,7 @@ def @chapter.image(_id)
end

actual = compile_block("//indepimage[sampleimg][sample photo]\n")
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
end

def test_indepimage_without_caption
Expand All @@ -492,7 +492,7 @@ def @chapter.image(_id)

# FIXME: indepimage's caption should not be with a counter.
actual = compile_block("//indepimage[sampleimg]\n")
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual
end

def test_indepimage_with_metric
Expand All @@ -503,7 +503,7 @@ def @chapter.image(_id)
end

actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
end

def test_indepimage_with_metric_width
Expand All @@ -515,7 +515,7 @@ def @chapter.image(_id)

@config['image_scale2width'] = true
actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
end

def test_indepimage_with_metric2
Expand All @@ -526,7 +526,7 @@ def @chapter.image(_id)
end

actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n))
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n), actual
end

def test_indepimage_without_caption_but_with_metric
Expand All @@ -538,7 +538,7 @@ def @chapter.image(_id)

# FIXME: indepimage's caption should not be with a counter.
actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
assert_equal %Q(\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual
assert_equal %Q(\\begin{reviewimage}%%sampleimg\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\end{reviewimage}\n), actual
end

def test_table
Expand Down Expand Up @@ -566,7 +566,7 @@ def test_customize_cellwidth

def test_emtable
actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
assert_equal "\\begin{table}[h]\n\\reviewtablecaption*{foo}\n\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n\\end{table}\n\n\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n",
assert_equal "\\begin{table}[h]%%\n\\reviewtablecaption*{foo}\n\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n\\end{table}\n\n\\begin{reviewtable}{|l|l|}\n\\hline\n\\reviewth{aaa} & \\reviewth{bbb} \\\\ \\hline\nccc & ddd\\textless{}\\textgreater{}\\& \\\\ \\hline\n\\end{reviewtable}\n",
actual
end

Expand All @@ -580,10 +580,10 @@ def @chapter.image(_id)
actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")

expected = <<-EOS
\\begin{table}[h]
\\begin{table}[h]%%sampleimg
\\reviewimgtablecaption{test for imgtable}
\\label{table:chap1:sampleimg}
\\begin{reviewimage}
\\begin{reviewimage}%%sampleimg
\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
\\end{reviewimage}
\\end{table}
Expand Down Expand Up @@ -1029,7 +1029,7 @@ def on_appendix?
\\reviewtableref{A.1}{table:chap1:foo}
\\begin{table}[h]
\\begin{table}[h]%%foo
\\reviewtablecaption{FOO}
\\label{table:chap1:foo}
\\begin{reviewtable}{|l|l|}
Expand Down Expand Up @@ -1064,7 +1064,7 @@ def @chapter.image(_id)
\\reviewimageref{A.1}{image:chap1:sampleimg}
\\begin{reviewimage}
\\begin{reviewimage}%%sampleimg
\\includegraphics[width=\\maxwidth]{./images/chap1-sampleimg.png}
\\caption{FOO}
\\label{image:chap1:sampleimg}
Expand Down

0 comments on commit 7171e1b

Please sign in to comment.