#--------------------------------------------------------------------- # Copyright (C) GFD Dennou Club, 2005. All rights reserved. #--------------------------------------------------------------------- #= Generate HTML from RD # # * Yasuhiro MORIKAWA, Masaki ISHIWATARI # * 2005/11/06 (Yasuhiro MORIKAWA) Default CSS is modified to local site # * 2005/11/06 (Yasuhiro MORIKAWA) URL of reference of rdtool is updated # * 2005/10/12 (Yasuhiro MORIKAWA) JAPart and ENPart is modified # * 2005/10/12 (Yasuhiro MORIKAWA) FOOTEREN is modified # * 2005/10/10 (Yasuhiro MORIKAWA) default FOOTERs are modified # * 2005/08/14 (Yasuhiro MORIKAWA) Link to rd-hindex.rb page is added # * 2005/08/10 (Yasuhiro MORIKAWA) Ruby and RD Path checker is added # * 2005/08/10 (Yasuhiro MORIKAWA) RD Header Index inserter is added # * 2005/08/10 (Yasuhiro MORIKAWA) Date perser is response to multi-language # * 2005/08/10 (Yasuhiro MORIKAWA) Date perser is addded # * 2005/07/07 (Yasuhiro MORIKAWA) "SUBDIRS" is deleted # * 2005/07/07 (Yasuhiro MORIKAWA) "chmod" and "chgrp" are added # * 2005/06/23 (Yasuhiro MORIKAWA) Suffix of JA file is change from "htm.ja" to "htm" # * 2005/06/23 (Yasuhiro MORIKAWA) Japanese commends are added # * 2005/06/12 (Yasuhiro MORIKAWA) Create # ###################################################################### # #== Settings # # [JAPANESE] 各種設定項目 INCLUDEFILE = include $(INCLUDEFILE) # Include file (optional) # [JA] インクルードファイル (任意) JA = 1 # 1: Create "htm", 0: Not Create (selective) EN = 0 # 1: Create "htm.en", 0: Not Create (selective) # [JA] 1 ならば作成, 0 ならば作成しない (選択必須) RDHINDEX = 2 # Index of Headers (selective) # 0:None, 1-3:Header Level # Note: CSS item is "ol.rd2html_hindex ul [ul ..]" # # [JA] ヘッダの目次 (選択必須) # 0:作成しない, 1-3:ヘッダレベルに対応 # 備考: CSS 設定は "ol.rd2html_hindex ul [ul ..]" で FOOTERJA = "
\ Last Updated: $(UpdateDateJA), Since: $(CreateDateJA) " # [JA] JA 用 HTML フッター (任意) # $(UpdateDateJA) は電脳 RD 書式で書かれた最上部の日時 # (JA part 部分内) # $(CreateDateJA) は電脳 RD 書式で書かれた最下部の日時 # (JA part 部分内) FOOTEREN = "
\ Last Updated: $(UpdateDateEN), Since: $(CreateDateEN) " # HTML Footer (optional) # $(UpdateDateEN) is date in Dennou RD on top (EN part) # $(CreateDateEN) is date in Dennou RD at bottom (EN part) CSS = ../cvs.css # Cascade Style Sheet (necessary) # [JA] カスケードスタイルシート (必須) CHMOD = 664 # Set mode (optional) # [JA] chmod する値 (任意) CHGRP = # Set group (optional) # [JA] chgrp する値 (任意) RUBY = ruby1.8 # Path to Ruby (necessary) # [JA] Ruby へのパス (必須) RD = rd2 # Path to rdtool (necessary) # [JA] rdtool へのパス (必須) RUBYLIB = # Set "RUBYLIB" (optional) # [JA] "RUBYLIB" の設定 (任意) RDOPTS = # Additional rd2 options (optional) # [JA] rd2 コマンドへのオプション (任意) OUTCODE = euc # character encoding of output [jis|euc|sjis] (necessary) # [JA] rd 出力時の文字コード [jis|euc|sjis] (必須) JACODE = EUC-JP # indicate CHARSET as charset [char encoding] (necessary) # [JA] rd2 コマンドの CHARSET (必須) # End Settings [JA] 設定項目ここまで ###################################################################### #== Commands # General command RD2HTM = rd2 -r rd/rd2html-lib --with-css=$(CSS) --with-part=HTML:html \ --out-code=$(OUTCODE) $(RDOPTS) # For Japanese RD2JA = $(RD2HTM) --html-charset=$(JACODE) --with-part=JA:rd # For English RD2EN = $(RD2HTM) --html-charset=US-ASCII --with-part=EN:rd ###################################################################### #== Ruby liner script for replacing title in HTML # # [JA] 引数 (1 つのみ) にとった HTML ファイルの一番上の

の内容を # 読み取り, その内容を タグに代入する. # H1ToTitle = $(RUBY) -e 'body = open(ARGV[0]){|io| io.read}; \ if /\<h1.*?\>(.*?)\<\/h1.*?\>/ =~ body then ;\ h1 = $$1 ;\ h1 = h1.chomp.gsub!(/\<.*?\>/){|s| s = ""} ;\ mod = body.gsub(/\<title\>.*<\/title\>/, \ "\<title\>" + h1 + "<\/title\>") ;\ else ;\ mod = body ;\ end ;\ out = open(ARGV[0], "w"); out.puts(mod) ;\ out.close' ###################################################################### #== Ruby liner script for getting JA part # # [JA] 引数 (複数可) または引数が無い場合標準入力から得られた文字列 # のうち, =begin, =end でくくられた部分と =begin JA, =end JA # でくくられた部分を標準出力に出力する. # JAPart = $(RUBY) -e 'inbody = false ;\ puts "=begin" ;\ lines = readlines ;\ lines.each {|line| ;\ inbody = true if /^=begin\s*$$/ =~ line ;\ inbody = true if /^=begin\s+JA\s*$$/ =~ line ;\ inbody = false if /^=end\s*$$/ =~ line ;\ inbody = false if /^=end\s+JA\s*$$/ =~ line ;\ next if line =~ /^=(begin|end)\s*$$/ ;\ next if line =~ /^=(begin\s+|end\s+)\w+\s*$$/ ;\ if inbody ;\ puts line ;\ end ;\ } ;\ puts "=end"' ###################################################################### #== Ruby liner script for getting EN part # # [JA] 引数 (複数可) または引数が無い場合標準入力から得られた文字列 # のうち, =begin, =end でくくられた部分と =begin EN, =end EN # でくくられた部分を標準出力に出力する. # ENPart = $(RUBY) -e 'inbody = false ;\ puts "=begin" ;\ lines = readlines ;\ lines.each {|line| ;\ inbody = true if /^=begin\s*$$/ =~ line ;\ inbody = true if /^=begin\s+EN\s*$$/ =~ line ;\ inbody = false if /^=end\s*$$/ =~ line ;\ inbody = false if /^=end\s+EN\s*$$/ =~ line ;\ next if line =~ /^=(begin|end)\s*$$/ ;\ next if line =~ /^=(begin\s+|end\s+)\w+\s*$$/ ;\ if inbody ;\ puts line ;\ end ;\ } ;\ puts "=end"' ###################################################################### #== Ruby liner script for getting creation date in Dennou RD format # # [JA] 引数 (複数可) または引数が無い場合標準入力から得られた文字列 # のうち, "* 2005/08/10 (氏名) ..." のように記述される一連の # 文字列から一番下の日付を標準出力に出力する. # CDateParser = $(RUBY) -e 'lines = readlines ;\ start = false ;\ date = "" ;\ lines.each{ |line| ;\ if /^\s*\#*\s*\*\s+(\d{2,4}[\/\-]\d{1,2}[\/\-]\d{1,2})\s+\(.+\)/ =~ line then ;\ start = true ;\ date = $$1 ;\ else ;\ if start then ;\ $$stdout.print date ;\ exit ;\ end ;\ end ;\ } ;\ $$stdout.print "unknown" ;\ exit' CreateDateJA = `$(JAPart) $< | $(CDateParser)` CreateDateEN = `$(ENPart) $< | $(CDateParser)` ###################################################################### #== Ruby liner script for getting update date in Dennou RD format # # [JA] 引数 (複数可) または引数が無い場合標準入力から得られた文字列 # のうち, "* 2005/08/10 (氏名) ..." のように記述される一連の # 文字列から一番上の日付を標準出力に出力する. UDateParser = $(RUBY) -e 'lines = readlines ;\ lines.each{ |line| ;\ if /^\s*\#*\s*\*\s+(\d{2,4}[\/\-]\d{1,2}[\/\-]\d{1,2})\s+\(.+\)/ =~ line then ;\ $$stdout.print $$1 ;\ exit ;\ end ;\ } ;\ $$stdout.print "unknown" ;\ exit' UpdateDateJA = `$(JAPart) $< | $(UDateParser)` UpdateDateEN = `$(ENPart) $< | $(UDateParser)` ###################################################################### #== Ruby liner script for getting RD Header index # # Reference: http://www.rubyist.net/~rubikitch/computer/rd-hindex/ # # [JA] 標準入力内から目次を取得し, 1 つ目の引数をファイル名として # 受け取り, そのファイル内の == より前に目次を組み込む, 標準 # 出力に出力する. # 2 つ目の引数は目次として取り込むヘッダのレベルの指定 1 〜 3 までが # 有効で, 0 や文字列などが代入された場合, 目次は組み込まれない. # 3 つ目の引数は part の指定で, もしも本文が JA part 内にある場合は # JA などと指定する. # なお, 目次の ol には =begin HTML <ol class="rd2html_hindex"> # =end HTMLというタグが入る. # # 参考: http://www.rubyist.net/~rubikitch/computer/rd-hindex/ # RDHindexParser = $(RUBY) -e \ 'rdlevel = ARGV[1].to_i ;\ rdhindex = "=begin HTML\n<hr></hr>\n<ol class=\"rd2html_hindex\">\n=end HTML\n" ;\ rdhindex << "=begin\n" ;\ while line = $$stdin.gets ;\ next if line =~ /^=(begin|end)$$/ ;\ if line =~ /^(=+)\s*(.+)$$/ ;\ level = $$1.length ; content = $$2 ;\ next if level == 1 || level > rdlevel + 1 ;\ rdhindex << " " * (level - 2) + "* ((<\"\#{content}\">))\n" ;\ end ;\ end ;\ rdhindex << "=end\n" ;\ rdhindex << "=begin HTML\n</ol>\n<hr></hr>\n=end HTML\n" ;\ rdhindex = "" if rdlevel == 0 ;\ ;\ body = open(ARGV[0]){|io| io.read} ;\ lines = body.split(/\n/) ;\ finished = false ; inbody = false ;\ results = "" ; rdbegin = "" ; rdend = "" ;\ lines.each{ |line| ;\ if line =~ /^=begin$$/ ;\ rdbegin = "=begin" ; rdend = "=end" ;\ elsif line =~ /^=begin\s+(.*)/ ;\ rdbegin = "=begin " + $$1 ; rdend = "=end " + $$1 ;\ end ;\ if line =~ /^=end$$/ || line =~ /^=end\s+(.*)/ ;\ rdbegin = "" ; rdend = "" ;\ end ;\ inbody = true if line =~ /^=begin$$/ || line =~ /^=begin\s+\#{ARGV[2]}$$/ ;\ inbody = false if line =~ /^=end(\s+\w+)*$$/ ;\ if /^==\s+/ =~ line && !(finished) && inbody then ;\ results << rdend + "\n" + rdhindex + "\n" + rdbegin + "\n" ;\ results << line + "\n" ;\ finished = true ;\ else ;\ results << line + "\n" ;\ end ;\ } ;\ puts results' ###################################################################### #== Search "rd" files __AllRDFiles__ = $(wildcard *.rd) RDFiles = $(__AllRDFiles__:%.v.rd=) GenerateFiles = $(HtmByJA) $(HtmByEN) HtmByJA = $(RDFiles:.rd=.htm) HtmByEN = $(RDFiles:.rd=.htm.en) ########################################################################## #== Rules # all: pathcheck $(GenerateFiles) help: @echo "" @echo " This Makefile needs following programs." @echo "" @echo " Ruby <URL:http://www.ruby-lang.org>" @echo " rdtool <URL:http://raa.ruby-lang.org/project/rdtool/>" @echo "" @echo "" @echo " make [all] :" @echo " Create HTML files from RD " @echo "" %.htm: %.rd @if [ $(JA) != "0" ] ; then \ echo -n "Insert RD Header Index Level:$(RDHINDEX) Part:JA .." ;\ $(JAPart) $< | $(RDHindexParser) $< "$(RDHINDEX)" JA > $<.rdhindex.tmp ;\ echo ' done' ;\ echo "$(RD2JA) $< > $@ || rm -f $@" ;\ $(RD2JA) $<.rdhindex.tmp > $@ || rm -f $@ ;\ rm -f $<.rdhindex.tmp ;\ if [ -f $@ ]; then \ echo -n 'Copy <h1> to <title> ..' ; $(H1ToTitle) $@ ; echo 'done' ;\ if [ ! X$(FOOTERJA) = X"" ] ; then \ echo -n 'Add footer ..' ;\ echo $(FOOTERJA) >> $@ ;\ echo ' done' ;\ fi ;\ fi ;\ if [ ! X$(CHMOD) = X"" ]; then \ echo -n chmod $(CHMOD) $@ .. ; chmod $(CHMOD) $@ ; echo ' done' ;\ fi ;\ if [ ! X$(CHGRP) = X"" ]; then \ echo -n chgrp $(CHGRP) $@ .. ; chgrp $(CHGRP) $@ ; echo ' done' ;\ fi ;\ fi %.htm.en: %.rd @if [ $(EN) != "0" ] ; then \ echo -n "Insert RD Header Index Level:$(RDHINDEX) Part:EN .." ;\ $(ENPart) $< | $(RDHindexParser) $< "$(RDHINDEX)" EN > $<.rdhindex.tmp ;\ echo ' done' ;\ echo "$(RD2EN) $< > $@ || rm -f $@" ;\ $(RD2EN) $<.rdhindex.tmp > $@ || rm -f $@ ;\ rm -f $<.rdhindex.tmp ;\ if [ -f $@ ]; then \ echo -n 'Copy <h1> to <title> ..' ; $(H1ToTitle) $@ ; echo ' done' ;\ if [ ! X$(FOOTEREN) = X"" ] ; then \ echo -n 'Add footer ..' ;\ echo $(FOOTEREN) >> $@ ;\ echo ' done' ;\ fi ;\ fi ;\ if [ ! X$(CHMOD) = X"" ]; then \ echo -n chmod $(CHMOD) $@ .. ; chmod $(CHMOD) $@ ; echo ' done' ;\ fi ;\ if [ ! X$(CHGRP) = X"" ]; then \ echo -n chgrp $(CHGRP) $@ .. ; chgrp $(CHGRP) $@ ; echo ' done' ;\ fi ;\ fi clean: -rm *~ *.bak clean.all: clean -rm $(GenerateFiles) pathcheck: @echo -n "Ruby path check .. " @if ! which $(RUBY) > /dev/null 2>&1 ; then \ echo "" ;\ echo " Error: RUBY=\"$(RUBY)\" is invalid path." ;\ echo "" ;\ echo " Please install Ruby (see http://www.ruby-lang.org), " ;\ echo " or set valid path." ;\ echo "" ;\ exit 1 ;\ fi @echo " done" @echo -n "RD path check .. " @if ! which $(RD) > /dev/null 2>&1 ; then \ echo "" ;\ echo " Error: RD=\"$(RD)\" is invalid path." ;\ echo "" ;\ echo " Please install RDtool (see http://raa.ruby-lang.org/project/rdtool/), " ;\ echo " or set valid path." ;\ echo "" ;\ exit 1 ;\ fi @echo " done" ###################################################################### #== Mode setting for Emacs #Local Variables: #mode: makefile #End: #