root/lang/ruby/Chemr/CHMBundle.rb

Revision 852, 0.9 kB (checked in by cho45, 13 months ago)

lang/ruby/Chemr/CHMBundle.rb,
lang/ruby/Chemr/AppController.rb,
lang/ruby/Chemr/CHMDocument.rb,
lang/ruby/Chemr/Chemr.xcodeproj/cho45.mode1,
lang/ruby/Chemr/Chemr.xcodeproj/project.pbxproj,
lang/ruby/Chemr/Chemr.xcodeproj/cho45.pbxuser:

設定ファイルをよむように

Line 
1
2require "yaml"
3
4class CHMBundle
5        attr_reader :path
6
7        def initialize(path)
8                @path   = path
9                @bundle = NSBundle.bundleWithPath(path.realpath.to_s)
10                @info   = @bundle.infoDictionary
11                @home   = @info[:CHMHome].to_s
12                @title  = @info[:CHMTitle].to_s
13                if @info[:CHMKeyword]
14                        @index = YAML.load(retrieve_object(@info[:CHMKeyword]))
15                end
16                if @info[:CHMTOC]
17                        @topics = YAML.load(retrieve_object(@info[:CHMTOC]))
18                end
19        rescue => e
20                OSX.NSRunAlertPanel("Error", e.inspect, "OK", "", nil)
21        end
22
23        def index
24                @index
25        end
26
27        def home
28                @home
29        end
30
31        def title
32                @title
33        end
34
35        def topics
36                @topics
37        end
38
39        def searchable?
40                false
41        end
42
43        def search(text)
44                nil
45        end
46
47        def retrieve_object(path)
48                log path
49#               p bundle
50#               p bundle.resourcePath
51#               p bundle.infoDictionary
52
53                log @bundle.resourcePath + path
54                begin
55                        File.read(@bundle.resourcePath + path)
56                rescue Errno::ENOENT
57                        raise Chmlib::Chm::RetrieveError
58                end
59        end
60end
61
Note: See TracBrowser for help on using the browser.