require "pathname" require "yaml" def mkchmbundle(bundle_name, title, home="/index.html", keywords=[], toc={}) root = Pathname.new(bundle_name) root.rmtree rescue nil root.mkpath contents = root + "Contents" contents.mkpath (contents + "PkgInfo").open("w") {|f| f << "BNDL????" } (contents + "Info.plist").open("w") {|f| f << <<-InfoPlist.gsub(/^\t{2}/, "") } CFBundleName CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType BNDL CFBundleSignature ???? CHMTitle #{title} CHMHome #{home} CHMKeyword /keyword.yaml CHMTOC /toc.yaml InfoPlist resources = contents + "Resources" resources.mkpath (resources + "keyword.yaml").open("w") {|f| f << keywords.to_yaml } (resources + "toc.yaml").open("w") {|f| f << toc.to_yaml } [root, resources] end if $0 == __FILE__ mkchmbundle("Test.chm", "Test", "/index.html", ["hoge", ["aaaa.html"]], {}) end