Class: SmartConfig::Markdown

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

Overview

Generates a markdown table documenting all config values in a SmartConfig module.

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Markdown

Returns a new instance of Markdown.



8
9
10
# File 'lib/smart_config/markdown.rb', line 8

def initialize(config)
  @config = config
end

Instance Method Details

#renderObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/smart_config/markdown.rb', line 12

def render
  rows = collect_entries(@config, [])
  return '' if rows.empty?

  lines = []
  lines << '| Key | Description | Example | Default | Format |'
  lines << '|-----|-------------|---------|---------|--------|'
  rows.each do |row|
    cells = [row[:path], row[:description], row[:example], row[:default], row[:format]]
    lines << "| #{cells.map { |c| escape(c) }.join(' | ')} |"
  end
  lines.join("\n")
end