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

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

Constructor Details

#initializeHtmlfileCommand

Returns a new instance of HtmlfileCommand.


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

def initialize
  super
  @target = nil
  @templatedir = srcdir_root + "data/bitclust/template.offline"
  @baseurl = "file://" + srcdir_root.to_s
  @version = "2.0.0"
  @parser.banner = "Usage: #{File.basename($0, '.*')} htmlfile [options] rdfile"
  @parser.on('--target=NAME', 'Compile NAME to HTML.') {|name|
    @target = name
  }
  @parser.on('--force', '-f', 'Force to use rd_file template.') {|name|
    @rd_file = true
  }
  @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


37
38
39
40
41
42
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
# File 'lib/bitclust/subcommands/htmlfile_command.rb', line 37

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]
  options = { 'version' => @version }
  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 }).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