Class: MarkDApp

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

Instance Method Summary collapse

Instance Method Details

#force_exit(reason) ⇒ Object



53
54
55
56
# File 'lib/markd.rb', line 53

def force_exit(reason)
  puts reason
  exit 0
end

#init(argv) ⇒ Object



49
50
51
# File 'lib/markd.rb', line 49

def init(argv)
  @options = parse_opts argv
end

#parse_opts(argv) ⇒ Object



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

def parse_opts(argv)
  @options = {}
  OptionParser.new { |opt|
    opt.on("-v", "--version") {
      version = File.read "#{APP_ROOT}/VERSION"
      puts "#{APP_NAME} #{version}"
      exit(0)
    }
    opt.on("-h", "--help") {
      puts usage
      exit(0)
    }
    opt.on("-o OUTDIR", "--output OUTDIR") { |out_dir|
      @options[:out_dir] = out_dir
    }
    
    opt.parse! argv
  }
  @options
end

#publish(filename, out_filename) ⇒ Object



58
59
60
61
62
# File 'lib/markd.rb', line 58

def publish(filename, out_filename)
  force_exit("#{filename} not file or exists") unless File.file? filename
  out_dir = @options[:out_dir] || "docs"
  MarkD.new.publish(filename, out_dir, out_filename)
end

#run(argv) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/markd.rb', line 64

def run(argv)
  init argv
  
  argv.each do |filename|
    # use 'index.html' as output if one input file given
    out_filename = (argv.size == 1) ? "index.html" : File.basename(filename, ".*") + ".html"
    publish filename, out_filename
  end
end

#usageObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/markd.rb', line 16

def usage
  usage_text = <<-"USAGE"
Usage:
markd [-o OUTPUT_DIR] markdown

Options:
-v, [--version]           show version
-h, [--help]              show usage
-o, [--output=OUTPUT_DIR] set output directory (default "docs")
USAGE
end