Class: BitClust::Subcommands::StatichtmlCommand

Inherits:
BitClust::Subcommand show all
Includes:
NameUtils
Defined in:
lib/bitclust/subcommands/statichtml_command.rb

Defined Under Namespace

Classes: URLMapperEx

Constant Summary

Constants included from NameUtils

NameUtils::CHAR_TO_MARK, NameUtils::CHAR_TO_NAME, NameUtils::CLASS_NAME_RE, NameUtils::CLASS_PATH_RE, NameUtils::CONST_PATH_RE, NameUtils::CONST_RE, NameUtils::GVAR_RE, NameUtils::LIBNAME_RE, NameUtils::MARK_TO_CHAR, NameUtils::MARK_TO_NAME, NameUtils::METHOD_NAME_RE, NameUtils::METHOD_SPEC_RE, NameUtils::MID, NameUtils::NAME_TO_CHAR, NameUtils::NAME_TO_MARK, NameUtils::TYPEMARK_RE

Instance Method Summary collapse

Methods included from NameUtils

build_method_id, classid2name, classname2id, classname?, decodeid, decodename_fs, decodename_url, encodeid, encodename_fs, encodename_rdocurl, encodename_url, functionname?, gvarname?, html_filename, libid2name, libname2id, libname?, method_spec?, methodid2classid, methodid2libid, methodid2mname, methodid2specparts, methodid2specstring, methodid2typechar, methodid2typemark, methodid2typename, methodname?, split_method_id, split_method_spec, typechar2mark, typechar2name, typechar?, typemark2char, typemark2name, typemark?, typename2char, typename2mark, typename?

Methods inherited from BitClust::Subcommand

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

Constructor Details

#initializeStatichtmlCommand

Returns a new instance of StatichtmlCommand.


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/bitclust/subcommands/statichtml_command.rb', line 85

def initialize
  if Object.const_defined?(:Encoding)
    Encoding.default_external = 'utf-8'
  end
  super
  @verbose = true
  @catalogdir = nil
  @templatedir = srcdir_root + "data/bitclust/template.offline"
  @themedir = srcdir_root + "theme/default"
  @suffix = ".html"
  @parser.banner = "Usage: #{File.basename($0, '.*')} statichtml [options]"
  @parser.on('-o', '--outputdir=PATH', 'Output directory') do |path|
    begin
      @outputdir = Pathname.new(path).realpath
    rescue Errno::ENOENT
      FileUtils.mkdir_p(path, :verbose => @verbose)
      retry
    end
  end
  @parser.on('--catalog=PATH', 'Catalog directory') do |path|
    @catalogdir = Pathname.new(path).realpath
  end
  @parser.on('--templatedir=PATH', 'Template directory') do |path|
    @templatedir = Pathname.new(path).realpath
  end
  @parser.on('--themedir=PATH', 'Theme directory') do |path|
    @themedir = Pathname.new(path).realpath
  end
  @parser.on('--suffix=SUFFIX', 'Suffix for each (X)HTML file [.html]') do |suffix|
    @suffix = suffix
  end
  @parser.on('--fs-casesensitive', 'Filesystem is case-sensitive') do
    @fs_casesensitive = true
  end
  @parser.on('--[no-]quiet', 'Be quiet') do |quiet|
    @verbose = !quiet
  end
end

Instance Method Details

#exec(argv, options) ⇒ Object


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/bitclust/subcommands/statichtml_command.rb', line 124

def exec(argv, options)
  create_manager_config

  prefix = options[:prefix]
  db = MethodDatabase.new(prefix.to_s)
  fdb = FunctionDatabase.new(prefix.to_s)
  manager = ScreenManager.new(@manager_config)

  db.transaction do
    methods = {}
    db.methods.each_with_index do |entry, i|
      entry.names.each do |name|
        method_name = entry.klass.name + entry.typemark + name
        (methods[method_name] ||= []) << entry
      end
    end

    entries = db.docs + db.libraries.sort + db.classes.sort
    create_html_entries("entries", entries, manager, db)
    create_html_methods("methods", methods, manager, db)
  end

  fdb.transaction do
    functions = {}
    create_html_entries("capi", fdb.functions, manager, fdb)
  end

  @urlmapper.bitclust_html_base = '..'
  create_file(@outputdir + "library/#{html_filename("index", @suffix)}",
              manager.library_index_screen(db.libraries.sort, {:database => db}).body,
              :verbose => @verbose)
  create_file(@outputdir + "class/#{html_filename("index", @suffix)}",
              manager.class_index_screen(db.classes.sort, {:database => db}).body,
              :verbose => @verbose)
  create_file(@outputdir + "function/#{html_filename("index", @suffix)}",
              manager.function_index_screen(fdb.functions.sort, { :database => fdb }).body,
              :verbose => @verbose)
  create_index_html(@outputdir)
  FileUtils.cp(@manager_config[:themedir] + @manager_config[:css_url],
               @outputdir.to_s, {:verbose => @verbose, :preserve => true})
  FileUtils.cp(@manager_config[:themedir] + @manager_config[:favicon_url],
               @outputdir.to_s, {:verbose => @verbose, :preserve => true})
  Dir.mktmpdir do |tmpdir|
    FileUtils.cp_r(@manager_config[:themedir] + 'images', tmpdir,
                   {:verbose => @verbose, :preserve => true})
    Dir.glob(File.join(tmpdir, 'images', '/**/.svn')).each do |d|
      FileUtils.rm_r(d, {:verbose => @verbose})
    end
    FileUtils.cp_r(File.join(tmpdir, 'images'), @outputdir.to_s,
                   {:verbose => @verbose, :preserve => true})
  end
end