Skip to content

Commit

Permalink
Merge pull request #719 from kmuto/tsizebuilder
Browse files Browse the repository at this point in the history
//tsizeでビルダ指定できるようにする
  • Loading branch information
kmuto committed Jan 3, 2017
2 parents f9e79d6 + c9f8475 commit 6201340
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 19 deletions.
13 changes: 13 additions & 0 deletions lib/review/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def bind(compiler, chapter, location)
@output = StringIO.new
@book = @chapter.book if @chapter.present?
@tabwidth = nil
@tsize = nil
if @book && @book.config && @book.config["tabwidth"]
@tabwidth = @book.config["tabwidth"]
end
Expand Down Expand Up @@ -450,6 +451,18 @@ def ul_item_begin(lines)
def ul_item_end
end

def tsize(str)
if matched = str.match(/\A\|(.*?)\|(.*)/)
builders = matched[1].split(/,/).map{|i| i.gsub(/\s/, '') }
c = self.class.to_s.gsub(/ReVIEW::/, '').gsub(/Builder/, '').downcase
if builders.include?(c)
@tsize = matched[2]
end
else
@tsize = str
end
end

def inline_raw(args)
if matched = args.match(/\|(.*?)\|(.*)/)
builders = matched[1].split(/,/).map{|i| i.gsub(/\s/, '') }
Expand Down
4 changes: 0 additions & 4 deletions lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@ def sup_end(level)
puts '</div>'
end

def tsize(str)
# null
end

def captionblock(type, lines, caption)
puts %Q[<div class="#{type}">]
unless caption.nil?
Expand Down
4 changes: 0 additions & 4 deletions lib/review/idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1048,10 +1048,6 @@ def label(id)
print "<label id='#{id}' />"
end

def tsize(str)
@tsize = str
end

def dtp(str)
print %Q(<?dtp #{str} ?>)
end
Expand Down
12 changes: 6 additions & 6 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,12 @@ def table_begin(ncols)
if @latex_tsize
puts macro('begin', 'reviewtable', @latex_tsize)
elsif @tsize
cellwidth = @tsize.split(/\s*,\s*/)
puts macro('begin', 'reviewtable', '|'+cellwidth.collect{|i| "p{#{i}mm}"}.join('|')+'|')
if @tsize =~ /\A[\d., ]+\Z/
cellwidth = @tsize.split(/\s*,\s*/)
puts macro('begin', 'reviewtable', '|'+cellwidth.collect{|i| "p{#{i}mm}"}.join('|')+'|')
else
puts macro('begin', 'reviewtable', @tsize)
end
else
puts macro('begin', 'reviewtable', (['|'] * (ncols + 1)).join('l'))
end
Expand Down Expand Up @@ -933,10 +937,6 @@ def compile_href(url, label)
end
end

def tsize(str)
@tsize = str
end

def latextsize(str)
@latex_tsize = str
end
Expand Down
5 changes: 0 additions & 5 deletions lib/review/topbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,6 @@ def label(id)
""
end

def tsize(id)
# FIXME
""
end

def dtp(str)
# FIXME
end
Expand Down
9 changes: 9 additions & 0 deletions test/test_idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ def test_customize_cellwidth

actual = compile_block("//tsize[2]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q|<table><tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="1" aid:tcols="3"><td xyh="1,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="5.669">A</td><td xyh="2,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="11.338">B</td><td xyh="3,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="11.338">C</td></tbody></table>|, actual

actual = compile_block("//tsize[|idgxml|2]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q|<table><tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="1" aid:tcols="3"><td xyh="1,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="5.669">A</td><td xyh="2,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="11.338">B</td><td xyh="3,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="11.338">C</td></tbody></table>|, actual

actual = compile_block("//tsize[|idgxml,html|2]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q|<table><tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="1" aid:tcols="3"><td xyh="1,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="5.669">A</td><td xyh="2,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="11.338">B</td><td xyh="3,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="11.338">C</td></tbody></table>|, actual

actual = compile_block("//tsize[|html|2]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q|<table><tbody xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="1" aid:tcols="3"><td xyh="1,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="9.448">A</td><td xyh="2,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="9.448">B</td><td xyh="3,1,0" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="9.448">C</td></tbody></table>|, actual
end

def test_customize_mmtopt
Expand Down
17 changes: 17 additions & 0 deletions test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,23 @@ def test_table
actual
end

def test_customize_cellwidth
actual = compile_block("//tsize[2,3,5]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(\\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual

actual = compile_block("//tsize[|latex,html|2,3,5]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(\\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual

actual = compile_block("//tsize[|html|2,3,5]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(\\begin{reviewtable}{|l|l|l|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual

actual = compile_block("//tsize[|latex|2,3,5]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(\\begin{reviewtable}{|p{2mm}|p{3mm}|p{5mm}|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual

actual = compile_block("//tsize[|latex||p{5mm}|cr|]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q(\\begin{reviewtable}{|p{5mm}|cr|}\n\\hline\n\\reviewth{A} & B & C \\\\ \\hline\n\\end{reviewtable}\n), actual
end

def test_imgtable
def @chapter.image(id)
item = Book::ImageIndex::Item.new("sampleimg",1, 'sample img')
Expand Down

0 comments on commit 6201340

Please sign in to comment.