Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benpa/spec tables prettier #1599

Merged
merged 8 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions scripts/css/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,30 @@ table.citation td {
border-bottom: none;
}

table.colwidths-auto caption {
font-family: monospace;
font-size: large;
padding: 2px;
text-align: left;
}

table.colwidths-auto {
width:100%;
margin-top: 20px;
}

table.colwidths-auto tr td:nth-child(1) {
width: 15%;
}

table.colwidths-auto tr td:nth-child(2) {
width: 15%;
}

table.colwidths-auto tr td:nth-child(3) {
width: 70%;
}

/* -- other body styles ----------------------------------------------------- */

ol.arabic {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
{{common_event.desc}}

{% for table in common_event.tables %}
{{"``"+table.title+"``" if table.title else "" }}

{{ tables.paramtable(table.rows, ["Key", "Type", "Description"]) }}
{{ tables.paramtable(table.rows, [(table.title or "") ~ " Key", "Type", "Description"]) }}

{% endfor %}
1 change: 0 additions & 1 deletion scripts/templating/matrix_templates/templates/events.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
{{event.desc}}

{% for table in event.content_fields %}
{{"``"+table.title+"``" if table.title else "" }}

{{ tables.paramtable(table.rows, [(table.title or "Content") ~ " Key", "Type", "Description"]) }}

Expand Down
8 changes: 4 additions & 4 deletions scripts/templating/matrix_templates/templates/http-api.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Request format:
{{ tables.split_paramtable(endpoint.req_param_by_loc) }}
{% if (endpoint.req_body_tables) %}
{% for table in endpoint.req_body_tables -%}
{{"``"+table.title+"``" if table.title else "" }}
{{ tables.paramtable(table.rows) }}
{{ tables.paramtable(table.rows, [(table.title or "") ~ " Parameter", "Type", "Description"] ) }}

{% endfor -%}
{% endif -%}

Expand All @@ -37,9 +37,9 @@ Response headers:
Response format:

{% for table in endpoint.res_tables -%}
{{"``"+table.title+"``" if table.title else "" }}

{{ tables.paramtable(table.rows) }}
{{ tables.paramtable(table.rows, [(table.title or "") ~ " Parameter", "Type", "Description"] ) }}


{% endfor %}
{% endif -%}
Expand Down
9 changes: 7 additions & 2 deletions scripts/templating/matrix_templates/templates/msgtypes.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
{{(4 + event.msgtype | length) * title_kind}}
{{event.desc | wrap(80)}}
{% for table in event.content_fields -%}
{{"``"+table.title+"``" if table.title else "" }}

{{ tables.paramtable(table.rows, [(table.title or "Content") ~ " Key", "Type", "Description"]) }}
{% if table.title -%}
{% set tabletitle = table.title -%}
{% else -%}
{% set tabletitle = "" -%}
{% endif -%}

{{ tables.paramtable(table.rows, [(table.title or "Content") ~ " Key", "Type", "Description"] ) }}

{% endfor %}
Example:
Expand Down
18 changes: 13 additions & 5 deletions scripts/templating/matrix_templates/templates/tables.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
{% set fieldwidths = (([titlerow] + flatrows) |
fieldwidths(rowkeys[0:-1], [10, 10])) + [50] -%}

{% set caption = titlerow['key'] | replace (' Key', '') | replace ('Parameter', '') -%}
{% if caption == 'Content' -%}
{% set caption = '' -%}
{% endif -%}

{{".. table:: "}}{{ caption }}
{{" :widths: auto"}}
{{""}}
{{ tableheader(fieldwidths) }}
{{ tablerow(fieldwidths, titlerow, rowkeys) }}
{{ tableheader(fieldwidths) }}
Expand All @@ -59,7 +67,7 @@
# Write a table header row, for the given column widths
#}
{% macro tableheader(widths) -%}
{% for arg in widths -%}
{{" "}}{% for arg in widths -%}
{{"="*arg}} {% endfor -%}
{% endmacro %}

Expand All @@ -71,7 +79,7 @@
# attributes of 'row' to look up for values to put in the columns.
#}
{% macro tablerow(widths, row, keys) -%}
{% for key in keys -%}
{{" "}}{% for key in keys -%}
{% set value=row[key] -%}
{% if not loop.last -%}
{# the first few columns need space after them -#}
Expand All @@ -81,7 +89,7 @@
the preceding columns, plus the number of preceding columns (for the
separators)) -#}
{{ value | wrap(widths[loop.index0]) |
indent_block(widths[0:-1]|sum + loop.index0) -}}
indent_block(widths[0:-1]|sum + loop.index0 + 2) -}}
{% endif -%}
{% endfor -%}
{% endmacro %}
Expand All @@ -93,10 +101,10 @@
# write a tablespan row. This is a single value which spans the entire table.
#}
{% macro tablespan(widths, value) -%}
{{value}}
{{" "}}{{value}}
{# we write a trailing space to stop the separator being misinterpreted
# as a header line. -#}
{{"-"*(widths|sum + widths|length -1)}} {% endmacro %}
{{" "}}{{"-"*(widths|sum + widths|length -1)}} {% endmacro %}



Expand Down