Class: BitClust::Subcommands::SearchpageCommand
- Inherits:
-
BitClust::Subcommand
- Object
- BitClust::Subcommand
- BitClust::Subcommands::SearchpageCommand
- Defined in:
- lib/bitclust/subcommands/searchpage_command.rb
Constant Summary collapse
- VENDORED_JS_FILES =
search_init.js is the in-page dropdown wiring used by statichtml layouts; this page ships its own wiring (search_page.js) instead.
%w[ search_navigation.js search_ranker.js search_controller.js ].freeze
Instance Method Summary collapse
- #exec(argv, options) ⇒ Object
-
#initialize ⇒ SearchpageCommand
constructor
A new instance of SearchpageCommand.
-
#needs_database? ⇒ Boolean
DB paths are taken as positional arguments (one per version), so the global --database option is not required.
Methods inherited from BitClust::Subcommand
#align_progress_bar_title, #error, #help, #option_error, #parse, #srcdir_root
Constructor Details
#initialize ⇒ SearchpageCommand
Returns a new instance of SearchpageCommand.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bitclust/subcommands/searchpage_command.rb', line 34 def initialize super @outputdir = nil @themedir = srcdir_root + "theme/default" @templatedir = srcdir_root + "data/bitclust/searchpage" @suffix = ".html" @fs_casesensitive = false @verbose = false @parser. = "Usage: #{File.basename($0, '.*')} searchpage [options] <dbpath>..." @parser.on('-o', '--outputdir=PATH', 'Output directory.') {|path| @outputdir = Pathname.new(path) } @parser.on('--themedir=PATH', 'Theme directory.') {|path| @themedir = Pathname.new(path) } @parser.on('--fs-casesensitive', 'Filesystem is case-sensitive.') { @fs_casesensitive = true } @parser.on('--verbose', 'Show progress.') { @verbose = true } end |
Instance Method Details
#exec(argv, options) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/bitclust/subcommands/searchpage_command.rb', line 63 def exec(argv, ) outputdir = @outputdir or error("no --outputdir given") error("no database given (pass one path per version)") if argv.empty? generator = SearchIndexGenerator.new(suffix: @suffix, fs_casesensitive: @fs_casesensitive) version_indexes = argv.map {|path| db = MethodDatabase.new(path) fdb = FunctionDatabase.new(path) if File.directory?(File.join(path, 'function')) version = db.properties['version'] or error("#{path}: no version property (not a bitclust database?)") $stderr.puts "indexing #{path} (#{version})" if @verbose [version, generator.build_index(db, fdb)] #: [String, Array[SearchIndexGenerator::entry]] } versions = version_indexes.map {|version, _| version } .sort_by {|v| Gem::Version.new(v) } jsdir = outputdir + "js" FileUtils.mkdir_p(jsdir) (jsdir + "search_data.js").write(SearchIndexGenerator.merged_js(version_indexes)) VENDORED_JS_FILES.each do |js| FileUtils.cp(@themedir + "js" + js, jsdir.to_s, :preserve => true) end # Ship the MIT notice for the vendored Aliki files alongside them. FileUtils.cp(@themedir + "js" + "NOTICE", jsdir.to_s, :preserve => true) FileUtils.cp(@themedir + "js" + "search_page.js", jsdir.to_s, :preserve => true) FileUtils.cp(@themedir + "search.css", outputdir.to_s, :preserve => true) (outputdir + "index.html").write(render_page(versions)) $stderr.puts "generated search page for #{versions.join(', ')}" if @verbose end |
#needs_database? ⇒ Boolean
DB paths are taken as positional arguments (one per version), so the global --database option is not required.
59 60 61 |
# File 'lib/bitclust/subcommands/searchpage_command.rb', line 59 def needs_database? false end |