diff --git a/lib/review/builder.rb b/lib/review/builder.rb
index ffe3b0499..1ac06d0c6 100644
--- a/lib/review/builder.rb
+++ b/lib/review/builder.rb
@@ -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
@@ -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/, '') }
diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb
index 3b713645a..a207a6471 100644
--- a/lib/review/htmlbuilder.rb
+++ b/lib/review/htmlbuilder.rb
@@ -278,10 +278,6 @@ def sup_end(level)
puts ''
end
- def tsize(str)
- # null
- end
-
def captionblock(type, lines, caption)
puts %Q[
]
unless caption.nil?
diff --git a/lib/review/idgxmlbuilder.rb b/lib/review/idgxmlbuilder.rb
index e65510fdd..69b37447c 100644
--- a/lib/review/idgxmlbuilder.rb
+++ b/lib/review/idgxmlbuilder.rb
@@ -1048,10 +1048,6 @@ def label(id)
print ""
end
- def tsize(str)
- @tsize = str
- end
-
def dtp(str)
print %Q()
end
diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb
index 9bccc0bf1..e4d831a82 100644
--- a/lib/review/latexbuilder.rb
+++ b/lib/review/latexbuilder.rb
@@ -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
@@ -933,10 +937,6 @@ def compile_href(url, label)
end
end
- def tsize(str)
- @tsize = str
- end
-
def latextsize(str)
@latex_tsize = str
end
diff --git a/lib/review/topbuilder.rb b/lib/review/topbuilder.rb
index 805281377..992b86d72 100644
--- a/lib/review/topbuilder.rb
+++ b/lib/review/topbuilder.rb
@@ -712,11 +712,6 @@ def label(id)
""
end
- def tsize(id)
- # FIXME
- ""
- end
-
def dtp(str)
# FIXME
end
diff --git a/test/test_idgxmlbuilder.rb b/test/test_idgxmlbuilder.rb
index 65298435d..64914826d 100644
--- a/test/test_idgxmlbuilder.rb
+++ b/test/test_idgxmlbuilder.rb
@@ -114,6 +114,15 @@ def test_customize_cellwidth
actual = compile_block("//tsize[2]\n//table{\nA\tB\tC\n//}\n")
assert_equal %Q|
A
B
C
|, actual
+
+ actual = compile_block("//tsize[|idgxml|2]\n//table{\nA\tB\tC\n//}\n")
+ assert_equal %Q|
A
B
C
|, actual
+
+ actual = compile_block("//tsize[|idgxml,html|2]\n//table{\nA\tB\tC\n//}\n")
+ assert_equal %Q|
A
B
C
|, actual
+
+ actual = compile_block("//tsize[|html|2]\n//table{\nA\tB\tC\n//}\n")
+ assert_equal %Q|
A
B
C
|, actual
end
def test_customize_mmtopt
diff --git a/test/test_latexbuilder.rb b/test/test_latexbuilder.rb
index b296ee58b..05bba0dcf 100644
--- a/test/test_latexbuilder.rb
+++ b/test/test_latexbuilder.rb
@@ -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')