Class: Mizuho::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/mizuho/generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, options = {}) ⇒ Generator

Returns a new instance of Generator.



12
13
14
15
16
17
18
19
# File 'lib/mizuho/generator.rb', line 12

def initialize(input, options = {})
  @input_file = input
  @output_name = options[:output]
  @template = locate_template_file(options[:template])
  @multi_page = options[:multi_page]
  @icons_dir = options[:icons_dir]
  @conf_file = options[:conf_file]
end

Class Method Details

.run_asciidoc(input, output, icons_dir = nil, conf_file = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mizuho/generator.rb', line 29

def self.run_asciidoc(input, output, icons_dir = nil, conf_file = nil)
  args = ["python", ASCIIDOC, "-a", "toc", "-a", "icons"]
  if icons_dir
    args << "-a"
    args << "iconsdir=#{icons_dir}"
  end
  if conf_file
    # With the splat operator we support a string and an array of strings.
    [*conf_file].each do |cf|
      args << "-f"
      args << cf
    end
  end
  args += ["-n", "-o", output, input]
  if !system(*args)
    raise GenerationError, "Asciidoc failed."
  end
end

Instance Method Details

#startObject



21
22
23
24
25
26
27
# File 'lib/mizuho/generator.rb', line 21

def start
  output_filename = determine_output_filename(@input_file, @output_name)
  self.class.run_asciidoc(@input_file, output_filename, @icons_dir, @conf_file)
  if @template
    apply_template(output_filename, @input_file, @output_name, @template, @multi_page)
  end
end