, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
rttool-1.0.3.0/rttool.ja.html 0000644 0001750 0001750 00000034660 11765335411 015651 0 ustar uwabami uwabami
RTtool
Index
- HTML$B=PNO;~$N%/%m%9%5%$%H%9%/%j%W%F%#%s%0@H
- Ruby 1.9$BBP1~!#(B
- $B2~9T%3!<%I$,(BDOS, MAC$B$@$H$&$^$/F0:n$7$J$$%P%0$r=$@5!#(B
- .rd2rc$B$r;H$o$J$/$J$C$?!#(B
- $B%(%9%1!<%W$G$-$k$h$&$K$J$C$?!#1Q8l$N%I%-%e%a%s%HIUB0!#(B
- Ruby1.8$B$N(Bwarning$B$r:o=|!#(B
- $BId9f$D$-$N?t;z$G$b1&B7$($K$9$k$h$&$K$7$?!#(B
- $B6uGr%;%k$N=hM}$G$N%P%0$rBP=h!#(B
- rt2html-lib.rb: caption$B$,;XDj$7$F$J$$$H$-$O(BCAPTION$BMWAG$r$D$1$J$$$h$&$K!#(B
- $B$"$*$-$5$s$N(Bsetup.rb$B$r;HMQ!#(B $B$=$l$KH<$$!"%Q%C%1!<%89=@.$rJQ99!#(B
- rt2html-lib.rb$B$K$*$$$F%?%0$r>.J8;z$KJQ99!#$3$l$G(BXHTML$B$G$bBg>fIW!#(B
RTtool$B$O%7%s%W%k$J:nI=%D!<%k!#(B
RD$B$NGd$j$G$"$k(B$B2DFI@-(B$B$H(B$B$5$^$6$^$J%U%)!<%^%C%H$KJQ492DG=(B$B$r7Q>5$7!"(B
RDtool$B$N$BM;9g(B$B$5$;$k$3$H$,2DG=$G$"$k!#(B
$B$$$C$F$_$l$P(B$B7;Do$_$?$$$J$b$N$G$"$k!#(B
$B:#$N$H$3$m!"(BRT$B$O(BHTML$B$H(BPlain text$B!JMW(Bw3m$B!K$XJQ49$G$-$k!#(B
w3m$B$N(BWindows$BHG$O(BCygwin$B$7$+$J$$$N$G!"(BWindows$B$N?M$O(BCygwin$B$r;H$&I,MW$,$"$k!#(B
HTML$B$X$NJQ49$N$_I,MW$J$i$P(Bw3m$B$OITMW$G$"$k!#(B
$B@_7W$NJ}$b(BRDtool$B$H;w$;$F$$$k!#(B
parser$B$H(Bvisitor$B$KJ,$1!"(Brt2html-lib.rb$B$r:n@.!#(B
$B0J2<$N%3%^%s%I$r
ruby -ropen-uri -e 'URI("http://www.rubyist.net/~rubikitch/archive/rttool-1.0.3.tar.gz").read.display' > rttool-1.0.3.tar.gz
tar xzvf rttool-1.0.3.tar.gz
$B<:GT$9$k>l9g$O
$B$=$l$+$i
cd rttool-1.0.3
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install
$B%Q%C%1!<%8$K$"$k(B rt $B%G%#%l%/%H%j$r(B $LOAD_PATH $B$NDL$C$?%G%#%l%/%H%j$K%3%T!<$9$k!#(B
require 'rt/rtparse'
$B$H;H$o$l$k$N$G!#(B
- rt/rt2 $B%3%^%s%I$r(B PATH $B$NDL$C$?%G%#%l%/%H%j$K0\F0$9$k!#(B
rt/dot.rt.rd2rc
- $B$b$7(B ~/.rd2rc $B$H$$$&%U%!%$%k$,B8:_$7$J$1$l$P!"(B ~/.rd2rc $B$K%j%M!<%`!#(B
- $BB8:_$9$k$H$-$O!":9J,$rE,59@_Dj$9$k!#(B
RT$B$O(B3$B$D$N(BBlock$B$G9=@.$5$l$k(B
- ConfigBlock
-
$B!VB0@-(B = $BCM!W$NAH$+$i$J$k!#(B
$B0J2<$NNc$G$O(B caption $BB0@-$r@_Dj$7!"I=Bj$r$D$1$F$$$k!#(B
$B$3$N(BBlock$B$O>JN,$G$-$k!#(B
- HeaderBlock
-
HTML$B$G$$$&(BTHEAD$B$NItJ,!#(B
$BI=$N%X%C%@$r@_Dj$9$k!#(B
$B%X%C%@$OCf1{B7$($K$J$k!#(B
$B$3$N(BBlock$B$b>JN,$G$-$k!#(B
- BodyBlock
-
HTML$B$G$$$&(BTBODY$B$NItJ,!#(B
$B%G!<%?$r5-=R$9$k!#(B
$B?t;z$O1&B7$(!"$=$l0J30$O:8B7$($K$J$k!#(B
HeaderBlock, BodyBlock $B$N9`L\$N6h@Z$O(B , $B$+(BTab$B$G$"$k!#(B
- $BI,$:$7$b>e$N9T$HB7$C$F$$$kI,MW$O$J$$!#(B
$B$?$@!"B7$($?J}$,8+$d$9$$$H$O$$$($k!#(B
- $B6h@ZJ8;z$O(B delimiter $BB0@-$NCM$rJQ$($k$3$H$GG$0U$NJ8;zNs$K$G$-$k!#(B
==$B$O:8$NNs$r?-$P$9!#(B
HTML$B$G$$$&(BTH$B!"(BTD$BMWAG$N(Bcolspan$BB0@-$K1F6A!#(B
- rowspan $BB0@-$NCM$rJQ$($k$3$H$GG$0U$NJ8;zNs$K$G$-$k!#(B
||$B$O>e$N9T$r?-$P$9!#(B
HTML$B$G$$$&(BTH$B!"(BTD$BMWAG$N(Browspan$BB0@-$K1F6A!#(B
- colspan $BB0@-$NCM$rJQ$($k$3$H$GG$0U$NJ8;z$K$G$-$k!#(B
ConfigBlock$B$G$O
- caption
-
$BI=$N%?%$%H%k$r@_Dj$9$k!#(B
- delimiter
-
$B%G!<%?$N6h@Z$r;XDj$9$k!#(B
- rowspan
-
$B:8$NNs$r?-$P$9;XDj!#!J%G%U%)%k%H$O(B==
$B!K(B
- colspan
-
$B>e$N9T$r?-$P$9@_Dj!#!J%G%U%)%k%H$O(B||
$B!K(B
- escape
-
delimiter$B$r%G!<%?$K4^$a$kI,MW$,$"$k$H$-$K$3$NB0@-$G;XDj$5$l$?J8;z$rA0CV$9$k!#(B
$B%G%U%)%k%H$G$OL58z$H$J$C$F$$$k!#(B
$BCM$r%+%s%^$G6h@Z$k$N$,0lHV4JC1$J(BRT$B!#(B
$ cat examples/easiest.rt
1, 2, 3
4, 5, 6
7, 8, 9
$ rt2 examples/easiest.rt
$B(#(!(((!(((!($(B
$B("(B 1$B("(B 2$B("(B 3$B("(B
$B('(!(+(!(+(!()(B
$B("(B 4$B("(B 5$B("(B 6$B("(B
$B('(!(+(!(+(!()(B
$B("(B 7$B("(B 8$B("(B 9$B("(B
$B(&(!(*(!(*(!(%(B
$ rt2 -r rt/rt2html-lib examples/easiest.rt
<!-- setup -->
<table border="1">
<!-- setup end -->
<!-- Header -->
<!-- Header end -->
<!-- Body -->
<tbody>
<tr><td align="right">1</td><td align="right">2</td><td align="right">3</td></tr>
<tr><td align="right">4</td><td align="right">5</td><td align="right">6</td></tr>
<tr><td align="right">7</td><td align="right">8</td><td align="right">9</td></tr>
</tbody>
<!-- Body end -->
<!-- teardown -->
</table>
<!-- teardown end -->
RT$B$O(Bdelimiter$B$r<+M3$K;XDj$G$-$k$,!"(Bdelimiter$B$rCO$NJ8$K4^$a$kI,MW$,$"$k$H$-!"(B
- delimiter$B$rJL$J$b$N$KCV49$9$k$+(B
- 1.0.0$B$GF3F~$5$l$?%(%9%1!<%W$r;H$&(B
$B%(%9%1!<%W$O!"(Bdelimiter$BJ8;z$NA0$KCV$/$3$H$G!"(Bdelimiter$B$G$O$J$/$FCO$NJ8$H$_$J$5$l$k!#(B
$ cat examples/escape.rt
delimiter = ;
escape = \
\z ; \;1 ; 2
$ rt2 examples/escape.rt
$B(#(!(((!(((!($(B
$B("(B\z$B("(B;1$B("(B 2$B("(B
$B(&(!(*(!(*(!(%(B
$ rt2 -r rt/rt2html-lib examples/escape.rt
<!-- setup -->
<table border="1">
<!-- setup end -->
<!-- Header -->
<!-- Header end -->
<!-- Body -->
<tbody>
<tr><td align="left">\z</td><td align="left">;1</td><td align="right">2</td></tr>
</tbody>
<!-- Body end -->
<!-- teardown -->
</table>
<!-- teardown end -->
$ cat examples/test1.rt
caption = Test Table
, Human, == , Dog , ==
|| , M , F ,M,F
x , 1.0 , 2.0, 1.1, 1.2
y , 0.4 , 0.5, 0.3, 0.1
$ rt2 examples/test1.rt
Test Table
$B(#(!(((!(!(!(!(!(((!(!(!(!(!($(B
$B("(B $B("(B Human $B("(B Dog $B("(B
$B("(B $B('(!(!(((!(!(+(!(!(((!(!()(B
$B("(B $B("(B M $B("(B F $B("(B M $B("(B F $B("(B
$B('(!(+(!(!(+(!(!(+(!(!(+(!(!()(B
$B("(Bx $B("(B 1.0$B("(B 2.0$B("(B 1.1$B("(B 1.2$B("(B
$B('(!(+(!(!(+(!(!(+(!(!(+(!(!()(B
$B("(By $B("(B 0.4$B("(B 0.5$B("(B 0.3$B("(B 0.1$B("(B
$B(&(!(*(!(!(*(!(!(*(!(!(*(!(!(%(B
$ rt2 -r rt/rt2html-lib examples/test1.rt
<!-- setup -->
<table border="1">
<caption>Test Table</caption>
<!-- setup end -->
<!-- Header -->
<thead>
<tr><th rowspan="2"></th><th colspan="2">Human</th><th colspan="2">Dog</th></tr>
<tr><th>M</th><th>F</th><th>M</th><th>F</th></tr>
</thead>
<!-- Header end -->
<!-- Body -->
<tbody>
<tr><td align="left">x</td><td align="right">1.0</td><td align="right">2.0</td><td align="right">1.1</td><td align="right">1.2</td></tr>
<tr><td align="left">y</td><td align="right">0.4</td><td align="right">0.5</td><td align="right">0.3</td><td align="right">0.1</td></tr>
</tbody>
<!-- Body end -->
<!-- teardown -->
</table>
<!-- teardown end -->
$B$5$i$K!"(BRD$B$KKd$a9~$`$3$H$b$G$-$k$N$@!#(B
RT$B$O(BRD$B$G$O$J$$$N$G(BRD$B$N(Bfilter$B5!G=$r;H$&(B$B$3$H$K$J$k!#(B
$B$3$l$GI=$D$-$N%F%-%9%H$r@8@.$G$-$k!#(B
begin$B$H(Bend$B$,HQ;($J$N$O(BRDtool$B$N;EMM$J$N$G$7$g$&$,$J$$!#(B
$B%3%^%s%I%i%$%s$,D9$/$J$k$N$G(Brdrt2$B$H$$$&%3%^%s%I$rMQ0U!#(B
$ cat examples/rttest.rd
=begin
= Sample RD/RT
This RD contains a table.
It is so-called RD/RT.
=end
=begin RT
caption = Test Table
, Human, == , Dog , ==
|| , M , F ,M,F
x , 1.0 , 2.0, 1.1, 1.2
y , 0.4 , 0.5, 0.3, 0.1
=end
=begin
It is simple.
=end
$ rdrt2 examples/rttest.rd | w3m -dump -T text/html
= Sample RD/RT
This RD contains a table. It is so-called RD/RT.
Test Table
$B(#(!(((!(!(!(!(!(((!(!(!(!(!($(B
$B("(B $B("(B Human $B("(B Dog $B("(B
$B("(B $B('(!(!(((!(!(+(!(!(((!(!()(B
$B("(B $B("(B M $B("(B F $B("(B M $B("(B F $B("(B
$B('(!(+(!(!(+(!(!(+(!(!(+(!(!()(B
$B("(Bx $B("(B 1.0$B("(B 2.0$B("(B 1.1$B("(B 1.2$B("(B
$B('(!(+(!(!(+(!(!(+(!(!(+(!(!()(B
$B("(By $B("(B 0.4$B("(B 0.5$B("(B 0.3$B("(B 0.1$B("(B
$B(&(!(*(!(!(*(!(!(*(!(!(*(!(!(%(B
It is simple.
HTML$B$d(BLaTeX$B$NI=$N=q$-J}$,$A$g$$%$%i$D$/!#(B
RD$B$KI=:n@.5!G=$,$"$l$P$$$$$,!"$$$m$$$mJ@32$,!#(B
- RD$B$NJ8K!$,J#;($K$J$k!#(B
- RD$B$H$7$F8+?I$/$J$k!#(B
- RT$B$NItJ,$@$1FH<+$KJQ99$,2DG=!#(B
- $B26$,(BRD$B$r0&$7$F$k$+$i!#(B
- $B<+J,$K9g$C$?I=:n@.%D!<%k$,$[$7$$!#(B
$BLs(B9$BG/!"$$$m$$$m$J$3$H$r9M$($F$$$?$,8=:_$N%7%s%W%k$J;EMM$N$^$^$,$$$$$HH=CG$7$?!#(B
Ruby's$B$H$7$^$9!#(B
rttool-1.0.3.0/test/ 0000775 0001750 0001750 00000000000 11765335411 014017 5 ustar uwabami uwabami rttool-1.0.3.0/test/test-rt2html-lib.rb 0000644 0001750 0001750 00000005042 11765335411 017460 0 ustar uwabami uwabami require 'rt/rt2html-lib'
require 'test/unit'
include RT
module Utils
def uncomment(str)
rep = "\001"
#if str =~ /\A\n(.+)\n\n\Z/p# POSIX
if str.gsub(/\n/, rep) =~ /\A#{rep}(.+)#{rep}#{rep}\Z/
#$1
$1.gsub(/#{rep}/, "\n")
else
assert_fail("not RTBlock format")
end
end
end
class RT2HTMLVisitorTest < Test::Unit::TestCase
def setup
@x = RT2HTMLVisitor::new
@x.visit(RTParser::parse(<<-END))
caption = Test Table
, Human, == , Dog , ==
|| , M , F ,M,F
x , 1.0 , 2.0, 1.1, 1.2
y , 0.4 , 0.5, 0.3, 0.1
END
end
include Utils
def test_setup
lines =
%Q[\n] +
%Q[Test Table\n]
assert_equal(lines, uncomment(@x.setup))
end
def test_teardown
assert_equal(%Q[
\n], uncomment(@x.teardown))
end
def test_visit_Header
lines =
%Q[\n] +
%Q[ | Human | Dog |
\n] +
%Q[M | F | M | F |
\n] +
%Q[\n]
assert_equal(lines, uncomment(@x.visit_Header))
end
def test_visit_Body
lines =
%Q[\n] +
%Q[x | 1.0 | 2.0 | 1.1 | 1.2 |
\n] +
%Q[y | 0.4 | 0.5 | 0.3 | 0.1 |
\n] +
%Q[\n]
assert_equal(lines, uncomment(@x.visit_Body))
end
def test0
assert_equal(RT::RTCell, RT::RTCell::new("a").class)
end
end
class RT2HTMLXSSTest < Test::Unit::TestCase
def setup
@x = RT2HTMLVisitor::new
@x.visit(RTParser::parse(<<-END))
caption = XSS Test
Test, ==
1.0 , a
END
end
include Utils
def test_setup
lines =
%Q[\n] +
%Q[<b>XSS Test</b>\n]
assert_equal(lines, uncomment(@x.setup))
end
def test_visit_Header
lines =
%Q[\n] +
%Q[<b>Test</b> |
\n] +
%Q[\n]
assert_equal(lines, uncomment(@x.visit_Header))
end
def test_visit_Body
lines =
%Q[\n] +
%Q[<b>1.0</b> | <b>a</b> |
\n] +
%Q[\n]
assert_equal(lines, uncomment(@x.visit_Body))
end
end
rttool-1.0.3.0/test/test-rtparser.rb 0000644 0001750 0001750 00000012467 11765335411 017173 0 ustar uwabami uwabami #!/usr/bin/ruby
require 'rt/rtparser'
require 'test/unit'
require 'nkf'
include RT
class RTCellTest < Test::Unit::TestCase
def test_equal
assert_equal(RTCell::new(""), RTCell::new("", :left))
assert_equal(RTCell::new(""), RTCell::new("", :right))
assert_equal(RTCell::new(""), RTCell::new("", :center))
end
def test_align
assert_equal(:left, RTCell::new("value").align)
assert_equal(:left, RTCell::new("value", :left).align)
assert_equal(:left, RTCell::new("1", :left).align)
assert_equal(:center, RTCell::new("value", :center).align)
assert_equal(:center, RTCell::new("1.90", :center).align)
assert_equal(:right, RTCell::new("1.1kg").align)
assert_equal(:right, RTCell::new("value", :right).align)
assert_raises(RuntimeError){ RTCell::new("value", :error)}
end
end
module CellShortcut
private
def c(x) RTCell::new(x,:center) end
def l(x) RTCell::new(x, :left) end
def r(x) RTCell::new(x, :right) end
end
class RTParserTest < Test::Unit::TestCase
def setup
@x = RTParser::new
end
def test_blocks
blocks = lambda{|str| @x.make_blocks(str).blocks}
# no block
assert_equal([[], [], []], blocks.call(""))
# 1 block: body
assert_equal([[], [], ["body"]], blocks.call("body"))
# 2 blocks: config body
assert_equal([["config"], [], ["body"]] ,blocks.call("config\n\nbody"))
# 3 blocks: config header body
assert_equal([["config1", "config2"], ["header"], ["body"]], blocks.call("config1\nconfig2\n\nheader\n\nbody"))
assert_raises(RuntimeError){ blocks.call("config\n\nheader\n\nbody\n\nextra")}
end
def test_parse_config
dc = RTParser::DefaultConfig
pc = lambda{|config_line| @x.parse_config(config_line).config}
assert_equal(dc, pc.call([]))
assert_equal(dc.update("p1"=>"v1", "p2"=>"v2", "p3"=>"v3"),
pc.call(["p1 = v1", "#comment", " p2= v2", "p3=v3"]))
assert_equal(dc.update("p1"=>"\t"), pc.call(["p1 = \t"]))
assert_raises(RuntimeError){ pc.call(["p1 = v1", "error"])}
end
include CellShortcut
def test_parse_header
ph = lambda{|header_line| @x.parse_header(header_line).header}
assert_equal([ [c(""), c("wide"), "==", c("std")],
[c("x"), c("1"), c("x2"), c("tall")],
[c(""), c("y1"), c("y2"), "||"]],
ph.call([ " , wide, == , std",
"#comment",
" x , 1 , x2, tall",
" , y1 , y2, || "]))
assert_equal([[c(""), c("x"), c("y"), c("z")]],
ph.call(["\t,x\t ,y \t,z"]))
assert_equal([[c(""), c("X"), c("Y"), c("Z")]],
ph.call(["\tX\t\tY\tZ"]))
assert_equal([[c(""), c("1999"), c(""), c("2000"), c("")]],
ph.call([",\t1999,\t,\t2000,"]))
assert_raises(RuntimeError){
ph.call([ " , wide, == , std",
"#comment",
" , x1 , differenterror ",
", y1 , y2, == "])}
end
def test_parse_body
pb = lambda{|body_line| @x.parse_body(body_line).body}
assert_equal([ [c(""), l("wide"), "==", r("-101")],
[c(""), r("2.2kg"), r("2L"), l("tall")],
[c(""), l("y1"), l("y2"), "||"],
[l("a"),l("b"), c(""), c("")]],
pb.call([ "#comment-----------",
" , wide, == , -101",
" , 2.2kg, 2L, tall",
", y1 , y2, ||",
"a, b,,"]))
end
def test_calc_span
tbl = [ [c(""), l("wide"), "==", "=="],
[c(""), r("2.2kg"), r("2L"), l("tall")],
[c(""), l("y1"), l("y2"), "||"]]
@x.calc_span(tbl)
assert_equal(1, tbl[0][0].rowspan)
assert_equal(1, tbl[0][0].colspan)
assert_equal(3, tbl[0][1].colspan)
assert_equal(2, tbl[1][3].rowspan)
end
end
class RTParseTest < Test::Unit::TestCase
include CellShortcut
module CRLF
include NKF
def to_unix(str) nkf("-eLu", str) end
def to_dos(str) nkf("-eLw", str) end
def to_mac(str) nkf("-eLm", str) end
end
def setup
@rt = <<-END
delimiter = ;
rowspan = @
; x ; @
z ; 1 ; 2
zz ; 3 ; 4
END
end
def check
assert_equal(';', @x.config['delimiter'])
assert_equal('@', @x.config['rowspan'])
assert_equal([[c(""), c("x"), "@"]], @x.header)
assert_equal([ [l("z"), r("1"), r("2")],
[l("zz"),r("3"), r("4")],
], @x.body)
end
include CRLF
def test_unix
@x = RTParser::parse(to_unix(@rt))
check
end
def test_dos
@x = RTParser::parse(to_dos(@rt))
check
end
def test_mac
@x = RTParser::parse(to_mac(@rt))
check
end
end
class RTParseWithEscapeTest
def test__parse__with_escape1
x = RTParser::parse <<-'END'
delimiter = ;
escape = %
%z ; %;1 ; 2
END
assert_equal(';', x.config['delimiter'])
assert_equal([ [l("%z"), l(";1"), r("2")],], x.body)
end
def test__parse__with_escape2
x = RTParser::parse <<-'END'
delimiter = ;
escape = \
\z ; \;1 ; 2
END
assert_equal(';', x.config['delimiter'])
assert_equal([ [l("\\z"), l(";1"), r("2")],], x.body)
end
end
rttool-1.0.3.0/test/rttool-sub.rb 0000644 0001750 0001750 00000047452 11765335411 016470 0 ustar uwabami uwabami # This script is auto-generated. DON'T EDIT!!!
#!/usr/bin/env ruby
=begin
== Candidates
# (view-srcfile "tgen/test-tgen.rb" "assert_permission")
=end
#### print
class Object
# puts MSG = self.inspect
# for debug.
def pr(msg=nil)
if msg then
print "#{msg} = "
end
display
print "\n"
self
end
# pr when $VERBOSE
def vpr(msg=nil)
if $VERBOSE then
self.pr msg
else
self
end
end
# eval and print
def ev(str)
puts "#{str} = #{eval str}"
end
end
#### array
class Array
# Make random value array. length==n
def Array.rand(n, r=0)
(1 .. n).collect{super(r)}
end
# join ' '
def js
join ' '
end
end
#### vrequire
# verbose require
def vrequire(f)
puts "loading " + f + "..."
require f
puts "loading " + f + "...done"
end
#### vsystem
# verbose system
def vsystem(cmd)
puts cmd
system cmd
end
#### time
class Time
# Simple benchmark function.
# Time.time(start_msg) { ... }
def Time.time(smsg="", emsg="%s seconds")
s=Time.now
print smsg
puts if smsg != ""
yield
sec=Time.now - s
printf emsg, sec
puts ""
end
end
#### nonzero
class Numeric
# 1 : self >=0 / -1 : self < 0
def sign
if self >= 0 then 1 else -1 end
end
# If self is negative, returns 0
def nonzero
[self, 0].max
end
end
class Vector
# If self is negative, returns 0
def nonzero
map{|x| x.nonzero}
end
end
class Matrix
# If self is negative, returns 0
def nonzero
map{|x| x.nonzero}
end
end
#### sigma
module Math
# Math.sigma(b, e) { expr }
def sigma(b,e)
if b > e then
0
else
s=0
b.upto(e) do |i|
s += yield(i) || 0
end
s
end
end
alias sum sigma
module_function :sigma
end
#### nonempty
class Object
# Is self non-nil and not-empty.
def nonempty?
if self and !self.empty?
self
end
end
end
#### tempfile
require 'pathname'
require 'tempfile'
require 'tmpdir'
class << Tempfile
# Create a temporary file whose contents is CONTENT.
# Returns the file's path.
def path(content, dir=Dir.tmpdir)
x = Tempfile.open("content", dir)
x.write content
x.close
x.open
x.path
end
# Similar to Tempfile.path. But returns Pathname object.
def pathname(content, dir=Dir.tmpdir)
Pathname.new(path(content, dir=Dir.tmpdir))
end
end
#### untar
module Untar
# Returns a command to uncompress an archive FILE.
def untar_command(file)
f = file
case f
when /\.tar\.gz$/, /\.tgz$/
"(tar xzvf #{f} || tar xvf #{f})"
when /\.tar\.bz2$/
"(tar xjvf #{f} || tar xvf #{f})"
when /\.tar$/, /\.gz$/
"tar xf #{f}"
when /\.zip$/
"unzip #{f}"
when /\.lzh$/
"lha x #{f}"
when /\.afz$/
"afio -ivZ #{f}"
when /\.rar$/i
"unrar %s"
when /\.sit$/i
"ln -s %s tmp.sit; unstuff tmp.sit"
when /\.7z$/i
"7za e #{f}"
else
nil
end
end
end
#### getopts
def _getopts_sub(argv, single_opts, *long_opts)
require 'optparse'
opt = OptionParser.new
(single_opts || "").split(//).each do |single_opt|
opt.on("-#{single_opt}"){ eval "$OPT_#{single_opt}=true" }
end
long_opts.each do |long_opt|
have_arg_p = (long_opt[-1,1] == ':')
long_opt.chomp!(':')
block = lambda{|x| eval "$OPT_#{long_opt}=x"}
if have_arg_p
if long_opt.length == 1 # -x arg
opt.on("-#{long_opt} [ARG]",&block)
else # --long arg
opt.on("--#{long_opt}=[ARG]",&block)
end
else # --long
opt.on("--#{long_opt}"){ eval "$OPT_#{long_opt}=true"}
end
end
opt.parse! argv
end
# getopts compatibility layer using optparse.rb
def getopts(single_opts, *long_opts)
_getopts_sub ARGV, single_opts, *long_opts
end
#### run config
# run config
# c = RunConfig.new("test")
# c.run_user_config
# c.run_local_config
#
class RunConfig
def initialize(name)
@name = name
end
def run_user_config
run_config [File.expand_path("~/.#{@name}rc")] if ENV.key?("HOME")
end
def run_local_config
rcs = []
rcs.push ".#{@name}rc"
rcs.push "#{@name}.rc"
rcs.push "_#{@name}rc"
rcs.push "$#{@name}rc"
rcs.push "#{@name}rc"
run_config rcs
end
private
def run_config(rcs)
catch(:EXIT) do
for rc in rcs
begin
load rc
throw :EXIT
rescue LoadError, Errno::ENOENT
rescue
print "load error: #{rc}\n"
print $!.class, ": ", $!, "\n"
for err in $@[0, $@.size - 2]
print "\t", err, "\n"
end
throw :EXIT
end
end
end
end
end
#### set_attr
class Object
# Defines a singleton attribute. for testing purpose.
def set_attr(ivar_name, init_value)
eval("class << self; attr_accessor :#{ivar_name} end")
self.instance_variable_set("@#{ivar_name}", init_value)
end
end
#### quote
class String
def quote(q="'")
%Q[#{q}#{self}#{q}]
end
# This function is different from dump.
def dquote
quote('"')
end
end
#### assert-file
# Example1:
# es = AssertFile.new("testdata/shorten-test.e")
# el = AssertFile.new("testdata/shorten-test.el")
# system "shorten.rb -l #{el} -e #{es} testdata/shorten-test-input.e"
# assert_file(es)
# assert_file(el)
#
# Example2:
# assert_file(:expected=>expected, :actual=>actual, :no_remove=>true)
#
# Example3:
# AssertFile.transaction(expected) {|asf|
# system "foo input > #{asf}"
# }
class AssertFile
require 'fileutils'
@@basedir = nil
def self.basedir=(basedir)
@@basedir = basedir
end
def self.transaction(*args, &block)
if block_given?
testcase = eval("self", block.binding)
assert_files = args.map{|x| new(x) }
if @@basedir
Dir.chdir(@@basedir) { yield assert_files }
else
yield(assert_files)
end
assert_files.each{|asf| testcase.assert_file(asf)}
else
raise ArgumentError, "must have block"
end
end
# new("expected_filename")
# new(:expeced=>"expected_filename", :actual=>"actual_filename")
# new(:expeced=>"expected_filename", :actual=>"actual_filename", :diff=>"diff")
def initialize(arg)
require 'test/unit'
case arg
when String # expected
@expected = arg
@actual = arg+".actual"
@diff = arg+".diff"
when Hash
@basedir = arg[:basedir]
@expected = arg[:expected]
@no_remove = arg[:no_remove]
@actual = arg[:actual] || (@expected+".actual")
@diff = arg[:diff] || (@expected+".diff")
else
raise TypeError, "AssertFile.new: must be String or Hash."
end
@basedir ||= @@basedir
FileUtils.mkdir_p @basedir if @basedir
@expected = pathconv(@expected)
@actual = pathconv(@actual)
@diff = pathconv(@diff)
end
attr_accessor :expected, :actual, :diff, :no_remove
def pathconv(path)
if @basedir
File.expand_path(path, @basedir)
else
path
end
end
def unlink_diff
File.unlink(diff) if File.exist?(diff)
end
def make_diff
system "diff -u #{expected} #{actual} | tee #{diff}"
end
def to_s
actual
end
alias :to_str :to_s
end
module Test
module Unit
# Use at Test::Unit::Assertions::AssertionMessage#convert
class System
def initialize(cmd)
@cmd = cmd
end
def inspect
`#{@cmd}`.to_s
end
end
module Assertions
def assert_file(assert_file, message=nil)
AssertFile === assert_file or assert_file = AssertFile.new(assert_file)
$>.sync = true
assert_file.unlink_diff
diff = System.new("diff -u #{assert_file.expected} #{assert_file.actual} | tee #{assert_file.diff}")
full_message = build_message(message, <#{content}"
end
# Same as textarea_ize. But the string is not escaped.
# It is expected that the string is HTML.
def textarea_ize_noconv(cols=nil, rows=nil)
textarea_ize(cols, rows, false)
end
end
#### redirect
class << IO
# Redirect stdout to STDOUT and executes the block.
def redirect(stdout)
begin
stdout_sv = STDOUT.dup
STDOUT.reopen(stdout)
yield
ensure
STDOUT.flush
STDOUT.reopen(stdout_sv)
end
end
end
#### system_to_string depend:redirect
# Similar to `` [backquotes]. If multiple arguments are given, the
# second and subsequent arguments are passed as parameters to command
# with no shell expansion.
require 'tmpdir'
require 'fileutils'
@@__system_to_string_count__ = 0
def system_to_string(*args)
begin
tmpf = File.join(Dir.tmpdir, "#{$$}-#{@@__system_to_string_count__}")
@@__system_to_string_count__ += 1
ret = nil
open(tmpf,"w") do |f|
IO.redirect(f) {
system(*args)
}
end
File.read(tmpf)
ensure
FileUtils.rm_f tmpf
end
end
#### EmacsLisp depend: system_to_string
module EmacsLisp
# Executes an EmacsLisp string by gnudoit.
def elisp(lisp)
system_to_string("gnudoit", lisp).chomp
end
# Converts a Ruby string to EmacsLisp string.
# [imported from el4r]
def dump_string(string)
dumped = string.dup
# \ -> \\
dumped.gsub! %r"\\" do '\\\\' end
# " -> \"
dumped.gsub! %r'"' do '\\"' end
# (zero byte) -> \0
dumped.gsub! %r'\0' do "\\\0" end
%Q'"#{dumped}"'
end
end
#### flib
class Object
# Same as File.read. But FILENAME is expanded.
def readf(filename)
File.read( File.expand_path(filename.to_s) )
end
# Write an object's string form. FILENAME is expanded.
def writef(filename)
open(File.expand_path(filename.to_s), "w"){|f| f.write(self.to_s)}
end
end
#### notify_exit
def notify_exit
# Notify when the program is exited.
at_exit do
bell_message "#$0 exited."
end
end
#### region
class String
# Scans a regexp once. Then cut matched part from string. Returns the matched part.
def kill_region!(regexp)
ret = ""
sub!(regexp) {
ret = $&
""
}
ret
end
end
#### ext
class String
# Returns a string which is replaced the filename's extension with NEWEXT.
def my_ext(newext=nil)
if newext
newext[0,1] != '.' and newext="."+newext
sub(/\.[^\.]+?$/, newext)
else
File.extname(self)
end
end
# Returns a string which is stripped the filename's extension.
def noext
sub(/\.[^\.]+$/,'')
end
end
#### StructWithType
class StructWithType < Struct
# TODO: document
def self.new(*args)
keys = []
types = []
args.each_with_index do |x,i|
if i%2 == 0
keys << x
else
types << x
end
end
unless keys.length > 0 &&
types.length > 0 &&
keys.length == types.length
raise ArgumentError, "#{self}: args.length must be even"
end
klass = super(*keys)
klass.instance_eval do
@@__type_dic__ = {}
@@__keys__ = keys
keys.each_with_index{|k,i| @@__type_dic__[k] = types[i]}
end
klass
end
def initialize(*args)
args.each_with_index do |x, i|
args[i] = __convert__(@@__keys__[i], x)
end
class << self
@@__keys__.each do |k|
define_method("#{k}="){|v| self[k]=v}
end
end
super(*args)
end
def __convert__(k,v)
__send__(@@__type_dic__[k.to_sym],v)
end
private :__convert__
def []=(k,v)
v = __convert__(k,v)
super(k,v)
end
end
#### ep
class String
# Expand tilde
def ep
case self
when /^~/
File.expand_path(self)
else
self
end
end
end
#### change_home
class File
def self.change_home(dir)
oldhome = ENV['HOME']
begin
ENV['HOME'] = dir
yield(dir)
ensure
ENV['HOME'] = oldhome
end
end
end
#### mapf
module Enumerable
#
# "map function"
# enum.mapf(:x)
# is short for
# enum.map { |elt| elt.x }
#
def mapf(message)
self.map { |elt| elt.send(message) }
end
end
#### build_hash
module Enumerable
#
# Like #map/#collect, but it generates a Hash. The block
# is expected to return two values: the key and the value for the new hash.
# numbers = (1..3)
# squares = numbers.build_hash { |n| [n, n*n] } # 1=>1, 2=>4, 3=>9
# sq_roots = numbers.build_hash { |n| [n*n, n] } # 1=>1, 4=>2, 9=>3
#
def build_hash
result = {}
self.each do |elt|
key, value = yield elt
result[key] = value
end
result
end
end
#### map_with_index
module Enumerable
#
# Same as Enumerable#map, but the index is yielded as well. See
# Enumerable#each_with_index.
# puts files.map_with_index { |fn, idx| "#{idx}. #{fn}" }
# print "Please select a file (0-#{files.size}): "
#
def map_with_index
result = []
self.each_with_index do |elt, idx|
result << yield(elt, idx)
end
result
end
end
#### bug!
class ScriptBug < Exception; end
# Raises ScriptBug exception.
def bug!( message = 'must not happen' )
raise ScriptBug, "\n[SCRIPT BUG] " + message
end
#### must
class Object
# Assert: type === obj
# ex. obj.must Fixnum, Float
def must( *args )
args.each {|c| return self if c === self }
raise TypeError, "wrong arg type '#{self.class}' for required #{args.join('/')}"
end
# Assert: obj.respond_to? meth
# ex. obj.must_have :read, :readlines
# ex. obj.needed :read, :readlines
def must_have( *args )
args.each do |m|
self.respond_to? m or
raise ArgumentError, "receiver #{inspect} does not have '#{m}'"
end
self
end
alias needed must_have
# Assert: self == obj
def must_be( obj )
self == obj or
raise ArgumentError, "expected #{obj.inspect} but is #{inspect}"
self
end
# Assert: self != nil
def must_exist
nil? and raise ArgumentError, 'receiver is wrongly nil'
end
end
#### Contents
class GenericContents
require 'forwardable'
extend Forwardable
methods = String.instance_methods(false) - %w[to_s to_str]
def_delegators(:@to_s, *methods)
attr :to_s
alias :to_str :to_s
end
# str = FileContents.new(filename)
class FileContents < GenericContents
def initialize(filename)
@to_s = File.read(filename)
end
end
# str = URIContents.new(uri)
class URIContents < GenericContents
def initialize(uri)
require 'open-uri'
@to_s = URI(uri).read
end
end
#### show_usage
# Prints the script's first comment block.
def show_usage(msg=nil)
name = caller[-1].sub(/:\d+$/, '')
$stderr.puts "\nError: #{msg}" if msg
$stderr.puts
File.open(name) do |f|
while line = f.readline and line.sub!(/^# ?/, '')
$stderr.puts line
end
end
exit 1
end
#### UnTable
# Strip table-related tags in HTML
class UnTable
# Strip table-related tags in SRC
def untable!(src)
src.gsub!(%r!?(table)\b[^>]*>!i,'')
# src.gsub!(%r!]*>!i,' ')
src.gsub!(%r!]*>!i,'')
src.gsub!(%r!]*>!i,'
')
src.gsub!(%r!
!i, '')
src
end
def untable(src)
untable!(src.dup)
end
end
#### system_safe
# mswin32 ruby's `system' workaround.
def system_safe(*x)
begin
system(*x)
rescue
end
end
#### unproc
class Object
def unproc(*x)
self
end
end
class Proc
def unproc(*x)
call(*x)
end
end
#### ConfigScript depend: set_attr, build_hash, unproc
require 'forwardable'
class ConfigScript
extend Forwardable
include Enumerable
def initialize(arg)
unless Hash === arg
eval(readf(arg.to_s))
arg = instance_variables.map{|iv|
[iv[1..-1], instance_variable_get(iv)]
}.build_hash{|kv| kv}
end
s_class = class << self; self end
arg.each do |k,v|
if Symbol === k
arg.delete k
k = k.to_s
arg[k]=v
end
s_class.class_eval do
define_method(k) {arg[k].unproc}
define_method("#{k}=") {|vv| arg[k]=vv}
end
end
@hash = arg
end
alias :[] :__send__
def_delegators :@hash, :keys, :each
def []=(k,v)
@hash[k.to_s]=v
end
def method_missing(name, *args, &block)
nil
end
end
#### dump
class Numeric
def dump() self end
end
#### __funcall
class Object
# Call a method even if it is private.
def __funcall(meth, *args, &block)
m = method(meth)
instance_eval { m.call(*args, &block) }
end
end
#### scriptdir
class Dir
def Dir.scriptdir
File.dirname(File.expand_path(caller(1)[0].scan(/^(.+?):\d+:/).to_s))
end
end
#### URLConv
module URLConv
def relative2absolute(html, baseurl)
# relativelink to absolute link
html.gsub!(/(href|src)=['"]?\s*(.*?)\s*?['"]?(>|\s)/mi) do |x|
begin
uri = URI.parse($2)
absolute_url = if uri.scheme.nil?
URI.join(baseurl, $2)
else
$2
end
"#{$1}=\"#{absolute_url}\"#{$3}"
rescue URI::InvalidURIError
next
end
end
html
end
end
#### END OF LIBRARY
# To add a new code (mylib-rb-add)
#### test
if __FILE__==$0
class MylibCommand
def initialize
@lines = File.readlines($0)
end
def run
meth = "do_#{ARGV[0]}"
if respond_to?(meth)
__send__ meth
else
do_list
end
end
def do_list
@lines.select{|line|
line =~ /^ *(class|module|def|attr|attr_reader|attr_writer|attr_accessor) |^#### /
}.display
end
def do_pieces
@lines.inject([]){|result, line|
if line =~ /^#### (.+?)/
result + ["#{$1}\n"]
else
result
end
}.display
end
alias :do_piece :do_pieces
end
MylibCommand.new.run
end
rttool-1.0.3.0/test/test.rb 0000644 0001750 0001750 00000002601 11765335411 015320 0 ustar uwabami uwabami #!/usr/bin/env ruby
require 'pathname'
require 'test/unit'
class TestRTtool < Test::Unit::TestCase
=begin eev
= How to make test files
(eecd2)
cd ..; rt2 -r rt/rt2html-lib examples/test1.rt > examples/test1.html
cd ..; rt2 -r rt/rt2html-lib examples/test2.rt > examples/test2.html
cd ..; rt2 -r rt/rt2html-lib examples/escape.rt > examples/escape.html
cd ..; rd2 --with-part=RT:rt examples/rttest.rd > examples/rttest.html
=end
def rt2html(name)
Dir.chdir(Pathname.new(__FILE__).dirname.parent) do
@html = "examples/#{name}.html"
@rt = "examples/#{name}.rt"
assert_equal File.read(@html), `ruby -Itest -Ilib bin/rt/rt2 -r rt/rt2html-lib #{@rt}`
end
end
def test__test1
# (find-filez "test1.rt test1.html" "../examples/")
rt2html "test1"
end
def test__test2
# (find-filez "test2.rt test2.html" "../examples/")
rt2html "test2"
end
def test__escape
# (find-filez "escape.rt escape.html" "../examples/")
rt2html "escape"
end
end
class TestRDRT2 < Test::Unit::TestCase
def rdrt2(name)
ENV['RUBYLIB'] = "../lib"
@html = "examples/#{name}.html"
@rd = "examples/#{name}.rd"
Dir.chdir(Pathname.new(__FILE__).dirname.parent) do
assert_equal File.read(@html), `ruby -Ilib bin/rt/rdrt2 #{@rd}`
end
end
def test_rttest
# (find-filez "rttest.rd rttest.html" "../examples/")
rdrt2 "rttest"
end
end
rttool-1.0.3.0/rttool.en.html 0000644 0001750 0001750 00000024354 11765335411 015660 0 ustar uwabami uwabami
RTtool
Index
- HTML XSS bug fix.
- RTtool works with Ruby 1.9 now.
- RTtool does not use .rd2rc anymore.
- Escape.
- English document.
- Removed Ruby-1.8 warning.
RT is a simple and human-readable table format.
RTtool is a converter from RT into various formats.
RT can be incorporated into RD.
At this time, RTtool can convert RT into HTML and plain text.
To convert into plain text, you need w3m.
Please execute the following commands.
ruby -ropen-uri -e 'URI("http://www.rubyist.net/~rubikitch/archive/rttool-1.0.3.tar.gz").read.display' > rttool-1.0.3.tar.gz
tar xzvf rttool-1.0.3.tar.gz
When you failed, please download it from the next link.
Then, install it.
cd rttool-1.0.3
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install
In ConfigBlock, these attributes can be set.
- caption
-
The caption of the table.
- delimiter
-
The delimiter of the table.
- rowspan
-
A string which stretches the left column. (defalut: ==
)
- colspan
-
A string which stretches the upper row. (default: ||
)
- escape
-
An escape character.
This attribute is disabled by default.
$ cat examples/easiest.rt
1, 2, 3
4, 5, 6
7, 8, 9
$ rt2 examples/easiest.rt
$B(#(!(((!(((!($(B
$B("(B 1$B("(B 2$B("(B 3$B("(B
$B('(!(+(!(+(!()(B
$B("(B 4$B("(B 5$B("(B 6$B("(B
$B('(!(+(!(+(!()(B
$B("(B 7$B("(B 8$B("(B 9$B("(B
$B(&(!(*(!(*(!(%(B
$ rt2 -r rt/rt2html-lib examples/easiest.rt
<!-- setup -->
<table border="1">
<!-- setup end -->
<!-- Header -->
<!-- Header end -->
<!-- Body -->
<tbody>
<tr><td align="right">1</td><td align="right">2</td><td align="right">3</td></tr>
<tr><td align="right">4</td><td align="right">5</td><td align="right">6</td></tr>
<tr><td align="right">7</td><td align="right">8</td><td align="right">9</td></tr>
</tbody>
<!-- Body end -->
<!-- teardown -->
</table>
<!-- teardown end -->
$ cat examples/escape.rt
delimiter = ;
escape = \
\z ; \;1 ; 2
$ rt2 examples/escape.rt
$B(#(!(((!(((!($(B
$B("(B\z$B("(B;1$B("(B 2$B("(B
$B(&(!(*(!(*(!(%(B
$ rt2 -r rt/rt2html-lib examples/escape.rt
<!-- setup -->
<table border="1">
<!-- setup end -->
<!-- Header -->
<!-- Header end -->
<!-- Body -->
<tbody>
<tr><td align="left">\z</td><td align="left">;1</td><td align="right">2</td></tr>
</tbody>
<!-- Body end -->
<!-- teardown -->
</table>
<!-- teardown end -->
$ cat examples/test1.rt
caption = Test Table
, Human, == , Dog , ==
|| , M , F ,M,F
x , 1.0 , 2.0, 1.1, 1.2
y , 0.4 , 0.5, 0.3, 0.1
$ rt2 examples/test1.rt
Test Table
$B(#(!(((!(!(!(!(!(((!(!(!(!(!($(B
$B("(B $B("(B Human $B("(B Dog $B("(B
$B("(B $B('(!(!(((!(!(+(!(!(((!(!()(B
$B("(B $B("(B M $B("(B F $B("(B M $B("(B F $B("(B
$B('(!(+(!(!(+(!(!(+(!(!(+(!(!()(B
$B("(Bx $B("(B 1.0$B("(B 2.0$B("(B 1.1$B("(B 1.2$B("(B
$B('(!(+(!(!(+(!(!(+(!(!(+(!(!()(B
$B("(By $B("(B 0.4$B("(B 0.5$B("(B 0.3$B("(B 0.1$B("(B
$B(&(!(*(!(!(*(!(!(*(!(!(*(!(!(%(B
$ rt2 -r rt/rt2html-lib examples/test1.rt
<!-- setup -->
<table border="1">
<caption>Test Table</caption>
<!-- setup end -->
<!-- Header -->
<thead>
<tr><th rowspan="2"></th><th colspan="2">Human</th><th colspan="2">Dog</th></tr>
<tr><th>M</th><th>F</th><th>M</th><th>F</th></tr>
</thead>
<!-- Header end -->
<!-- Body -->
<tbody>
<tr><td align="left">x</td><td align="right">1.0</td><td align="right">2.0</td><td align="right">1.1</td><td align="right">1.2</td></tr>
<tr><td align="left">y</td><td align="right">0.4</td><td align="right">0.5</td><td align="right">0.3</td><td align="right">0.1</td></tr>
</tbody>
<!-- Body end -->
<!-- teardown -->
</table>
<!-- teardown end -->
$ cat examples/rttest.rd
=begin
= Sample RD/RT
This RD contains a table.
It is so-called RD/RT.
=end
=begin RT
caption = Test Table
, Human, == , Dog , ==
|| , M , F ,M,F
x , 1.0 , 2.0, 1.1, 1.2
y , 0.4 , 0.5, 0.3, 0.1
=end
=begin
It is simple.
=end
$ rdrt2 examples/rttest.rd | w3m -dump -T text/html
= Sample RD/RT
This RD contains a table. It is so-called RD/RT.
Test Table
$B(#(!(((!(!(!(!(!(((!(!(!(!(!($(B
$B("(B $B("(B Human $B("(B Dog $B("(B
$B("(B $B('(!(!(((!(!(+(!(!(((!(!()(B
$B("(B $B("(B M $B("(B F $B("(B M $B("(B F $B("(B
$B('(!(+(!(!(+(!(!(+(!(!(+(!(!()(B
$B("(Bx $B("(B 1.0$B("(B 2.0$B("(B 1.1$B("(B 1.2$B("(B
$B('(!(+(!(!(+(!(!(+(!(!(+(!(!()(B
$B("(By $B("(B 0.4$B("(B 0.5$B("(B 0.3$B("(B 0.1$B("(B
$B(&(!(*(!(!(*(!(!(*(!(!(*(!(!(%(B
It is simple.
Ruby's
rttool-1.0.3.0/rttool.en.rd 0000644 0001750 0001750 00000013307 11765335411 015315 0 ustar uwabami uwabami =begin
= RTtool
##### [whats new]
== What's new
=== [2009/01/25] 1.0.3 released
* HTML XSS bug fix.
* RTtool works with Ruby 1.9 now.
=== [2006/09/20] 1.0.2 released
* Bugfix about linefeed.
=== [2005/10/28] 1.0.1 released
* RTtool does not use .rd2rc anymore.
=== [2005/10/26] 1.0.0 released
* Escape.
* English document.
* Removed Ruby-1.8 warning.
##### [/whats new]
##### [abstract]
== Abstract
RT is a simple and human-readable table format.
RTtool is a converter from RT into various formats.
RT can be incorporated into RD.
At this time, RTtool can convert RT into HTML and plain text.
To convert into plain text, you need (()).
##### [/abstract]
== Environment
##### [install]
== Install
Please execute the following commands.
ruby -ropen-uri -e 'URI("http://www.rubyist.net/~rubikitch/archive/rttool-1.0.3.tar.gz").read.display' > rttool-1.0.3.tar.gz
tar xzvf rttool-1.0.3.tar.gz
When you failed, please download it from the next link.
* (())
Then, install it.
cd rttool-1.0.3
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install
##### [/install]
== RT Syntax
* RT consists of three Blocks.
:ConfigBlock
ConfigBlock consist of groups of "attribute = value".
The following examples has (({caption})) attribute.
ConfigBlock can be omitted.
:HeaderBlock
A part of THEAD by HTML.
HeaderBlock sets a header of the table.
A header is located at the center.
HeaderBlock can be omitted.
:BodyBlock
A part of TBODY by HTML.
BodyBlock sets data of the table.
A number is located at the right and others are located at left.
* The default delimiter on HeaderBlock and BodyBlock is a comma or a Tab.
* It is not necessary to be always harmonious with an upper line.
* Arbitrary character can be a delimiter by changing (({delimiter})) attribute.
* (({==})) stretches the left column. (colspan)
* (({||})) stretches the upper row. (rowspan)
== Attributes
In ConfigBlock, these attributes can be set.
:caption
The caption of the table.
:delimiter
The delimiter of the table.
:rowspan
A string which stretches the left column. (defalut: (({==})))
:colspan
A string which stretches the upper row. (default: (({||})))
:escape
An escape character.
This attribute is disabled by default.
== Examples
=== The Easiest RT
$ cat examples/easiest.rt
1, 2, 3
4, 5, 6
7, 8, 9
$ rt2 examples/easiest.rt
┌─┬─┬─┐
│ 1│ 2│ 3│
├─┼─┼─┤
│ 4│ 5│ 6│
├─┼─┼─┤
│ 7│ 8│ 9│
└─┴─┴─┘
$ rt2 -r rt/rt2html-lib examples/easiest.rt
=== Use the Escape Attribute
$ cat examples/escape.rt
delimiter = ;
escape = \
\z ; \;1 ; 2
$ rt2 examples/escape.rt
┌─┬─┬─┐
│\z│;1│ 2│
└─┴─┴─┘
$ rt2 -r rt/rt2html-lib examples/escape.rt
=== More Complex RT
$ cat examples/test1.rt
caption = Test Table
, Human, == , Dog , ==
|| , M , F ,M,F
x , 1.0 , 2.0, 1.1, 1.2
y , 0.4 , 0.5, 0.3, 0.1
$ rt2 examples/test1.rt
Test Table
┌─┬─────┬─────┐
│ │ Human │ Dog │
│ ├──┬──┼──┬──┤
│ │ M │ F │ M │ F │
├─┼──┼──┼──┼──┤
│x │ 1.0│ 2.0│ 1.1│ 1.2│
├─┼──┼──┼──┼──┤
│y │ 0.4│ 0.5│ 0.3│ 0.1│
└─┴──┴──┴──┴──┘
$ rt2 -r rt/rt2html-lib examples/test1.rt
Test Table
| Human | Dog |
M | F | M | F |
x | 1.0 | 2.0 | 1.1 | 1.2 |
y | 0.4 | 0.5 | 0.3 | 0.1 |
=== RT Included by RD (RD/RT)
$ cat examples/rttest.rd
=begin
= Sample RD/RT
This RD contains a table.
It is so-called RD/RT.
=end
=begin RT
caption = Test Table
, Human, == , Dog , ==
|| , M , F ,M,F
x , 1.0 , 2.0, 1.1, 1.2
y , 0.4 , 0.5, 0.3, 0.1
=end
=begin
It is simple.
=end
$ rdrt2 examples/rttest.rd | w3m -dump -T text/html
= Sample RD/RT
This RD contains a table. It is so-called RD/RT.
Test Table
┌─┬─────┬─────┐
│ │ Human │ Dog │
│ ├──┬──┼──┬──┤
│ │ M │ F │ M │ F │
├─┼──┼──┼──┼──┤
│x │ 1.0│ 2.0│ 1.1│ 1.2│
├─┼──┼──┼──┼──┤
│y │ 0.4│ 0.5│ 0.3│ 0.1│
└─┴──┴──┴──┴──┘
It is simple.
== License
Ruby's
=end
rttool-1.0.3.0/bin/ 0000775 0001750 0001750 00000000000 11765335411 013610 5 ustar uwabami uwabami rttool-1.0.3.0/bin/rt/ 0000775 0001750 0001750 00000000000 11765335411 014235 5 ustar uwabami uwabami rttool-1.0.3.0/bin/rt/rdrt2 0000644 0001750 0001750 00000000121 11765335411 015205 0 ustar uwabami uwabami #!/usr/bin/env ruby
exec "rd2", "-r", "rd/rt-filter", "--with-part=RT:rt", *ARGV
rttool-1.0.3.0/bin/rt/rt2 0000644 0001750 0001750 00000006166 11765335411 014676 0 ustar uwabami uwabami #! /usr/bin/env ruby
=begin
= NAME
rt2 - converter from RT to other mark-up language.
$Id: rt2 1532 2009-01-24 16:04:36Z rubikitch $
= SYNOPSIS
rt2 [-r ] [options]
= DESCRIPTION
rt2 inputs from ((||)) and outputs in (({STDOUT})). you can
choose ((||)) to select output format. For example, use
"rt/rt2html-lib.rb" to turn it into HTML.
= OPTIONS
please check the output of
% rt2 --help
and
% rt2 -r rt/rt2html-lib.rb --help
= FILES
* ~/.rt2rc - User configuration file.
= SEE ALSO
ruby(1)
=end
require "kconv"
require "optparse"
require "rt/rtparser"
def Kconv.name2const(name)
case name
when "iso-2022-jp"
Kconv::JIS
when "euc-jp"
Kconv::EUC
when "shift_jis"
Kconv::SJIS
end
end
include RT
# global vars
$Visitor = nil
$RT2_Sub_OptionParser = nil
# local vars
include_path = []
with_part = []
output_file = nil
output_index = nil
out_code = nil
from_rto = nil
# user option
$DEFAULT_FORMAT_LIB = "rt/rt2txt-lib"
$RC = {}
# initialize OptionParser
ARGV.options = OptionParser.new("Usage: #{$0} [options] rt-file > output\n") do
|q|
q.version = "1.0.3"
q.on_head("global options:")
q.on("-rLIB", "--require=LIB",
String,
"choose format library.") do |i|
# require LIB
require i
if $Visitor_Class && !$Visitor
$Visitor = $Visitor_Class.new()
if $RT2_Sub_OptionParser
require $RT2_Sub_OptionParser
$RT2_Sub_OptionParser = nil
end
end
end
q.on("-oNAME",
String,
"indicate base name of output file") do |i|
output_file = i
end
q.on("--out-code=KCODE",
String,
"character encoding of output.(jis|euc|sjis)") do |i|
case i
when /sjis|shift-jis/i
out_code = "shift_jis"
when /jis|iso-2022-jp/i
out_code = "iso-2022-jp"
when /euc|euc-jp/i
out_code = "euc-jp"
end
end
q.on("-IPATH", "--include-path=PATH",
String,
"add PATH to list of include path") do |i|
# add to include path
include_path.unshift(i)
end
q.on_tail("--help",
"print this message") do
STDERR.print(q.to_s)
exit(0)
end
end # OptionParser.new
# require format lib implicitly
unless File.basename($0) == "rt2"
require "rt/" + File.basename($0) + "-lib.rb"
require $RT2_Sub_OptionParser if $RT2_Sub_OptionParser
# make visitor
$Visitor = $Visitor_Class.new()
end
begin
ARGV.parse!
rescue
STDERR.print("Error: " + $!.inspect + "\n")
STDERR.print(ARGV.options.to_s)
exit(1)
end
unless $Visitor_Class
require $DEFAULT_FORMAT_LIB
$Visitor = $Visitor_Class.new
end
# file base name setup
$Visitor.filename = output_file if output_file
# character encoding
if out_code
begin
$Visitor.charcode = out_code
rescue NameError
end
end
parsed = RTParser::parse(readlines.join)
# output
out = $Visitor.visit(parsed)
# character encoding convert
out = Kconv.kconv(out, Kconv.name2const(out_code), Kconv::AUTO) if out_code
if output_file
filename = output_file + "." + $Visitor.type::OUTPUT_SUFFIX
file = open(filename, "w")
file.print(out)
file.close
STDERR.print("#{$0}: output to #{filename}...\n")
else
print(out)
end
rttool-1.0.3.0/bin/rdrt2 0000644 0001750 0001750 00000000121 11765335411 014560 0 ustar uwabami uwabami #!/usr/bin/env ruby
exec "rd2", "-r", "rd/rt-filter", "--with-part=RT:rt", *ARGV
rttool-1.0.3.0/bin/rt2 0000644 0001750 0001750 00000006166 11765335411 014251 0 ustar uwabami uwabami #! /usr/bin/env ruby
=begin
= NAME
rt2 - converter from RT to other mark-up language.
$Id: rt2 1532 2009-01-24 16:04:36Z rubikitch $
= SYNOPSIS
rt2 [-r ] [options]
= DESCRIPTION
rt2 inputs from ((||)) and outputs in (({STDOUT})). you can
choose ((||)) to select output format. For example, use
"rt/rt2html-lib.rb" to turn it into HTML.
= OPTIONS
please check the output of
% rt2 --help
and
% rt2 -r rt/rt2html-lib.rb --help
= FILES
* ~/.rt2rc - User configuration file.
= SEE ALSO
ruby(1)
=end
require "kconv"
require "optparse"
require "rt/rtparser"
def Kconv.name2const(name)
case name
when "iso-2022-jp"
Kconv::JIS
when "euc-jp"
Kconv::EUC
when "shift_jis"
Kconv::SJIS
end
end
include RT
# global vars
$Visitor = nil
$RT2_Sub_OptionParser = nil
# local vars
include_path = []
with_part = []
output_file = nil
output_index = nil
out_code = nil
from_rto = nil
# user option
$DEFAULT_FORMAT_LIB = "rt/rt2txt-lib"
$RC = {}
# initialize OptionParser
ARGV.options = OptionParser.new("Usage: #{$0} [options] rt-file > output\n") do
|q|
q.version = "1.0.3"
q.on_head("global options:")
q.on("-rLIB", "--require=LIB",
String,
"choose format library.") do |i|
# require LIB
require i
if $Visitor_Class && !$Visitor
$Visitor = $Visitor_Class.new()
if $RT2_Sub_OptionParser
require $RT2_Sub_OptionParser
$RT2_Sub_OptionParser = nil
end
end
end
q.on("-oNAME",
String,
"indicate base name of output file") do |i|
output_file = i
end
q.on("--out-code=KCODE",
String,
"character encoding of output.(jis|euc|sjis)") do |i|
case i
when /sjis|shift-jis/i
out_code = "shift_jis"
when /jis|iso-2022-jp/i
out_code = "iso-2022-jp"
when /euc|euc-jp/i
out_code = "euc-jp"
end
end
q.on("-IPATH", "--include-path=PATH",
String,
"add PATH to list of include path") do |i|
# add to include path
include_path.unshift(i)
end
q.on_tail("--help",
"print this message") do
STDERR.print(q.to_s)
exit(0)
end
end # OptionParser.new
# require format lib implicitly
unless File.basename($0) == "rt2"
require "rt/" + File.basename($0) + "-lib.rb"
require $RT2_Sub_OptionParser if $RT2_Sub_OptionParser
# make visitor
$Visitor = $Visitor_Class.new()
end
begin
ARGV.parse!
rescue
STDERR.print("Error: " + $!.inspect + "\n")
STDERR.print(ARGV.options.to_s)
exit(1)
end
unless $Visitor_Class
require $DEFAULT_FORMAT_LIB
$Visitor = $Visitor_Class.new
end
# file base name setup
$Visitor.filename = output_file if output_file
# character encoding
if out_code
begin
$Visitor.charcode = out_code
rescue NameError
end
end
parsed = RTParser::parse(readlines.join)
# output
out = $Visitor.visit(parsed)
# character encoding convert
out = Kconv.kconv(out, Kconv.name2const(out_code), Kconv::AUTO) if out_code
if output_file
filename = output_file + "." + $Visitor.type::OUTPUT_SUFFIX
file = open(filename, "w")
file.print(out)
file.close
STDERR.print("#{$0}: output to #{filename}...\n")
else
print(out)
end
rttool-1.0.3.0/rttool.ja.rd 0000644 0001750 0001750 00000017213 11765335411 015305 0 ustar uwabami uwabami =begin
= RTtool
##### [whats new]
== 更新履歴
=== [2009/01/25] 1.0.3 released
* HTML出力時のクロスサイトスクリプティング脆弱性を修正。
* Ruby 1.9対応。
=== [2006/09/20] 1.0.2 released
* 改行コードがDOS, MACだとうまく動作しないバグを修正。
=== [2005/10/28] 1.0.1 released
* .rd2rcを使わなくなった。
=== [2005/10/26] 1.0.0 released
* エスケープできるようになった。英語のドキュメント付属。
* Ruby1.8のwarningを削除。
=== [2001/11/15] 0.1.7 released
* 符号つきの数字でも右揃えにするようにした。
=== [2001/08/07] 0.1.6 released
* 空白セルの処理でのバグを対処。
=== [2001/07/17] 0.1.5 released
* rt2html-lib.rb: captionが指定してないときはCAPTION要素をつけないように。
=== [2001/07/09] 0.1.4 released
* あおきさんのsetup.rbを使用。 それに伴い、パッケージ構成を変更。
=== [2001/06/03] 0.1.3 released
* rt2html-lib.rbにおいてタグを小文字に変更。これでXHTMLでも大丈夫。
##### [/whats new]
##### [abstract]
== 概要
RTtoolはシンプルな作表ツール。
RDの売りである((*可読性*))と((*さまざまなフォーマットに変換可能*))を継承し、
RDtoolの実験的機能ではあるがfilter機能によりRDと((*融合*))させることが可能である。
いってみれば((*兄弟みたいなものである。*))
今のところ、RTはHTMLとPlain text(要(()))へ変換できる。
w3mのWindows版はCygwinしかないので、Windowsの人はCygwinを使う必要がある。
HTMLへの変換のみ必要ならばw3mは不要である。
設計の方もRDtoolと似せている。
parserとvisitorに分け、rt2html-lib.rbを作成。
##### [/abstract]
##### [install]
== インストール
以下のコマンドを実行。
ruby -ropen-uri -e 'URI("http://www.rubyist.net/~rubikitch/archive/rttool-1.0.3.tar.gz").read.display' > rttool-1.0.3.tar.gz
tar xzvf rttool-1.0.3.tar.gz
失敗する場合は次のリンクからダウンロード。
* (())
それから次のコマンドでインストール。
cd rttool-1.0.3
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install
##### [/install]
(1)パッケージにある rt ディレクトリを $LOAD_PATH の通ったディレクトリにコピーする。
* (({require 'rt/rtparse'}))と使われるので。
(2)rt/rt2 コマンドを PATH の通ったディレクトリに移動する。
(3)rt/dot.rt.rd2rc
* もし ~/.rd2rc というファイルが存在しなければ、 ~/.rd2rc にリネーム。
* 存在するときは、差分を適宜設定する。
== RTの文法
* RTは3つのBlockで構成される
:ConfigBlock
「属性 = 値」の組からなる。
以下の例では caption 属性を設定し、表題をつけている。
このBlockは省略できる。
:HeaderBlock
HTMLでいうTHEADの部分。
表のヘッダを設定する。
ヘッダは中央揃えになる。
このBlockも省略できる。
:BodyBlock
HTMLでいうTBODYの部分。
データを記述する。
数字は右揃え、それ以外は左揃えになる。
* HeaderBlock, BodyBlock の項目の区切は ((',')) かTabである。
* 必ずしも上の行と揃っている必要はない。
ただ、揃えた方が見やすいとはいえる。
* 区切文字は delimiter 属性の値を変えることで任意の文字列にできる。
* (('=='))は左の列を伸ばす。
HTMLでいうTH、TD要素のcolspan属性に影響。
* rowspan 属性の値を変えることで任意の文字列にできる。
* (('||'))は上の行を伸ばす。
HTMLでいうTH、TD要素のrowspan属性に影響。
* colspan 属性の値を変えることで任意の文字にできる。
== 属性一覧
ConfigBlockでは次の属性が設定できる。
:caption
表のタイトルを設定する。
:delimiter
データの区切を指定する。
:rowspan
左の列を伸ばす指定。(デフォルトは(({==})))
:colspan
上の行を伸ばす設定。(デフォルトは(({||})))
:escape
delimiterをデータに含める必要があるときにこの属性で指定された文字を前置する。
デフォルトでは無効となっている。
== 例
=== 一番簡単なRT
値をカンマで区切るのが一番簡単なRT。
$ cat examples/easiest.rt
1, 2, 3
4, 5, 6
7, 8, 9
$ rt2 examples/easiest.rt
┌─┬─┬─┐
│ 1│ 2│ 3│
├─┼─┼─┤
│ 4│ 5│ 6│
├─┼─┼─┤
│ 7│ 8│ 9│
└─┴─┴─┘
$ rt2 -r rt/rt2html-lib examples/easiest.rt
=== エスケープ
RTはdelimiterを自由に指定できるが、delimiterを地の文に含める必要があるとき、
* delimiterを別なものに置換するか
* 1.0.0で導入されたエスケープを使う
エスケープは、delimiter文字の前に置くことで、delimiterではなくて地の文とみなされる。
$ cat examples/escape.rt
delimiter = ;
escape = \
\z ; \;1 ; 2
$ rt2 examples/escape.rt
┌─┬─┬─┐
│\z│;1│ 2│
└─┴─┴─┘
$ rt2 -r rt/rt2html-lib examples/escape.rt
=== ちょっと複雑なRT
$ cat examples/test1.rt
caption = Test Table
, Human, == , Dog , ==
|| , M , F ,M,F
x , 1.0 , 2.0, 1.1, 1.2
y , 0.4 , 0.5, 0.3, 0.1
$ rt2 examples/test1.rt
Test Table
┌─┬─────┬─────┐
│ │ Human │ Dog │
│ ├──┬──┼──┬──┤
│ │ M │ F │ M │ F │
├─┼──┼──┼──┼──┤
│x │ 1.0│ 2.0│ 1.1│ 1.2│
├─┼──┼──┼──┼──┤
│y │ 0.4│ 0.5│ 0.3│ 0.1│
└─┴──┴──┴──┴──┘
$ rt2 -r rt/rt2html-lib examples/test1.rt
Test Table
| Human | Dog |
M | F | M | F |
x | 1.0 | 2.0 | 1.1 | 1.2 |
y | 0.4 | 0.5 | 0.3 | 0.1 |
=== RDに埋め込む
さらに、RDに埋め込むこともできるのだ。
RTは((*RDではないのでRDのfilter機能を使う*))ことになる。
これで表つきのテキストを生成できる。
beginとendが煩雑なのはRDtoolの仕様なのでしょうがない。
コマンドラインが長くなるのでrdrt2というコマンドを用意。
$ cat examples/rttest.rd
=begin
= Sample RD/RT
This RD contains a table.
It is so-called RD/RT.
=end
=begin RT
caption = Test Table
, Human, == , Dog , ==
|| , M , F ,M,F
x , 1.0 , 2.0, 1.1, 1.2
y , 0.4 , 0.5, 0.3, 0.1
=end
=begin
It is simple.
=end
$ rdrt2 examples/rttest.rd | w3m -dump -T text/html
= Sample RD/RT
This RD contains a table. It is so-called RD/RT.
Test Table
┌─┬─────┬─────┐
│ │ Human │ Dog │
│ ├──┬──┼──┬──┤
│ │ M │ F │ M │ F │
├─┼──┼──┼──┼──┤
│x │ 1.0│ 2.0│ 1.1│ 1.2│
├─┼──┼──┼──┼──┤
│y │ 0.4│ 0.5│ 0.3│ 0.1│
└─┴──┴──┴──┴──┘
It is simple.
== なぜにRT
* HTMLやLaTeXの表の書き方がちょいイラつく。
* 読み書きしにくい。
* RDに表作成機能があればいいが、いろいろ弊害が。
* RDの文法が複雑になる。
* RDとして見辛くなる。
* RTの部分だけ独自に変更が可能。
* 俺がRDを愛してるから。
* 自分に合った表作成ツールがほしい。
== TODO
約9年、いろいろなことを考えていたが現在のシンプルな仕様のままがいいと判断した。
== ライセンス
Ruby'sとします。
=end
rttool-1.0.3.0/lib/ 0000775 0001750 0001750 00000000000 11765335411 013606 5 ustar uwabami uwabami rttool-1.0.3.0/lib/rd/ 0000775 0001750 0001750 00000000000 11765335411 014213 5 ustar uwabami uwabami rttool-1.0.3.0/lib/rd/rt-filter.rb 0000644 0001750 0001750 00000000434 11765335411 016447 0 ustar uwabami uwabami require 'tempfile'
$RC["filter"]["rt"] = Filter.new(:target) do |inn, out|
ext = $Visitor_Class.const_get('OUTPUT_SUFFIX')
if ext == 'txt'
ext = 'html'
end
tmpf = Tempfile.new("rt")
tmpf.write inn.read
tmpf.close
out.print `rt2 -r rt/rt2#{ext}-lib #{tmpf.path}`
end
rttool-1.0.3.0/lib/rt/ 0000775 0001750 0001750 00000000000 11765335411 014233 5 ustar uwabami uwabami rttool-1.0.3.0/lib/rt/rtparser.rb 0000644 0001750 0001750 00000012031 11765335411 016415 0 ustar uwabami uwabami #!/usr/bin/ruby
=begin
rtparser.rb
$Id: rtparser.rb 1370 2006-09-20 00:19:07Z rubikitch $
=end
module RT
class RTCell
def initialize(value, align = nil)
@rowspan = @colspan = 1
@value = value
@align = case align # {:left, :center :right}
when :left, :center, :right
align
when nil
if /^[+\-]?[0-9]+\.?[0-9]*/ === value
:right
else
:left
end
else
raise "[BUG]Illegal align type"
end
end
def == (x)
case x
when self.class
self.value == "" && x.value == "" || self.value == x.value && self.align == x.align
else
false
end
end
def inspect
if value==""
"()"
else
a = case align
when :left
"l"
when :center
"c"
when :right
"r"
else
raise "[BUG]Illegal align type"
end
"#{a}(#{value})"
end
end
attr_reader :value, :align
attr_accessor :rowspan, :colspan
end
class RTParser
DefaultConfig = {
'delimiter' => "[,\t]",
'rowspan' => "||",
'colspan' => "==",
'escape' => nil,
'caption' => nil,
}
def initialize(str="")
@str = str.dup
normalize_linefeed! @str
@config_line = []
@header_line = []
@body_line = []
@config = DefaultConfig.dup
@header = []
@body = []
end
attr_reader :str, :config, :header, :body
def normalize_linefeed!(str)
str.gsub!("\r\n", "\n")
str.gsub!("\r", "\n")
end
def self::parse(str)
obj = self::new str
obj.make_blocks
obj.parse_config
obj.parse_header
obj.parse_body
obj.calc_span(obj.header)
obj.calc_span(obj.body)
obj
end
def blocks
[@config_line, @header_line, @body_line]
end
def make_blocks(str = @str)
part = str.split(/\n\n/).collect{|x| x.split(/\n/)}
case part.length
when 0
when 1
@body_line, = part
when 2
@config_line, @body_line = part
when 3
@config_line, @header_line, @body_line = part
else
raise "RT: blocks are too many."
end
self
end
def parse_config(lines = @config_line)
lines.each do |line|
case line
when /^#/ # comment
when /^\s*(\S+)\s*=\s*(.+)$/
@config[$1] = $2
else
raise "RT: syntax error in config block"
end
end
self
end
def split2(str,re)
ret = str.split(re, -1)
end
private :split2
ESCAPE_TMP = "\001\002"
def _escape!(str)
esc = config['escape']
str.gsub!(/#{Regexp.quote(esc)}#{config['delimiter']}/, ESCAPE_TMP) if esc
end
private :_escape!
def _unescape!(str)
str.gsub!(/#{ESCAPE_TMP}/, config['delimiter'])
end
private :_unescape!
def parse_table_data(lines) # iterator
ret = []
lines.each do |line|
case line
when /^#/ # comment
else
_escape! line
ret << split2(line, /\s*#{config['delimiter']}\s*/).collect {|x|
_unescape! x
yield(x.strip)
}
end
end
unless ret.find_all{|x| x.length == ret[0].length} == ret
raise "RT: different column size"
end
ret
end
private :parse_table_data
def _make_cell(x, align)
case x
when config['rowspan'], config['colspan']
x
else
RTCell::new(x, align)
end
end
private :_make_cell
def parse_header(lines = @header_line)
@header = parse_table_data(lines) {|x|
_make_cell x, :center
}
self
end
def parse_body(lines = @body_line)
@body = parse_table_data(lines) {|x|
_make_cell x, nil
}
self
end
def calc_span(tbl)
return if tbl.empty?
cols = tbl[0].length
tbl.each do |row|
row.each_with_index do |elm, j|
case elm
when String
when RTCell
nspan = 1
1.upto(cols-j-1) do |k|
break unless row[j+k] == config['colspan']
nspan += 1
end
row[j].colspan = nspan
else
raise "[BUG] invalid cell"
end
end
end
rows = tbl.length
0.upto(cols-1) do |j|
0.upto(rows-1) do |i|
case tbl[i][j]
when String
when RTCell
nspan = 1
1.upto(rows-i-1) do |k|
break unless tbl[i+k][j] == config['rowspan']
nspan += 1
end
tbl[i][j].rowspan = nspan
else
raise "[BUG] invalid cell"
end
end
end
end
end # class RTCell, RTParser
end # module RT
rttool-1.0.3.0/lib/rt/rt2html-lib.rb 0000644 0001750 0001750 00000004041 11765335411 016715 0 ustar uwabami uwabami #!/usr/bin/ruby
=begin
rt2html-lib.rb
$Id: rt2html-lib.rb 1531 2009-01-21 17:21:23Z rubikitch $
=end
require 'rt/rtvisitor'
require 'cgi'
module RT
class RT2HTMLVisitor < RTVisitor
OUTPUT_SUFFIX = "html"
INCLUDE_SUFFIX = ["html"]
def initialize() super end
def block(name)
%Q[\n] +
yield +
%Q[\n\n]
end
private :block
def esc(str) CGI.escapeHTML(str) end
private :esc
def setup
block('setup') do
s = %Q[\n]
s << %Q[#{esc(caption)}\n] if caption
s
end
end
def teardown
block('teardown') do
%Q[
\n]
end
end
def cell_element(cell, name)
rs, cs = cell.rowspan, cell.colspan
if rs == 1 and cs == 1
ret = "<#{name}>"
elsif rs == 1
ret = %Q[<#{name} colspan="#{cs}">]
elsif cs == 1
ret = %Q[<#{name} rowspan="#{rs}">]
else
ret = %Q[<#{name} colspan="#{cs}" rowspan="#{rs}">]
end
ret
end
private :cell_element
def visit_Header(ary = @header)
block('Header') do
if ary.empty?
""
else
ret = "\n"
ary.each do |line|
ret << ''
each_cell(line) do |cell|
ret << cell_element(cell, 'th')
ret << esc(cell.value)
ret << ''
end
ret << "
\n"
end
ret << "\n"
end
end
end
def visit_Body(ary = @body)
block('Body') do
ret = "\n"
ary.each do |line|
ret << ''
each_cell(line) do |cell|
ret << cell_element(cell, %Q[td align="#{cell.align.id2name}"])
ret << esc(cell.value)
ret << ''
end
ret << "
\n"
end
ret << "\n"
end
end
end # RT2HTMLVisitor
end
$Visitor_Class = RT::RT2HTMLVisitor
rttool-1.0.3.0/lib/rt/w3m.rb 0000644 0001750 0001750 00000001602 11765335411 015263 0 ustar uwabami uwabami #!/usr/bin/ruby
=begin
w3m.rb
$Id: w3m.rb 597 2005-10-18 21:03:12Z rubikitch $
--- W3M.w3m(url, options='-e')
invoke w3m.
--- W3M.html2txt(htmlstr, options='-e')
convert htmlstr to plain text.
--- W3M.source(url, options='-e')
get the source.
=end
module W3M
module_function
def external_filter (str, prog)
require 'open3'
pipe = Open3.popen3(prog)
pipe[0] .print str
pipe[0] .close
pipe[1] .read
end
private_class_method :external_filter
def w3m(url, option='-e')
open("| w3m -dump #{option} #{url}").readlines.join
end
def html2txt(htmlstr, option='-e')
external_filter(htmlstr, "w3m -dump -T text/html #{option}")
end
def source(url, option='')
open("| w3m -dump_source #{option} #{url}").readlines.join
end
end
if __FILE__ == $0
s = W3M::source('http://www.ruby-lang.org')
#print W3M::html2txt s
end
rttool-1.0.3.0/lib/rt/rtvisitor.rb 0000644 0001750 0001750 00000001672 11765335411 016631 0 ustar uwabami uwabami #!/usr/bin/ruby
=begin
rtvisitor.rb
$Id: rtvisitor.rb 1531 2009-01-21 17:21:23Z rubikitch $
=end
require 'rt/rtparser'
module RT
class RTVisitor
def each_cell(ary)
ary.each do |x|
if x.class == RT::RTCell
yield x
end
end
end
private :each_cell
def initialize
end
attr_reader :rt, :header, :body, :caption
attr_accessor :filename, :charcode
def self.visit(parsed)
self::new.visit(parsed)
end
def visit(parsed)
@filename = @charset = nil
@rt = parsed
@header = @rt.header
@body = @rt.body
@caption = @rt.config['caption']
setup + visit_Caption + visit_Header + visit_Body + teardown
end
def setup
""
end
def teardown
""
end
def visit_Caption
""
end
def visit_Header
""
end
def visit_Body
""
end
end
end
rttool-1.0.3.0/lib/rt/rt2txt-lib.rb 0000644 0001750 0001750 00000000470 11765335411 016572 0 ustar uwabami uwabami #!/usr/bin/ruby
require 'rt/w3m'
require 'rt/rt2html-lib'
module RT
class RT2TXTVisitor < RT2HTMLVisitor
OUTPUT_SUFFIX = "txt"
INCLUDE_SUFFIX = ["txt"]
def visit(parsed)
W3M::html2txt(super)
end
end # RT2TXTVisitor
end
$Visitor_Class = RT::RT2TXTVisitor
rttool-1.0.3.0/ChangeLog 0000644 0001750 0001750 00000003216 11765335411 014612 0 ustar uwabami uwabami 2005-10-27 23:00 rubikitch
* examples/rttest.html: rdtool-0.6.18
2005-10-27 22:58 rubikitch
* Rakefile, rttool-rctool, bin/rt/rdrt2, lib/PATHCONV, setup/rt.rb:
Removed .rd2rc(RCtool) dependency.
2005-10-26 06:17 rubikitch
* lib/rt/rtparser.rb: Listed all the attributes of ConfigBlock.
2005-10-26 06:02 rubikitch
* setup/rt.rb: use RCtool
2005-10-23 09:57 rubikitch
* examples/escape.html, examples/escape.rt, test/test.rb: supported
escape
2005-10-22 17:38 rubikitch
* lib/rt/rtparser.rb, test/test-rtparser.rb: supported escape
2005-10-22 17:05 rubikitch
* lib/rt/rt2html-lib.rb, lib/rt/rtparser.rb, test/test-rtparser.rb:
refactored
2005-10-19 15:27 rubikitch
* setup.rb: ruby 1.8 warning fixed. ignore CVS directory.
2005-10-19 06:25 rubikitch
* examples/: test1.html, test1.rt, test2.html, test2.rt: Japanese
-> English
2005-10-19 06:25 rubikitch
* lib/rt/rt2html-lib.rb: removed test code
2005-10-16 22:40 rubikitch
* GPL, README.ja, dot.rt.rd2rc, rt.html, rt.rd, setup.rb,
bin/PATHCONV, bin/rt/rdrt2, bin/rt/rt2, examples/rttest.rd,
examples/test1.rt, examples/test2.rt, lib/PATHCONV,
lib/rt/rt2html-lib.rb, lib/rt/rt2txt-lib.rb, lib/rt/rtparser.rb,
lib/rt/rtvisitor.rb, lib/rt/w3m.rb, setup/rt.rb,
test/test-rtparser.rb: Initial revision
2005-10-16 22:40 rubikitch
* GPL, README.ja, dot.rt.rd2rc, rt.html, rt.rd, setup.rb,
bin/PATHCONV, bin/rt/rdrt2, bin/rt/rt2, examples/rttest.rd,
examples/test1.rt, examples/test2.rt, lib/PATHCONV,
lib/rt/rt2html-lib.rb, lib/rt/rt2txt-lib.rb, lib/rt/rtparser.rb,
lib/rt/rtvisitor.rb, lib/rt/w3m.rb, setup/rt.rb,
test/test-rtparser.rb: rttool