Changeset 683 for lang/ruby/chm
- Timestamp:
- 10/24/07 20:55:49 (6 years ago)
- Files:
-
- 1 modified
-
lang/ruby/chm/lib/chm.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/chm/lib/chm.rb
r676 r683 4 4 5 5 require "chmlib" 6 require "strscan" 6 7 require "nkf" 7 8 … … 14 15 15 16 def initialize(filename) 17 @filename = filename 16 18 @h = Chmlib.chm_open(filename) 17 19 raise ChmError, "Not exists?" unless @h … … 27 29 end 28 30 31 def home 32 if File.basename(@filename, ".chm") == File.basename(@home) 33 @home = self.topics.flatten.find {|i| i[:local] }[:local] 34 else 35 @home 36 end 37 end 38 39 def unescape!(n) 40 n.gsub!(/</, "<") 41 n.gsub!(/>/, ">") 42 n.gsub!(/"/, "\"") 43 n.gsub!(/&/, "&") 44 n 45 end 46 47 # keyword index 29 48 def index 30 49 return nil unless @index 31 50 return @index_cache if @index_cache 32 51 33 text = retrieve_object(@index)52 text = NKF.nkf("-w", retrieve_object(@index)) 34 53 #<OBJECT type="text/sitemap"> 35 54 #<param name="Name" value="pushd(path = nil, &block) (c/m Shell) (ruby-src:doc/shell.rd)"> … … 45 64 next unless n 46 65 next if n.empty? or n.match(/^\s+$/) 47 n.gsub!(/</, "<") 48 n.gsub!(/>/, ">") 49 n.gsub!(/"/, "\"") 50 n.gsub!(/&/, "&") 51 n = NKF.nkf("-w", n) 66 unescape!(n) 52 67 (index[n] ||= []) << local 53 68 end 54 69 end 55 70 @index_cache = index.to_a 71 end 72 73 # table of contents 74 def topics 75 return nil unless @topics 76 return @topics_cache if @topics_cache 77 78 text = NKF.nkf("-w", retrieve_object(@topics)) 79 result = [] 80 81 s = StringScanner.new(text) 82 s.skip(/.*?<UL>\s*/m) 83 84 current = result 85 level = [] 86 while s.scan(/<(LI|UL|\/UL)>\s*/) 87 case s[1] 88 when "LI" 89 s.skip(%r{<OBJECT type="text/sitemap">\s*}) 90 s.scan(%r{<param name="Name" value="([^"]+)">\s*(<param name="Local" value="([^"]+)">)?\s*}) 91 current << { 92 :name => unescape!(s[1]), 93 :local => s[3] || "", 94 :children => [] 95 } 96 s.skip(%r{.*?</OBJECT>\s*}) 97 when "UL" 98 level << current 99 current = current.last[:children] 100 when "/UL" 101 current = level.pop 102 end 103 end 104 105 106 # result = [ 107 # {name:"name",local:"",child:[]}, 108 # ], 109 # 110 @topics_cache = result 56 111 end 57 112 … … 179 234 180 235 if $0 == __FILE__ 181 chm = Chmlib::Chm.new("/Users/cho45/htmlhelp/rubymanjp.chm")182 236 require "pp" 183 chm.index #cache 184 puts "ok" 185 pp chm.index.select {|k,v| /split/i === k } 237 #chm = Chmlib::Chm.new("/Users/cho45/htmlhelp/rubymanjp.chm") 238 # chm.index #cache 239 # puts "ok" 240 # pp chm.index.select {|k,v| /split/i === k } 241 chm = Chmlib::Chm.new("/Users/cho45/htmlhelp/kr2doc.chm") 242 pp chm.home 243 #pp chm.topics 186 244 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)