require "lib/rwd/ruby" require "lib/rwd/xml" require "lib/rwd/net" require "lib/rwd/browser" require "lib/rwd/thread" require "md5" require "rbconfig" begin require "win32ole" require "win32/registry" rescue LoadError $".push "win32ole.so" $".push "win32/registry.rb" end $rwd_exit = ARGV.include?("--rwd-exit") # Hack ??? $rwd_exit = true if defined?(REQUIRE2LIB) $rwd_debug = ($rwd_debug or $DEBUG or false) $rwd_border = ($rwd_border or 0) $rwd_dir = Dir.pwd $rwd_files = File.expand_path("rwd_files", Dir.pwd) $rwd_html = {} ARGV.delete_if do |arg| arg =~ /^--rwd-/ end RWDEmptyline = "..." #module RWD rcfile = nil s = ENV["HOME"] ; s = File.expand_path(".rwdrc", s) unless s.nil? ; rcfile = s if (not s.nil? and rcfile.nil? and File.file?(s)) s = ENV["USERPROFILE"] ; s = File.expand_path("rwd.cfg", s) unless s.nil? ; rcfile = s if (not s.nil? and rcfile.nil? and File.file?(s)) s = ENV["windir"] ; s = File.expand_path("rwd.cfg", s) unless s.nil? ; rcfile = s if (not s.nil? and rcfile.nil? and File.file?(s)) AL = "align='left'" AC = "align='center'" AR = "align='right'" VA = "valign='middle'" Format = "\n\t" unless rcfile.nil? puts "Reading #{rcfile} ..." Hash.file(rcfile).each do |k, v| ENV[k] = v unless ENV.include?(k) end end if ENV["RWDTHEME"] if ENV["RWDTHEME"] = "PDA" load 'lib/rwdthemes/default.rwd' end if ENV["RWDTHEME"] = "DEFAULT" $rwdtinkerlog.info "rwd: loading theme DEFAULT" load 'lib/rwdthemes/default.rwd' end if ENV["RWDTHEME"] = "WINDOWSLOOKALIKE" load 'lib/rwdthemes/windowslike.rwd' end else load 'lib/rwdthemes/default.rwd' end ENV["RWDBROWSER"] = (ENV["RWDBROWSER"] or defaultbrowser) or puts "No browser found." ENV["RWDPORTS"] = (ENV["RWDPORTS"] or "7701-7709") ENV["RWDTHEME"] = (ENV["RWDTHEME"] or "DEFAULT") #trap("INT") {puts "Terminating..." ; exit} $SAFE = 0 class IE def initialize(url) @ie = WIN32OLE.new("InternetExplorer.Application") @ev = WIN32OLE_EVENT.new(@ie, "DWebBrowserEvents2") @ie.navigate(url) @ie.menubar = false @ie.toolbar = false @ie.addressbar = false @ie.statusbar = false @ie.visible = true at_exit do @ie.visible = false end @ev.on_event("OnQuit") do Thread.main.exit end Thread.new do loop do WIN32OLE_EVENT.message_loop end end end end class Array def rwd_options(emptyline=nil) if emptyline.nil? a = self else a = [emptyline].concat(self) end a.numsort.collect{|s| "" }.join("\n") end def rwd_method(method) res = "" self.each do |s| s = s.join("/") if s.kind_of?(Array) s2 = s.dup s2[0..0] = s2[0..0].upcase res = res + "

#{s2.to_html}

" end return res end def rwd_row(key=nil, value=nil, bold=false) res = "" res = res + "" res = res + "" unless key.nil? res = res + self.collect{|s| "

#{"" if bold}#{s.to_s.to_html}#{"" if bold}

"}.join("") res = res + "
" return res end def rwd_table(headers=nil, highlightrows=[]) res = "" highlightrows = [highlightrows].flatten n = -1 res = res + "" res = res + headers.rwd_row(nil, nil, true) unless headers.nil? res = res + self.collect{|a| a.rwd_row(nil, nil, highlightrows.include?(n+=1))}.join("") res = res + "
" return res end def rwd_headers(emptyfield=false) res = "" res = res + "" res = res + "

" if emptyfield res = res + self.collect{|s| "

#{s.to_html}

" }.join("") res = res + "
" return res end def rwd_form(prefix, values=[], twoparts=0, options={}) res = [] res << "" self.each_index do |n| name = "#{prefix.to_html}#{self[n].downcase.to_html}" res << "" res << "

" res << "#{self[n].to_html}:" res << "

" if options.keys.include?(self[n]) res << "" else s = "" s << "" res << s end res << "
" if twoparts > 0 and n == twoparts-1 res << "" end end res << "
" return res.join("\n") end end class Hash def rwd_table(field=nil, joinwith=nil, headers=nil) res = [] res << "" res << headers.rwd_headers((not field.nil?)) if not headers.nil? self.keys.numsort.each do |key| key2 = key value2 = self[key] key2 = key2.join(joinwith) if key2.kind_of?(Array) value2 = [value2] if value2.kind_of?(String) res << value2.rwd_row(field, key2) end res << "
" res.join("\n") end end class EVTable def rwd_table(field=nil, joinwith=@sep) super(field, joinwith, @headers) end def rwd_form(prefix="", key=nil, twoparts=false) values = self[key] if not key.nil? values = [] if values.nil? options = {} if File.file?(oldlocation("constraints.tsv")) table = File.basename(@file).gsub(/\.tsv$/, "") TSVFile.new(oldlocation("constraints.tsv")).subset(["Table", "Constraint"], [table, "key"], ["Column", "Value"]).values.each do |column, table2| options[column] = TSVFile.new(oldlocation("#{table2}.tsv")).keys.collect{|a| a.join("\t")} end end @headers.rwd_form(prefix, values, twoparts ? @key : 0, options) end def rwd_metadata res = [] res << "" res << "" res << " " res << " " res << "" @headers.each_index do |n| res << "" res << " " res << " " res << "" end res << "
" return res.join("\n") end end class OpenTag def prechildren(res, before, after, varshtml, varsstring, switches, help, oneormorefields, firstaction, tabs, tab, pda=false) bef = before[-1] res << Format % ["Before", @subtype] if ($rwd_debug and not bef.nil?) res << bef if not bef.nil? res << Format % ["Pre", @subtype] if $rwd_debug align = AC align = "align='#{@args["align"]}'" if @args.include?("align") valign = VA valign = "valign='#{@args["valign"]}'" if @args.include?("valign") value1 = "" value1 = varshtml[@args["name"]] if varshtml.include?(@args["name"]) value1 = @args["value"] if @args.include?("value") value2 = "" value2 = varsstring[@args["name"]] if varsstring.include?(@args["name"]) value2 = @args["value"] if @args.include?("value") cellspacing = 3 cellspacing = 0 if pda case @subtype when "application" when "window", "helpwindow" args = @args.deep_dup args["nohelpbutton"] = (not help) template = $rwd_html_1 # template = $rwd_html_PDA_1 if pda res << (template(template, args)) when "p" then res << "

" when "pre" then res << "

"
    when "big"		then res << "

" when "small" then res << "

" when "list" then res << "