root/lang/ruby/gem_chm/lib/gem_chm/bundle.rb @ 2431

Revision 2431, 1.8 kB (checked in by moro, 5 years ago)

lang/ruby/gem_chm: first import. "chm bundle" generator for Chemr.

Line 
1require 'erb'
2require 'yaml'
3
4module GemChm
5=begin
6Contents
7  +-- PkgInfo
8  +-- Info.plist
9  +-- Resources/
10        +-- keyword.yaml
11        +-- toc.yaml
12        +-- rdoc/
13=end
14
15  class Bundle
16    PKG_INFO_CONTENTS = 'BNDL????'
17    class << self
18      def pkg_info
19        PKG_INFO_CONTENTS
20      end
21    end
22
23    def initialize(name, home="/index.html")
24      @name, @home = name, home
25    end
26
27    def info_plist
28      INFO_PLIST_TEMPLATE.result(binding)
29    end
30
31    def generate(gem_rdoc)
32      root = @name + ".chm"
33      Dir.mkdir(root)
34      Dir.chdir(root) do
35        Dir.mkdir("Contents")
36        Dir.chdir("Contents") do
37          File.open("PkgInfo","w"){|f| f << self.class.pkg_info }
38          File.open("Info.plist","w"){|f| f << self.info_plist }
39          Dir.mkdir("Resources")
40          Dir.chdir("Resources") do
41            File.open("keyword.yaml","w"){|f| f << gem_rdoc.keywords.to_yaml }
42            File.open("toc.yaml","w"){|f| f << gem_rdoc.toc.to_yaml }
43            gem_rdoc.store_docs(Dir.pwd)
44          end
45        end
46      end
47    end
48  end
49
50  INFO_PLIST_TEMPLATE = ERB.new(<<-TEMPLATE)
51<?xml version="1.0" encoding="UTF-8"?>
52<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
53<plist version="1.0">
54<dict>
55    <key>CFBundleName</key>
56    <string></string>
57    <key>CFBundleInfoDictionaryVersion</key>
58    <string>6.0</string>
59    <key>CFBundlePackageType</key>
60    <string>BNDL</string>
61    <key>CFBundleSignature</key>
62    <string>????</string>
63
64    <key>CHMTitle</key>
65    <string><%= @name %></string>
66    <key>CHMHome</key>
67    <string><%= @home %></string>
68    <key>CHMKeyword</key>
69    <string>/keyword.yaml</string>
70    <key>CHMTOC</key>
71    <string>/toc.yaml</string>
72</dict>
73</plist>
74  TEMPLATE
75end
76
Note: See TracBrowser for help on using the browser.