Improve CLI reference

This commit is contained in:
Clément Fournier
2018-05-25 03:02:37 +02:00
parent eb21f3189d
commit de080f02e4
3 changed files with 179 additions and 155 deletions

View File

@ -0,0 +1,23 @@
<!-- Row of the CLI reference table, describing an option -->
<!-- Argument summary: -->
<!-- options: comma separated list of aliases for the option.-->
<!-- option_arg: optional name for the argument of the option, eg 'arg', will be formatted eg to '<arg>'-->
<!-- description: description, you can use "some" inline markdown -->
<!-- required: whether the option is required, if specified, whatever the value, it's considered required -->
<!-- languages: languages to which the option applies -->
<!-- default: default value -->
{% assign arg = {{ include.option_arg | prepend: "&nbsp;<" | append: ">" | escape_once | keep_if: include.option_arg }} %}
{% capture required_label %}{% if include.required %}<span class="label label-primary">Required</span> {% endif %}{% endcapture %}
<tr>
<td><code>{{ include.options | split: ',' | mappend: arg | join: "</code><br/><code>" }}</code></td>
<td>{{ required_label }}
{{ include.description
| regex_replace: "`(.*?)`", "<code>\1</code>"
| regex_replace: "\*\*(.*?)\*\*", "<b>\1</b>"
| regex_replace: "\*(.*?)\*", "<i>\1</i>"
| regex_replace: "\[(.*?)\]\((.*?)\)", "<a href='\2'>\1</a>" }}
</td>
<td><code>{{ include.default }}</code></td>
<td>{{ include.languages }}</td>
</tr>

View File

@ -44,6 +44,31 @@ module CustomFilters
end
def regex_replace(str, regex, subst)
if str && regex
str.gsub(Regexp::new(regex), subst || "")
end
end
def regex_split(str, regex = nil)
if str
str.split(regex && Regexp::new(regex))
end
end
# Takes an array of strings and maps every element x to {{ x | append: suffix }}
def mappend(xs, suffix)
Array(xs).map {|x| "#{x}#{suffix}" }
end
# Returns the initial argument only if the second argument is truthy
def keep_if(any, test)
if test
any
end
end
private
def flatten_rec(seq)

File diff suppressed because it is too large Load Diff