Skip to content

Instantly share code, notes, and snippets.

@a6b8
Last active July 10, 2021 21:00
Show Gist options
  • Select an option

  • Save a6b8/3f05e93bd4c73eb71d1e047d46c28cf3 to your computer and use it in GitHub Desktop.

Select an option

Save a6b8/3f05e93bd4c73eb71d1e047d46c28cf3 to your computer and use it in GitHub Desktop.
Create Option Markdown
def markdown_options_tables( lists, params )
def pick_values( pick, params )
keys = pick
.to_s
.split( '__' )
.map{ | a | a.to_sym }
result = nil
case( keys.length)
when 1
result = params[ keys[ 0 ] ]
when 2
result = params[ keys[ 0 ] ][ keys[ 1 ] ]
when 3
result = params[ keys[ 0 ] ][ keys[ 1 ] ][ keys[ 2 ] ]
when 4
result = params[ keys[ 0 ] ][ keys[ 1 ] ][ keys[ 2 ] ][ keys[ 3 ] ]
end
return result
end
sort = {}
lists[ 0 ].each do | key |
category = key.to_s.split( '__' )[ 0 ].to_sym
!sort.key?( category ) ? sort[ category ] = [] : ''
sort[ category ].push( key )
end
tables = {}
alphabet = 'A'.upto( 'Z' ).to_a
sort.keys.each.with_index do | category, index |
char = alphabet[ index ]
str = ''
str += "| Nr | Name | Key | Default | Type | Description |\n"
str += "| :-- | :-- | :-- | :-- | :-- | :-- |\n"
sort[ category ].each.with_index do | key, index |
nr = "#{char}.#{index + 1}."
name = key.to_s.split('__').drop( 1 ).map { | a | a[ 0, 1 ].upcase + a[ 1, a.length ]}.join( " " )
default = pick_values( key, params )
type = default.class.to_s
type.eql?('String') ? default = "\"#{default}\"" : ''
default = "`#{default}`"
str += "| #{nr} | #{name} |:#{key} | #{default} | #{type} | |\n"
end
tables[ category ] = str
end
str = "## Options\n"
tables.keys.each.with_index do | key |
name = key.to_s
name = name[ 0, 1 ].upcase + name[ 1, name.length ]
str += "### " + name + "\n"
str += tables[ key ]
str += "\n\n"
end
str = str[ 0, str.rindex("\n\n\n")]
return str
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment