From 282f61a752c425f1a4beca76b29976eb29294f03 Mon Sep 17 00:00:00 2001 From: takahashim Date: Wed, 20 Jan 2016 20:32:54 +0900 Subject: [PATCH 1/3] HTMLBuilder: use class instead of width for //image[scale=XXX] cf. #372 --- doc/sample.css | 23 +++++++++++++++++++++++ lib/review/htmlbuilder.rb | 15 ++++++++++++--- test/sample-book/src/style.css | 24 +++++++++++++++++++++++- test/test_htmlbuilder.rb | 10 +++++----- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/doc/sample.css b/doc/sample.css index dcfd4e376..2c709e8ac 100644 --- a/doc/sample.css +++ b/doc/sample.css @@ -106,3 +106,26 @@ p.noindent { p.flushright { text-align: right; } + + +/** + * from EBPAJ EPUB 3 File Creation Guide sample style + * + * cf. http://ebpaj.jp/counsel/guide + */ + +/* image width definition(pacentage) */ +.width-010per { width: 10%; } +.width-020per { width: 20%; } +.width-025per { width: 25%; } +.width-030per { width: 30%; } +.width-033per { width: 33%; } +.width-040per { width: 40%; } +.width-050per { width: 50%; } +.width-060per { width: 60%; } +.width-067per { width: 67%; } +.width-070per { width: 70%; } +.width-075per { width: 75%; } +.width-080per { width: 80%; } +.width-090per { width: 90%; } +.width-100per { width: 100%; } diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index ef4c949ca..d76510a24 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -599,15 +599,24 @@ def texequation(lines) def handle_metric(str) if str =~ /\Ascale=([\d.]+)\Z/ - return "width=\"#{($1.to_f * 100).round}%\"" + return {'class' => sprintf("width-%03dper", ($1.to_f * 100).round)} else k, v = str.split('=', 2) - return %Q|#{k}=\"#{v.sub(/\A["']/, '').sub(/["']\Z/, '')}\"| + return {k => v.sub(/\A["']/, '').sub(/["']\Z/, '')} end end def result_metric(array) - " #{array.join(' ')}" + attrs = {} + array.each do |item| + k = item.keys[0] + if attrs[k] + attrs[k] << item[k] + else + attrs[k] = [item[k]] + end + end + " "+attrs.map{|k, v| %Q|#{k}="#{v.join(' ')}"| }.join(' ') end def image_image(id, caption, metric) diff --git a/test/sample-book/src/style.css b/test/sample-book/src/style.css index e80c7f459..75c67c1bd 100644 --- a/test/sample-book/src/style.css +++ b/test/sample-book/src/style.css @@ -248,4 +248,26 @@ strong{ } em { font-style: italic; -} \ No newline at end of file +} + +/** + * from EBPAJ EPUB 3 File Creation Guide sample style + * + * cf. http://ebpaj.jp/counsel/guide + */ + +/* image width definition(pacentage) */ +.width-010per { width: 10%; } +.width-020per { width: 20%; } +.width-025per { width: 25%; } +.width-030per { width: 30%; } +.width-033per { width: 33%; } +.width-040per { width: 40%; } +.width-050per { width: 50%; } +.width-060per { width: 60%; } +.width-067per { width: 67%; } +.width-070per { width: 70%; } +.width-075per { width: 75%; } +.width-080per { width: 80%; } +.width-090per { width: 90%; } +.width-100per { width: 100%; } diff --git a/test/test_htmlbuilder.rb b/test/test_htmlbuilder.rb index ddcae160c..6cf2a22b7 100644 --- a/test/test_htmlbuilder.rb +++ b/test/test_htmlbuilder.rb @@ -359,7 +359,7 @@ def @chapter.image(id) end actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n") - assert_equal %Q|
\nsample photo\n

\n図1.1: sample photo\n

\n
\n|, actual + assert_equal %Q|
\nsample photo\n

\n図1.1: sample photo\n

\n
\n|, actual end def test_image_with_metric2 @@ -370,7 +370,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|
\nsample photo\n

\n図1.1: sample photo\n

\n
\n|, actual + assert_equal %Q|
\nsample photo\n

\n図1.1: sample photo\n

\n
\n|, actual end def test_image_with_tricky_id @@ -414,7 +414,7 @@ def @chapter.image(id) end actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n") - assert_equal %Q|
\nsample photo\n

\n図: sample photo\n

\n
\n|, actual + assert_equal %Q|
\nsample photo\n

\n図: sample photo\n

\n
\n|, actual end def test_indepimage_with_metric2 @@ -425,7 +425,7 @@ def @chapter.image(id) end actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2, html::class=\"sample\",latex::ignore=params]\n") - assert_equal %Q|
\nsample photo\n

\n図: sample photo\n

\n
\n|, actual + assert_equal %Q|
\nsample photo\n

\n図: sample photo\n

\n
\n|, actual end def test_indepimage_without_caption_but_with_metric @@ -436,7 +436,7 @@ def @chapter.image(id) end actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n") - assert_equal %Q|
\n\n
\n|, actual + assert_equal %Q|
\n\n
\n|, actual end def test_dlist From 2898698c13505ef8468caed609c7264d4947df13 Mon Sep 17 00:00:00 2001 From: takahashim Date: Sun, 24 Jan 2016 15:23:53 +0900 Subject: [PATCH 2/3] fix rubocop warning --- lib/review/htmlbuilder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index d76510a24..ffd83513c 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -616,7 +616,7 @@ def result_metric(array) attrs[k] = [item[k]] end end - " "+attrs.map{|k, v| %Q|#{k}="#{v.join(' ')}"| }.join(' ') + " "+attrs.map{|k, v| %Q|#{k}="#{v.join(' ')}"| }.join(' ') end def image_image(id, caption, metric) From 026ae6850d2bff23da73ec75731f1d52d37e3ce0 Mon Sep 17 00:00:00 2001 From: takahashim Date: Sun, 24 Jan 2016 15:34:47 +0900 Subject: [PATCH 3/3] travis.yml: add libgmp3-dev for fix in TravisCI --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8ce2151b0..4d4d0801e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,10 @@ rvm: - 2.3.0 - ruby-head +addons: + apt_packages: + - libgmp3-dev + branches: only: - master