Permalink
Browse files

Use TextUtils from builders

  • Loading branch information...
1 parent f0651b7 commit 89406b99b770ecd02bf81765636ec618e5c9f1b8 @kdmsnr kdmsnr committed Feb 23, 2012
Showing with 20 additions and 46 deletions.
  1. +12 −33 lib/review/builder.rb
  2. +1 −1 lib/review/htmlbuilder.rb
  3. +2 −1 lib/review/idgxmlbuilder.rb
  4. +2 −1 lib/review/topbuilder.rb
  5. +3 −10 test/test_builder.rb
View
45 lib/review/builder.rb
@@ -9,13 +9,15 @@
require 'review/book/index'
require 'review/exception'
+require 'review/textutils'
require 'stringio'
-require 'nkf'
require 'cgi'
module ReVIEW
class Builder
+ include TextUtils
+
CAPTION_TITLES = %w(note memo tip info planning best important security caution term link notice point shoot reference practice expert)
def pre_paragraph
@@ -53,28 +55,16 @@ def result
alias :raw_result result
- def convert_outencoding(*s)
- if ReVIEW.book.param["outencoding"] =~ /^EUC$/i
- NKF.nkf("-W, -e", *s)
- elsif ReVIEW.book.param["outencoding"] =~ /^SJIS$/i
- NKF.nkf("-W, -s", *s)
- elsif ReVIEW.book.param["outencoding"] =~ /^JIS$/i
- NKF.nkf("-W, -j", *s)
- else
- ## for 1.9 compatibility
- if s.size == 1
- return s[0]
- end
- return *s
- end
- end
-
def print(*s)
- @output.print(convert_outencoding(*s))
+ @output.print *s.map{|i|
+ convert_outencoding(i, ReVIEW.book.param["outencoding"])
+ }
end
def puts(*s)
- @output.puts(convert_outencoding(*s))
+ @output.puts *s.map{|i|
+ convert_outencoding(i, ReVIEW.book.param["outencoding"])
+ }
end
def list(lines, id, caption)
@@ -405,26 +395,15 @@ def image_ext
end
def inline_include(file_name)
- enc = inencoding()
- compile_inline NKF.nkf("--#{enc}", File.open(file_name).read)
+ compile_inline convert_inencoding(File.open(file_name).read,
+ ReVIEW.book.param["inencoding"])
end
def include(file_name)
- enc = inencoding()
File.foreach(file_name) do |line|
- paragraph([NKF.nkf("--#{enc}", line)])
- end
- end
-
- def inencoding
- if ReVIEW.book.param["inencoding"].nil?
- enc = "utf8"
- else
- # UTF-8, SJIS, EUC => utf8, sjis, euc
- enc = ReVIEW.book.param["inencoding"].gsub(/-/, '').downcase
+ paragraph([convert_inencoding(line, ReVIEW.book.param["inencoding"])])
end
end
- private :inencoding
def ul_item_begin(lines)
ul_item(lines)
View
2 lib/review/htmlbuilder.rb
@@ -96,7 +96,7 @@ def result
end
header += <<EOT
<meta name="generator" content="ReVIEW" />
- <title>#{convert_outencoding(@chapter.title)}</title>
+ <title>#{convert_outencoding(@chapter.title, ReVIEW.book.param["outencoding"])}</title>
</head>
<body>
EOT
View
3 lib/review/idgxmlbuilder.rb
@@ -1045,7 +1045,8 @@ def text(str)
def inline_chapref(id)
chs = ["", "", ""]
unless ReVIEW.book.param["chapref"].nil?
- _chs = NKF.nkf("-w", ReVIEW.book.param["chapref"]).split(",")
+ _chs = convert_inencoding(ReVIEW.book.param["chapref"],
+ ReVIEW.book.param["inencoding"]).split(",")
if _chs.size != 3
error "--chapsplitter must have exactly 3 parameters with comma."
else
View
3 lib/review/topbuilder.rb
@@ -726,7 +726,8 @@ def inline_chap(id)
def inline_chapref(id)
chs = ["", "", ""]
unless ReVIEW.book.param["chapref"].nil?
- _chs = NKF.nkf("-w", ReVIEW.book.param["chapref"]).split(",")
+ _chs = convert_inencoding(ReVIEW.book.param["chapref"],
+ ReVIEW.book.param["inencoding"]).split(",")
if _chs.size != 3
error "--chapsplitter must have exactly 3 parameters with comma."
else
View
13 test/test_builder.rb
@@ -113,20 +113,13 @@ def test_compile_inline
assert_equal [:text, text], @b.compile_inline(text)
end
- def test_convert_outencoding_1arg
- ReVIEW.book.param = {'outencoding' => "UTF-8"}
+ def test_convert_outencoding
+ ReVIEW.book.param = {'outencoding' => "EUC"}
b = Builder.new
- ret = b.convert_outencoding("a")
+ ret = b.convert_outencoding("a", ReVIEW.book.param["outencoding"])
assert_equal "a", ret
end
- def test_convert_outencoding_2arg
- ReVIEW.book.param = {'outencoding' => "UTF-8"}
- b = Builder.new
- ret = b.convert_outencoding("a","b")
- assert_equal(["a","b"], ret)
- end
-
class XBuilder < Builder
def list_header(id, caption)
end

0 comments on commit 89406b9

Please sign in to comment.