Class: BitClust::Subcommands::ChmCommand

Inherits:
BitClust::Subcommand show all
Defined in:
lib/bitclust/subcommands/chm_command.rb

Defined Under Namespace

Classes: Sitemap, URLMapperEx

Constant Summary collapse

HHP_SKEL =
<<EOS
[OPTIONS]
Compatibility=1.1 or later
Compiled file=refm.chm
Contents file=refm.hhc
Default Window=titlewindow
Default topic=doc/index.html
Display compile progress=No
Error log file=refm.log
Full-text search=Yes
Index file=refm.hhk
Language=0x411 日本語 (日本)
Title=Rubyリファレンスマニュアル

[WINDOWS]
titlewindow="Rubyリファレンスマニュアル","refm.hhc","refm.hhk","doc/index.html","doc/index.html",,,,,0x21420,,0x387e,,,,,,,,0

[FILES]
<%= @html_files.join("\n") %>
EOS
HHC_SKEL =
<<EOS
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
</HEAD>
<BODY>
<UL><% [:library].each do |k| %>
<%= @sitemap[k].to_html %>
<% end %></UL>
</BODY>
</HTML>
EOS
HHK_SKEL =
<<EOS
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
</HEAD>
<BODY>
<UL><% @index_contents.sort.each do |content| %>
<%= content.to_html %>
<% end %></UL>
</BODY>
</HTML>
EOS

Instance Method Summary collapse

Methods inherited from BitClust::Subcommand

#error, #help, #option_error, #parse, #srcdir_root

Constructor Details

#initializeChmCommand

Returns a new instance of ChmCommand.


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/bitclust/subcommands/chm_command.rb', line 143

def initialize
  super
  @sitemap = {
    :library => Sitemap.new('ライブラリ', 'library/index.html'),
  }
  @sitemap[:library] << Sitemap::Content.new('標準ライブラリ', 'library/_builtin.html')
  @sitemap[:library] << Sitemap::Content.new('添付ライブラリ')
  @stdlibs = {}
  @index_contents = []
  @parser.banner = "Usage: #{File.basename($0, '.*')} chm [options]"
  @parser.on('-o', '--outputdir=PATH', 'Output directory') do |path|
    begin
      @outputdir = Pathname.new(path).realpath
    rescue Errno::ENOENT
      FileUtils.mkdir_p(path, :verbose => true)
      retry
    end
  end
end

Instance Method Details

#exec(argv, options) ⇒ Object


163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/bitclust/subcommands/chm_command.rb', line 163

def exec(argv, options)
  create_manager_config
  prefix = options[:prefix]
  db = MethodDatabase.new(prefix.to_s)
  manager = ScreenManager.new(@manager_config)
  @html_files = []
  db.transaction do
    methods = {}
    db.methods.each do |entry|
      method_name = entry.klass.name + entry.typemark + entry.name
      (methods[method_name] ||= []) << entry
    end

    entries = db.docs + db.libraries.sort + db.classes.sort + methods.values.sort
    pb = ProgressBar.new('entry', entries.size)
    entries.each do |c|
      filename = create_html_file(c, manager, @outputdir, db)
      @html_files << filename
      e = c.is_a?(Array) ? c.sort.first : c
      case e.type_id
      when :library
        content = Sitemap::Content.new(e.name.to_s, filename)
        if e.name.to_s != '_builtin'
          @sitemap[:library][1] << content
          @stdlibs[e.name.to_s] = content
        end
        @index_contents << Sitemap::Content.new(e.name.to_s, filename)
      when :class
        content = Sitemap::Content.new(e.name.to_s, filename)
        if e.library.name.to_s == '_builtin'
          @sitemap[:library][0] << content
        else
          @stdlibs[e.library.name.to_s] << content
        end
        @index_contents << Sitemap::Content.new("#{e.name} (#{e.library.name})", filename)
      when :method
        e.names.each do |e_name|
          name = e.typename == :special_variable ? "$#{e_name}" : e_name
          @index_contents <<
            Sitemap::Content.new("#{name} (#{e.library.name} - #{e.klass.name})", filename)
          @index_contents <<
            Sitemap::Content.new("#{e.klass.name}#{e.typemark}#{name} (#{e.library.name})", filename)
        end
      end
      pb.title.replace(e.name)
      pb.inc
    end
    pb.finish
  end
  @html_files.sort!
  create_file(@outputdir + 'refm.hhp', HHP_SKEL, true)
  create_file(@outputdir + 'refm.hhc', HHC_SKEL, true)
  create_file(@outputdir + 'refm.hhk', HHK_SKEL, true)
  create_file(@outputdir + 'library/index.html', manager.library_index_screen(db.libraries.sort, {:database => db}).body)
  create_file(@outputdir + 'class/index.html', manager.class_index_screen(db.classes.sort, {:database => db}).body)
  FileUtils.cp(@manager_config[:themedir] + @manager_config[:css_url],
               @outputdir.to_s, {:verbose => true, :preserve => true})
end