rttool-1.0.3.0/0000775000175000017500000000000011765335411013040 5ustar uwabamiuwabamirttool-1.0.3.0/examples/0000775000175000017500000000000011765335411014656 5ustar uwabamiuwabamirttool-1.0.3.0/examples/escape.html0000644000175000017500000000042111765335411016777 0ustar uwabamiuwabami
\z;12
rttool-1.0.3.0/examples/rttest.html0000644000175000017500000000206511765335411017072 0ustar uwabamiuwabami examples/rttest.rd

Sample RD/RT

This RD contains a table. It is so-called RD/RT.

Test Table
HumanDog
MFMF
x1.02.01.11.2
y0.40.50.30.1

It is simple.

rttool-1.0.3.0/examples/test2.rt0000644000175000017500000000012711765335411016264 0ustar uwabamiuwabamicaption = 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 rttool-1.0.3.0/examples/escape.rt0000644000175000017500000000005111765335411016457 0ustar uwabamiuwabamidelimiter = ; escape = \ \z ; \;1 ; 2 rttool-1.0.3.0/examples/test1.rt0000644000175000017500000000017311765335411016264 0ustar uwabamiuwabamicaption = 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 rttool-1.0.3.0/examples/easiest.html0000644000175000017500000000066511765335411017206 0ustar uwabamiuwabami
123
456
789
rttool-1.0.3.0/examples/test1.html0000644000175000017500000000120311765335411016576 0ustar uwabamiuwabami
Test Table
HumanDog
MFMF
x1.02.01.11.2
y0.40.50.30.1
rttool-1.0.3.0/examples/rttest.rd0000644000175000017500000000036311765335411016532 0ustar uwabamiuwabami=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 rttool-1.0.3.0/examples/test2.html0000644000175000017500000000120311765335411016577 0ustar uwabamiuwabami
Test Table
HumanDog
MFMF
x1.02.01.11.2
y0.40.50.30.1
rttool-1.0.3.0/examples/easiest.rt0000644000175000017500000000003011765335411016651 0ustar uwabamiuwabami1, 2, 3 4, 5, 6 7, 8, 9 rttool-1.0.3.0/metadata.yml0000664000175000017500000000277611765335411015357 0ustar uwabamiuwabami--- !ruby/object:Gem::Specification name: rttool version: !ruby/object:Gem::Version version: 1.0.3.0 platform: ruby authors: - rubikitch - Kazuhiro NISHIYAMA autorequire: bindir: bin cert_chain: [] date: 2009-01-28 00:00:00 +09:00 default_executable: dependencies: [] description: email: zn@mbf.nifty.com executables: - rdrt2 - rt2 extensions: [] extra_rdoc_files: [] files: - ChangeLog - GPL - bin/rdrt2 - bin/rt/rdrt2 - bin/rt/rt2 - bin/rt2 - examples/easiest.html - examples/easiest.rt - examples/escape.html - examples/escape.rt - examples/rttest.html - examples/rttest.rd - examples/test1.html - examples/test1.rt - examples/test2.html - examples/test2.rt - lib/rd/rt-filter.rb - lib/rt/rt2html-lib.rb - lib/rt/rt2txt-lib.rb - lib/rt/rtparser.rb - lib/rt/rtvisitor.rb - lib/rt/w3m.rb - rttool.en.html - rttool.en.rd - rttool.ja.html - rttool.ja.rd - test/rttool-sub.rb - test/test-rt2html-lib.rb - test/test-rtparser.rb - test/test.rb has_rdoc: false homepage: http://raa.ruby-lang.org/project/rttool/ post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: "0" version: required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: "0" version: requirements: [] rubyforge_project: rwiki rubygems_version: 1.0.1 signing_key: specification_version: 2 summary: Simple table generator test_files: [] rttool-1.0.3.0/GPL0000644000175000017500000004311011765335411013402 0ustar uwabamiuwabami GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 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.html0000644000175000017500000003466011765335411015651 0ustar uwabamiuwabami RTtool

Index


Title: RTtool

1 $B99?7MzNr(B

1.1 [2009/01/25] 1.0.3 released

  • HTML$B=PNO;~$N%/%m%9%5%$%H%9%/%j%W%F%#%s%0@H
  • Ruby 1.9$BBP1~!#(B

1.2 [2006/09/20] 1.0.2 released

  • $B2~9T%3!<%I$,(BDOS, MAC$B$@$H$&$^$/F0:n$7$J$$%P%0$r=$@5!#(B

1.3 [2005/10/28] 1.0.1 released

  • .rd2rc$B$r;H$o$J$/$J$C$?!#(B

1.4 [2005/10/26] 1.0.0 released

  • $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

1.5 [2001/11/15] 0.1.7 released

  • $BId9f$D$-$N?t;z$G$b1&B7$($K$9$k$h$&$K$7$?!#(B

1.6 [2001/08/07] 0.1.6 released

  • $B6uGr%;%k$N=hM}$G$N%P%0$rBP=h!#(B

1.7 [2001/07/17] 0.1.5 released

  • rt2html-lib.rb: caption$B$,;XDj$7$F$J$$$H$-$O(BCAPTION$BMWAG$r$D$1$J$$$h$&$K!#(B

1.8 [2001/07/09] 0.1.4 released

  • $B$"$*$-$5$s$N(Bsetup.rb$B$r;HMQ!#(B $B$=$l$KH<$$!"%Q%C%1!<%89=@.$rJQ99!#(B

1.9 [2001/06/03] 0.1.3 released

  • rt2html-lib.rb$B$K$*$$$F%?%0$r>.J8;z$KJQ99!#$3$l$G(BXHTML$B$G$bBg>fIW!#(B

2 $B35MW(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

3 $B%$%s%9%H!<%k(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
  1. $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
  2. rt/rt2 $B%3%^%s%I$r(B PATH $B$NDL$C$?%G%#%l%/%H%j$K0\F0$9$k!#(B
  3. 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

4 RT$B$NJ8K!(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

5 $BB0@-0lMw(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

6 $BNc(B

6.1 $B0lHV4JC1$J(BRT

$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 -->

6.2 $B%(%9%1!<%W(B

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 -->

6.3 $B$A$g$C$HJ#;($J(BRT

$ 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 -->

6.4 RD$B$KKd$a9~$`(B

$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.

7 $B$J$<$K(BRT

  • HTML$B$d(BLaTeX$B$NI=$N=q$-J}$,$A$g$$%$%i$D$/!#(B

    • $BFI$_=q$-$7$K$/$$!#(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

8 TODO

$BLs(B9$BG/!"$$$m$$$m$J$3$H$r9M$($F$$$?$,8=:_$N%7%s%W%k$J;EMM$N$^$^$,$$$$$HH=CG$7$?!#(B

9 $B%i%$%;%s%9(B

Ruby's$B$H$7$^$9!#(B

rttool-1.0.3.0/test/0000775000175000017500000000000011765335411014017 5ustar uwabamiuwabamirttool-1.0.3.0/test/test-rt2html-lib.rb0000644000175000017500000000504211765335411017460 0ustar uwabamiuwabamirequire '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[\n] assert_equal(lines, uncomment(@x.setup)) end def test_teardown assert_equal(%Q[
Test Table
\n], uncomment(@x.teardown)) end def test_visit_Header lines = %Q[\n] + %Q[HumanDog\n] + %Q[MFMF\n] + %Q[\n] assert_equal(lines, uncomment(@x.visit_Header)) end def test_visit_Body lines = %Q[\n] + %Q[x1.02.01.11.2\n] + %Q[y0.40.50.30.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[\n] assert_equal(lines, uncomment(@x.setup)) end def test_visit_Header lines = %Q[\n] + %Q[\n] + %Q[\n] assert_equal(lines, uncomment(@x.visit_Header)) end def test_visit_Body lines = %Q[\n] + %Q[\n] + %Q[\n] assert_equal(lines, uncomment(@x.visit_Body)) end end rttool-1.0.3.0/test/test-rtparser.rb0000644000175000017500000001246711765335411017173 0ustar uwabamiuwabami#!/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.rb0000644000175000017500000004745211765335411016470 0ustar uwabamiuwabami# 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!]*>!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.rb0000644000175000017500000000260111765335411015320 0ustar uwabamiuwabami#!/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.html0000644000175000017500000002435411765335411015660 0ustar uwabamiuwabami RTtool

Index


Title: RTtool

1 What's new

1.1 [2009/01/25] 1.0.3 released

  • HTML XSS bug fix.
  • RTtool works with Ruby 1.9 now.

1.2 [2006/09/20] 1.0.2 released

  • Bugfix about linefeed.

1.3 [2005/10/28] 1.0.1 released

  • RTtool does not use .rd2rc anymore.

1.4 [2005/10/26] 1.0.0 released

  • Escape.
  • English document.
  • Removed Ruby-1.8 warning.

2 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 w3m.

3 Environment

4 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

5 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)

6 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.

7 Examples

7.1 The Easiest RT

$ 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 -->

7.2 Use the Escape Attribute

$ 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 -->

7.3 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
$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 -->

7.4 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
$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.

8 License

Ruby's

rttool-1.0.3.0/rttool.en.rd0000644000175000017500000001330711765335411015315 0ustar uwabamiuwabami=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
<b>XSS Test</b>
<b>Test</b>
<b>1.0</b><b>a</b>
123
456
789
=== 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
\z;12
=== 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
HumanDog
MFMF
x1.02.01.11.2
y0.40.50.30.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/0000775000175000017500000000000011765335411013610 5ustar uwabamiuwabamirttool-1.0.3.0/bin/rt/0000775000175000017500000000000011765335411014235 5ustar uwabamiuwabamirttool-1.0.3.0/bin/rt/rdrt20000644000175000017500000000012111765335411015205 0ustar uwabamiuwabami#!/usr/bin/env ruby exec "rd2", "-r", "rd/rt-filter", "--with-part=RT:rt", *ARGV rttool-1.0.3.0/bin/rt/rt20000644000175000017500000000616611765335411014676 0ustar uwabamiuwabami#! /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/rdrt20000644000175000017500000000012111765335411014560 0ustar uwabamiuwabami#!/usr/bin/env ruby exec "rd2", "-r", "rd/rt-filter", "--with-part=RT:rt", *ARGV rttool-1.0.3.0/bin/rt20000644000175000017500000000616611765335411014251 0ustar uwabamiuwabami#! /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.rd0000644000175000017500000001721311765335411015305 0ustar uwabamiuwabami=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
123
456
789
=== エスケープ 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
\z;12
=== ちょっと複雑な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
HumanDog
MFMF
x1.02.01.11.2
y0.40.50.30.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/0000775000175000017500000000000011765335411013606 5ustar uwabamiuwabamirttool-1.0.3.0/lib/rd/0000775000175000017500000000000011765335411014213 5ustar uwabamiuwabamirttool-1.0.3.0/lib/rd/rt-filter.rb0000644000175000017500000000043411765335411016447 0ustar uwabamiuwabamirequire '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/0000775000175000017500000000000011765335411014233 5ustar uwabamiuwabamirttool-1.0.3.0/lib/rt/rtparser.rb0000644000175000017500000001203111765335411016415 0ustar uwabamiuwabami#!/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.rb0000644000175000017500000000404111765335411016715 0ustar uwabamiuwabami#!/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[\n] if caption s end end def teardown block('teardown') do %Q[
#{esc(caption)}
\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.rb0000644000175000017500000000160211765335411015263 0ustar uwabamiuwabami#!/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.rb0000644000175000017500000000167211765335411016631 0ustar uwabamiuwabami#!/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.rb0000644000175000017500000000047011765335411016572 0ustar uwabamiuwabami#!/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/ChangeLog0000644000175000017500000000321611765335411014612 0ustar uwabamiuwabami2005-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