Class: Lm2doc::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/lm2doc/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



8
9
10
# File 'lib/lm2doc/cli.rb', line 8

def initialize(argv)
  self.argv = argv
end

Instance Attribute Details

#argvObject

Returns the value of attribute argv.



6
7
8
# File 'lib/lm2doc/cli.rb', line 6

def argv
  @argv
end

#inputsObject

Returns the value of attribute inputs.



6
7
8
# File 'lib/lm2doc/cli.rb', line 6

def inputs
  @inputs
end

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/lm2doc/cli.rb', line 6

def output
  @output
end

Instance Method Details

#executeObject



41
42
43
44
45
46
47
# File 'lib/lm2doc/cli.rb', line 41

def execute
  self.parse_argv
  
  self.inputs.each do |input|
    perfrom_source(input)
  end
end

#parse_argvObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lm2doc/cli.rb', line 16

def parse_argv
  self.inputs = []
  
  opts = OptionParser.new(self.argv.dup) do |opts|
    opts.banner = "lm2doc is a convertor for lightweight markup language to pretty html document."
    opts.separator ""
    opts.separator "Usage:"
    opts.separator "    lm2doc [OPTION]...[-i] FILE"
    opts.separator ""
    
    opts.separator "Options:"
    opts.on("-v", "--version", "show the version of lm2doc") { puts Lm2doc::VERSION; exit }
    opts.on("-i", "--in FILE", "input path") {|v| self.inputs = [ v ] }
    # opts.on("-o", "--out DIR|FILE", "output path") {|v| self.output = v }
  end
  
  others = opts.parse!
  self.inputs = others
  
  if self.inputs.length != 1
    puts opts.help()
    exit
  end
end

#perfrom_source(source_file) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/lm2doc/cli.rb', line 49

def perfrom_source(source_file)
  source = Resource::Source.build(source_file)
  
  output_dir = File.dirname(source_file)
  FileUtils.mkdir_p(output_dir)
  source.write(output_dir, :theme => theme)
end

#themeObject



12
13
14
# File 'lib/lm2doc/cli.rb', line 12

def theme
  Lm2doc.theme("simple")
end