Class: Jets::Commands::Markdown::Page
- Inherits:
-
Object
- Object
- Jets::Commands::Markdown::Page
- Defined in:
- lib/jets/commands/markdown/page.rb
Instance Attribute Summary collapse
-
#cli_name ⇒ Object
readonly
Returns the value of attribute cli_name.
Instance Method Summary collapse
- #desc_markdown ⇒ Object
- #description ⇒ Object
- #doc ⇒ Object
- #front_matter ⇒ Object
- #full_command ⇒ Object
-
#initialize(cli_class:, command_name:) ⇒ Page
constructor
A new instance of Page.
-
#long_desc_markdown ⇒ Object
If the Thor long_description is empty then use the description.
-
#long_description ⇒ Object
Use command’s long description as main description.
- #namespace ⇒ Object
- #options ⇒ Object
-
#options_markdown ⇒ Object
handles blank options.
- #path ⇒ Object
- #usage ⇒ Object
- #usage_markdown ⇒ Object
Constructor Details
#initialize(cli_class:, command_name:) ⇒ Page
Returns a new instance of Page.
4 5 6 7 8 9 10 |
# File 'lib/jets/commands/markdown/page.rb', line 4 def initialize(cli_class:, command_name:) @cli_class = cli_class # IE: Jets::Commands::Main @command_name = command_name # IE: generate @cli_name = "jets" @command = @cli_class.commands[@command_name] end |
Instance Attribute Details
#cli_name ⇒ Object (readonly)
Returns the value of attribute cli_name.
3 4 5 |
# File 'lib/jets/commands/markdown/page.rb', line 3 def cli_name @cli_name end |
Instance Method Details
#desc_markdown ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/jets/commands/markdown/page.rb', line 90 def desc_markdown <<-EOL ## Description #{description} EOL end |
#description ⇒ Object
27 28 29 |
# File 'lib/jets/commands/markdown/page.rb', line 27 def description @command.description end |
#doc ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/jets/commands/markdown/page.rb', line 63 def doc <<-EOL #{front_matter} #{usage_markdown} #{long_desc_markdown} #{} EOL end |
#front_matter ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/jets/commands/markdown/page.rb', line 72 def front_matter command = [cli_name, full_command].compact.join(' ') <<-EOL --- title: #{command} reference: true --- EOL end |
#full_command ⇒ Object
18 19 20 |
# File 'lib/jets/commands/markdown/page.rb', line 18 def full_command [namespace, @command_name].compact.join(':') end |
#long_desc_markdown ⇒ Object
If the Thor long_description is empty then use the description.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/jets/commands/markdown/page.rb', line 99 def long_desc_markdown return desc_markdown if long_description.empty? <<-EOL ## Description #{description}. #{long_description} EOL end |
#long_description ⇒ Object
Use command’s long description as main description
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jets/commands/markdown/page.rb', line 46 def long_description text = @command.long_description return "" if text.nil? # empty description lines = text.split("\n") lines.map do |line| # In the CLI help, we use 2 spaces to designate commands # In Markdown we need 4 spaces. line.sub(/^ \b/, ' ') end.join("\n") end |
#namespace ⇒ Object
22 23 24 25 |
# File 'lib/jets/commands/markdown/page.rb', line 22 def namespace ns = @cli_class.to_s.sub('Jets::Commands::','').underscore.gsub('/','-') ns == 'main' ? nil : ns end |
#options ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jets/commands/markdown/page.rb', line 31 def shell = Shell.new @cli_class.send(:class_options_help, shell, nil => @command..values) text = shell.stdout.string return "" if text.empty? # there are no options lines = text.split("\n")[1..-1] # remove first line wihth "Options: " lines.map! do |line| # remove 2 leading spaces line.sub(/^ /, '') end lines.join("\n") end |
#options_markdown ⇒ Object
handles blank options
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/jets/commands/markdown/page.rb', line 112 def return '' if .empty? <<-EOL ## Options ``` #{} ``` EOL end |
#path ⇒ Object
58 59 60 61 |
# File 'lib/jets/commands/markdown/page.rb', line 58 def path full_name = [cli_name, namespace, @command_name].compact.join('-') "docs/_reference/#{full_name}.md" end |
#usage ⇒ Object
12 13 14 15 16 |
# File 'lib/jets/commands/markdown/page.rb', line 12 def usage = @cli_class.send(:banner, @command) # banner is protected method invoking_command = File.basename($0) # could be rspec, etc .sub(invoking_command, cli_name) end |
#usage_markdown ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/jets/commands/markdown/page.rb', line 82 def usage_markdown <<-EOL ## Usage #{usage} EOL end |