Class: Kanpachi::SubCommand::Doc

Inherits:
Thor
  • Object
show all
Defined in:
lib/kanpachi/cli/doc.rb

Overview

class CLI < Thor

Instance Method Summary collapse

Instance Method Details

#generate_doc(api_name, source_path, destination_path = "doc") ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kanpachi/cli/doc.rb', line 10

def generate_doc(api_name, source_path, destination_path="doc")
  puts "Starting"
  api_files = Dir.glob(File.join(destination_root, source_path, "**", "*.rb"))
  if api_files.empty?
    puts "No ruby files in source_path: #{File.join(destination_root, source_path)}"
    return
  end
  api_files.each do |file|
    require file
  end

  api = APIList.find(api_name)

  require 'fileutils'
  destination = File.join(destination_root, destination_path)
  FileUtils.mkdir_p(destination) unless File.exist?(destination)
  File.open("#{destination}/index.html", "w"){|f| f << doc_template.result(binding)}
  puts "Documentation available there: #{destination}/index.html"
  `open #{destination}/index.html` if RUBY_PLATFORM =~ /darwin/ && !ENV['DONT_OPEN']
end