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(options = {}) ⇒ Creator
constructor
cli_class is top-level CLI class.
- #say(text) ⇒ Object
- #subcommand?(command_name) ⇒ Boolean
- #subcommand_class(command_name) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Creator
cli_class is top-level CLI class.
19 20 21 22 23 |
# File 'lib/cli_markdown/creator.rb', line 19 def initialize(={}) @cli_class = [:cli_class] @cli_name = [:cli_name] @parent_command_name = [:parent_command_name] end |
Class Method Details
.clean ⇒ Object
13 14 15 16 |
# File 'lib/cli_markdown/creator.rb', line 13 def self.clean FileUtils.rm_rf("docs/_reference") FileUtils.rm_f("docs/reference.md") end |
.create_all(options = {}) ⇒ Object
8 9 10 11 |
# File 'lib/cli_markdown/creator.rb', line 8 def self.create_all(={}) clean unless [:parent_command_name] new().create_all end |
Instance Method Details
#create_all ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cli_markdown/creator.rb', line 25 def create_all create_index unless @parent_command_name commands = @cli_class.commands.reject { |command_name, command| command.hidden? } 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
66 67 68 69 70 |
# File 'lib/cli_markdown/creator.rb', line 66 def create_include_reference path = "docs/_includes/reference.md" FileUtils.mkdir_p(File.dirname(path)) IO.write(path, "Generic tool description. Please edit #{path} with a description.") unless File.exist?(path) end |
#create_index ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/cli_markdown/creator.rb', line 58 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
52 53 54 55 56 |
# File 'lib/cli_markdown/creator.rb', line 52 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
80 81 82 |
# File 'lib/cli_markdown/creator.rb', line 80 def say(text) puts text unless self.class.mute end |
#subcommand?(command_name) ⇒ Boolean
72 73 74 |
# File 'lib/cli_markdown/creator.rb', line 72 def subcommand?(command_name) @cli_class.subcommands.include?(command_name) end |
#subcommand_class(command_name) ⇒ Object
76 77 78 |
# File 'lib/cli_markdown/creator.rb', line 76 def subcommand_class(command_name) @cli_class.subcommand_classes[command_name] end |