Skip to content

Commit

Permalink
Merge pull request blzjns#14 from DavidRenault/master
Browse files Browse the repository at this point in the history
Fix the render of raml2html with the update of the template from raml…
  • Loading branch information
blzjns authored Jul 18, 2018
2 parents e224b8f + 7f8d044 commit 36859c7
Show file tree
Hide file tree
Showing 3 changed files with 398 additions and 88 deletions.
18 changes: 18 additions & 0 deletions raml2html_template/examples.nunjucks
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% if parent.examples.length %}
<p><strong>{{ 'Example' if parent.examples.length == 1 else 'Examples' }}</strong>:</p>
<div class="examples">
{% for example in parent.examples %}
{% if example.displayName or example.description %}
<p>
{% if example.displayName %}
<strong>{{ example.displayName }}</strong>:<br />
{% endif %}
{% if example.description %}
{{ example.description }}
{% endif %}
</p>
{% endif %}
<pre><code>{{ example.value | escape }}</code></pre>
{% endfor %}
</div>
{% endif %}
125 changes: 89 additions & 36 deletions raml2html_template/item.nunjucks
Original file line number Diff line number Diff line change
@@ -1,47 +1,100 @@
<li>
{% if item.displayName %}
<strong>{{ item.displayName }}</strong>:
{% else %}
<strong>{{ key }}</strong>:
{% endif %}
<strong>{{ item.key }}</strong>{% if item.type !== nil %}:

{% if not item.structuredValue %}
<em>
{%- if item.required -%}required {% endif -%}
(
{%- if item.enum -%}
{%- if item.enum.length === 1 -%}
{{ item.enum.join(', ') }}
{%- else -%}
one of {{ item.enum.join(', ') }}
{%- endif -%}
{%- else -%}
{%- if item.type === 'array' and item.items -%}
array of {{ item.items.originalType | d(item.items.type) }}
{%- elif item.type === 'union' and item.anyOf.length -%}
union of
{% for alt in item.anyOf -%}
{{ alt.originalType | d(alt.displayName) | d(alt.type) }}
{%- if not loop.last %} or {% endif -%}
{%- endfor -%}
{%- else -%}
{{ item.type }}
{%- endif -%}
{%- endif -%}

<em>
{%- if item.required -%}required {% endif -%}
(
{%- if item.enum -%}
one of {{ item.enum.join(', ') }}
{%- else -%}
{{ item.type }}
{%- endif -%}

{%- if item.default or item.default == 0 or item.default == false %} - default: {{ item.default }}{%- endif -%}
{%- if item.repeat %} - repeat: {{ item.repeat }}{%- endif -%}
{%- if item.type == 'string' -%}
{%- if item.minLength or item.minLength == 0 %} - minLength: {{ item.minLength }}{%- endif -%}
{%- if item.maxLength or item.maxLength == 0 %} - maxLength: {{ item.maxLength }}{%- endif -%}
{%- else -%}
{%- if item.minimum or item.minimum == 0 %} - minimum: {{ item.minimum }}{%- endif -%}
{%- if item.maximum or item.maximum == 0 %} - maximum: {{ item.maximum }}{%- endif -%}
{%- endif -%}
{%- if item.pattern %} - pattern: {{ item.pattern }}{%- endif -%}
)
</em>
{%- if item.default or item.default == 0 or item.default == false %} - default: {{ item.default }}{%- endif -%}
{%- if item.repeat %} - repeat: {{ item.repeat }}{%- endif -%}
{%- if item.type == 'string' -%}
{%- if item.minLength or item.minLength == 0 %} - minLength: {{ item.minLength }}{%- endif -%}
{%- if item.maxLength or item.maxLength == 0 %} - maxLength: {{ item.maxLength }}{%- endif -%}
{%- else -%}
{%- if item.minItems or item.minItems == 0 %} - minItems: {{ item.minItems }}{%- endif -%}
{%- if item.maxItems or item.maxItems == 0 %} - maxItems: {{ item.maxItems }}{%- endif -%}
{%- if item.minimum or item.minimum == 0 %} - minimum: {{ item.minimum }}{%- endif -%}
{%- if item.maximum or item.maximum == 0 %} - maximum: {{ item.maximum }}{%- endif -%}
{%- endif -%}
{%- if item.pattern %} - pattern: {{ item.pattern }}{%- endif -%}
)
</em>
{% endif %}
{% endif %}

{% markdown %}
{{ item.description }}
{% endmarkdown %}

{% if item.schema %}
<p><strong>Schema</strong>:</p>
<pre><code>{{ item.schema | escape }}</code></pre>
{% if item.annotations.length %}
<h3>Annotations</h3>
<ul>
{% for item in item.annotations %}
{% include "./item.nunjucks" %}
{% endfor %}
</ul>
{% endif %}

{% if item.example %}
<p><strong>Example</strong>:</p>
{% if item.type == 'string' %}
<pre>{{ item.example| escape }}</pre>
{% else %}
<pre><code>{{ item.example | escape }}</code></pre>
{% if item.items and item.items.properties %}
{% if isStandardType(item.items) %}
<p><strong>Items</strong>: {{ item.items }}</p>
{% endif %}

{% if not isStandardType(item.items) %}
<p><strong>Items</strong>: {{ item.items.displayName }}</p>

{% if item.items.properties or item.items.examples.length %}
<div class="items">
{% if item.items.properties %}
<ul>
{% for item in item.items.properties %}
{% include "./item.nunjucks" %}
{% endfor %}
</ul>
{% endif %}

{# Sub-item Examples #}
{% set parent = item.items %}
{% include "./examples.nunjucks" %}
</div>
{% endif %}
{% endif %}
{% endif %}
</li>

{% if item.properties %}
<ul>
{% for item in item.properties %}
{% include "./item.nunjucks" %}
{% endfor %}
</ul>
{% endif %}

{# Item Examples #}
{% set parent = item %}
{% include "./examples.nunjucks" %}

{% if item.structuredValue %}
<pre><code>{{ item.structuredValue | dump }}</code></pre>
{% endif %}

</li>
Loading

0 comments on commit 36859c7

Please sign in to comment.