Class: Lono::Markdown::Creator

Inherits:
Object
  • Object
show all
Defined in:
lib/lono/markdown/creator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_class, parent_command_name) ⇒ Creator

command_class is top-level CLI class.



18
19
20
21
# File 'lib/lono/markdown/creator.rb', line 18

def initialize(command_class, parent_command_name)
  @command_class = command_class
  @parent_command_name = parent_command_name
end

Class Method Details

.cleanObject



12
13
14
15
# File 'lib/lono/markdown/creator.rb', line 12

def self.clean
  FileUtils.rm_rf("docs/_reference")
  FileUtils.rm_f("docs/reference.md")
end

.create_all(command_class, parent_command_name = nil) ⇒ Object



7
8
9
10
# File 'lib/lono/markdown/creator.rb', line 7

def self.create_all(command_class,  parent_command_name=nil)
  clean unless parent_command_name
  new(command_class, parent_command_name).create_all
end

Instance Method Details

#create_allObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lono/markdown/creator.rb', line 23

def create_all
  create_index unless @parent_command_name

  @command_class.commands.keys.each do |command_name|
    page = Page.new(@command_class, command_name, @parent_command_name)
    create_page(page)

    if subcommand?(command_name)
      subcommand_class = subcommand_class(command_name)
      parent_command_name = command_name

      say "Creating subcommands pages for #{parent_command_name}..."
      Creator.create_all(subcommand_class, parent_command_name)
    end
  end
end

#create_indexObject



46
47
48
49
50
51
# File 'lib/lono/markdown/creator.rb', line 46

def create_index
  page = Index.new(@command_class)
  FileUtils.mkdir_p(File.dirname(page.path))
  say "Creating #{page.path}"
  IO.write(page.path, page.doc)
end

#create_page(page) ⇒ Object



40
41
42
43
44
# File 'lib/lono/markdown/creator.rb', line 40

def create_page(page)
  say "Creating #{page.path}..."
  FileUtils.mkdir_p(File.dirname(page.path))
  IO.write(page.path, page.doc)
end

#say(text) ⇒ Object



61
62
63
# File 'lib/lono/markdown/creator.rb', line 61

def say(text)
  puts text unless self.class.mute
end

#subcommand?(command_name) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/lono/markdown/creator.rb', line 53

def subcommand?(command_name)
  @command_class.subcommands.include?(command_name)
end

#subcommand_class(command_name) ⇒ Object



57
58
59
# File 'lib/lono/markdown/creator.rb', line 57

def subcommand_class(command_name)
  @command_class.subcommand_classes[command_name]
end