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

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

Constructor Details

#initializeStatichtmlCommand

Returns a new instance of StatichtmlCommand.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
# File 'lib/bitclust/subcommands/statichtml_command.rb', line 105

def initialize
  if Object.const_defined?(:Encoding)
    begin
      verbose, $VERBOSE = $VERBOSE, false
      Encoding.default_external = 'utf-8'
    ensure
      $VERBOSE = verbose
    end
  end
  super
  @verbose = true
  @catalogdir = nil
  @templatedir = srcdir_root + "data/bitclust/template.offline"
  @themedir = srcdir_root + "theme/default"
  @suffix = ".html"
  @gtm_tracking_id = nil
  @meta_robots_content = ["noindex"]
  @stop_on_syntax_error = true
  @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('--canonical-base-url=URL', 'Canonical base URL') do |url|
    @canonical_base_url = url
  end
  @parser.on('--edit-base-url=URL', 'Edit base URL') do |url|
    @edit_base_url = url
  end
  @parser.on('--tracking-id=ID', 'Google Tag Manager Tracking ID') do |id|
    @gtm_tracking_id = id
  end
  @parser.on('--meta-robots-content=VALUE1,VALUE2,...', Array, 'HTML <meta> element: <meta name="robots" content="VALUE1,VALUE2..."') do |values|
    @meta_robots_content = values
  end
  @parser.on('--no-stop-on-syntax-error', 'Do not stop on syntax error') do |boolean|
    @stop_on_syntax_error = boolean
  end
  @parser.on('--[no-]quiet', 'Be quiet') do |quiet|
    @verbose = !quiet
  end
end

Instance Method Details

#exec(argv, options) ⇒ Object



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
221
222
223
# File 'lib/bitclust/subcommands/statichtml_command.rb', line 167

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|
      next if entry.undefined?

      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
    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] + "syntax-highlight.css",
               @outputdir.to_s, :verbose => @verbose, :preserve => true)
  FileUtils.cp(@manager_config[:themedir] + "script.js",
               @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