Class: SmartConfig::Markdown
- Inherits:
-
Object
- Object
- SmartConfig::Markdown
- Defined in:
- lib/smart_config/markdown.rb
Overview
Generates a markdown table documenting all config values in a SmartConfig module.
Instance Method Summary collapse
-
#initialize(config) ⇒ Markdown
constructor
A new instance of Markdown.
- #render ⇒ Object
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
#render ⇒ Object
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 |