Class: BitClust::Subcommands::HtmlfileCommand

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

Instance Method Summary collapse

Methods inherited from BitClust::Subcommand

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

Constructor Details

#initializeHtmlfileCommand

Returns a new instance of HtmlfileCommand.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bitclust/subcommands/htmlfile_command.rb', line 14

def initialize
  super
  @target = nil
  @templatedir = srcdir_root + "data/bitclust/template.offline"
  @baseurl = "file://" + srcdir_root.to_s
  @version = RUBY_VERSION
  @parser.banner = "Usage: #{File.basename($0, '.*')} htmlfile [options] rdfile"
  @parser.on('--target=NAME', 'Compile NAME to HTML.') {|name|
    @target = name
  }
  @parser.on('--[no-]force', '-f', 'Force to use rd_file template.') {|bool|
    @rd_file = bool
  }
  @parser.on('--ruby_version=VER', '--ruby=VER', 'Set Ruby version') {|version|
    @version = version
  }
  @parser.on('--baseurl=URL', 'Base URL of generated HTML') {|url|
    @baseurl = url
  }
  @parser.on('--templatedir=PATH', 'Template directory') {|path|
    @templatedir = path
  }
end

Instance Method Details

#exec(argv, options) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
# File 'lib/bitclust/subcommands/htmlfile_command.rb', line 43

def exec(argv, options)
  db = MethodDatabase.dummy({'version' => @version})
  if options[:prefix]
    db = MethodDatabase.new(options[:prefix])
  end
  @capi = options[:capi]
  target_file = argv[0]
  if /refm\/doc\// =~ target_file
    @rd_file = true if @rd_file.nil?
  end
  options = { 'version' => @version } #: Database::database_properties
  manager = ScreenManager.new(:templatedir => @templatedir,
                              :base_url => @baseurl,
                              :cgi_url => @baseurl,
                              :default_encoding => 'utf-8')

  unless @rd_file
    begin
      if @capi
        lib = FunctionReferenceParser.parse_file(target_file, options)
        unless @target
          raise NotImplementedError, "generating a C API html without --target=NAME is not implemented yet."
        end
      else
        lib = RRDParser.parse_stdlib_file(target_file, options)
      end
      entry = @target ? lookup(lib, @target) : lib
      puts manager.entry_screen(entry, { :database => db, :target_version => @version }).body
      return
    rescue ParseError => ex
      $stderr.puts ex.message
      $stderr.puts ex.backtrace[0], ex.backtrace[1..-1]&.map{|s| "\tfrom " + s}
    end
  end

  begin
    entry = DocEntry.new(db, target_file)
    source = Preprocessor.read(target_file, options)
    entry.source = source
    puts manager.doc_screen(entry, { :database => db }).body
  rescue WriterError => ex
    $stderr.puts ex.message
    exit 1
  end
end

#needs_database?Boolean

DB は与えられれば使うが必須ではない (--database は任意)

Returns:

  • (Boolean)


39
40
41
# File 'lib/bitclust/subcommands/htmlfile_command.rb', line 39

def needs_database?
  false
end