Class: CliMarkdown::Creator
- Inherits:
-
Object
- Object
- CliMarkdown::Creator
- Defined in:
- lib/cli_markdown/creator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_all ⇒ Object
- #create_include_reference ⇒ Object
- #create_index ⇒ Object
- #create_page(page) ⇒ Object
-
#initialize(cli_class:, cli_name:, parent_command_name: nil) ⇒ Creator
constructor
cli_class is top-level CLI class.
- #say(text) ⇒ Object
- #subcommand?(command_name) ⇒ Boolean
- #subcommand_class(command_name) ⇒ Object
Constructor Details
#initialize(cli_class:, cli_name:, parent_command_name: nil) ⇒ Creator
cli_class is top-level CLI class.
18 19 20 21 22 |
# File 'lib/cli_markdown/creator.rb', line 18 def initialize(cli_class:, cli_name:, parent_command_name: nil) @cli_class = cli_class @cli_name = cli_name @parent_command_name = parent_command_name end |
Class Method Details
.clean ⇒ Object
12 13 14 15 |
# File 'lib/cli_markdown/creator.rb', line 12 def self.clean FileUtils.rm_rf("docs/_reference") FileUtils.rm_f("docs/reference.md") end |
.create_all(options = {}) ⇒ Object
7 8 9 10 |
# File 'lib/cli_markdown/creator.rb', line 7 def self.create_all(={}) clean unless [:parent_command_name] new().create_all end |
Instance Method Details
#create_all ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cli_markdown/creator.rb', line 24 def create_all create_index unless @parent_command_name @cli_class.commands.keys.each do |command_name| page = Page.new( cli_class: @cli_class, cli_name: @cli_name, command_name: command_name, parent_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( cli_class: subcommand_class, cli_name: @cli_name, parent_command_name: parent_command_name ) end end end |
#create_include_reference ⇒ Object
64 65 66 67 |
# File 'lib/cli_markdown/creator.rb', line 64 def create_include_reference path = "docs/_includes/reference.md" IO.write(path, "Generic tool description. Please edit #{path} with a description.") unless File.exist?(path) end |
#create_index ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/cli_markdown/creator.rb', line 56 def create_index create_include_reference page = Index.new(@cli_class, @cli_name) FileUtils.mkdir_p(File.dirname(page.path)) say "Creating #{page.path}" IO.write(page.path, page.doc) end |
#create_page(page) ⇒ Object
50 51 52 53 54 |
# File 'lib/cli_markdown/creator.rb', line 50 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
77 78 79 |
# File 'lib/cli_markdown/creator.rb', line 77 def say(text) puts text unless self.class.mute end |
#subcommand?(command_name) ⇒ Boolean
69 70 71 |
# File 'lib/cli_markdown/creator.rb', line 69 def subcommand?(command_name) @cli_class.subcommands.include?(command_name) end |
#subcommand_class(command_name) ⇒ Object
73 74 75 |
# File 'lib/cli_markdown/creator.rb', line 73 def subcommand_class(command_name) @cli_class.subcommand_classes[command_name] end |