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

Theme with attributes rendering #299

Open
wants to merge 12 commits into
base: olio-theme
Choose a base branch
from
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
coverage
node_modules
src
test

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the reason behind this being removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember exactly, but i think I needed it for debugging. Returned it.

npm-debug.log
.travis.yml
Expand Down
2 changes: 1 addition & 1 deletion templates/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ html
a.text-muted.back-to-top(href='#top')
i.fa.fa-toggle-up
|  Back to top
div(class=self.fullWidth ? 'container-fluid' : 'container')
div(class='container-fluid')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this being hard-coded to container-fluid now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I remember I liked it more :) Reverted.

.row
block nav
+Nav(false)
Expand Down
177 changes: 102 additions & 75 deletions templates/mixins.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

mixin Badge(method)
//- Draw a badge for a given HTTP method
case method
Expand Down Expand Up @@ -26,37 +25,37 @@ mixin Nav()
if self.api.navItems && self.api.navItems.length
.resource-group
.heading
.chevron
i.open.fa.fa-angle-down
a(href='#top') Overview
.chevron
i.open.fa.fa-angle-down
a(href='#top') Overview
.collapse-content
ul: each item in self.api.navItems
li
a(href=item[1])!= item[0]
ul: each item in self.api.navItems
li
a(href=item[1])!= item[0]
each resourceGroup in self.api.resourceGroups || []
.resource-group
.heading
.chevron
i.open.fa.fa-angle-down
a(href=resourceGroup.elementLink)!= resourceGroup.name || 'Resource Group'
.chevron
i.open.fa.fa-angle-down
a(href=resourceGroup.elementLink)!= resourceGroup.name || 'Resource Group'
.collapse-content
ul
each item in resourceGroup.navItems || []
li
a(href=item[1])!= item[0]
each resource in resourceGroup.resources || []
li
if !self.condenseNav || (resource.actions.length != 1)
a(href=resource.elementLink)!= resource.name || 'Resource'
ul: each action in resource.actions || []
li: a(href=action.elementLink)
+Badge(action.method)
!= action.name || action.method + ' ' + (action.attributes && action.attributes.uriTemplate || resource.uriTemplate)
else
- var action = resource.actions[0]
a(href=action.elementLink)
+Badge(action.method)
!= action.name || resource.name || action.method + ' ' + (action.attributes && action.attributes.uriTemplate || resource.uriTemplate)
ul
each item in resourceGroup.navItems || []
li
a(href=item[1])!= item[0]
each resource in resourceGroup.resources || []
li
if !self.condenseNav || (resource.actions.length != 1)
a(href=resource.elementLink)!= resource.name || 'Resource'
ul: each action in resource.actions || []
li: a(href=action.elementLink)
+Badge(action.method)
!= action.name || action.method + ' ' + (action.attributes && action.attributes.uriTemplate || resource.uriTemplate)
else
- var action = resource.actions[0]
a(href=action.elementLink)
+Badge(action.method)
!= action.name || resource.name || action.method + ' ' + (action.attributes && action.attributes.uriTemplate || resource.uriTemplate)
//- Link to the API hostname, e.g. api.yourcompany.com
each meta in self.api.metadata || {}
if meta.name == 'HOST'
Expand Down Expand Up @@ -99,7 +98,13 @@ mixin Parameters(params)
code= self.urldec(value.value)
= ' '

mixin RequestResponse(title, request, collapse)
mixin Constraints(name, schema)
each constraint in ['minLength', 'maxLength', 'pattern']
if schema.properties[name][constraint]
div #{constraint}: #{schema.properties[name][constraint]}


mixin RequestResponse(title, request, collapse, showSchema)
.title
strong
= title
Expand All @@ -110,9 +115,9 @@ mixin RequestResponse(title, request, collapse)
.collapse-button
span.close Hide
span.open Show
+RequestResponseBody(request, collapse)
+RequestResponseBody(request, collapse, false, showSchema)

mixin RequestResponseBody(request, collapse, showBlank)
mixin RequestResponseBody(request, collapse, showBlank, showSchema)
if request.hasContent || showBlank
div(class=collapse ? 'collapse-content' : ''): .inner
if request.description
Expand All @@ -124,26 +129,48 @@ mixin RequestResponseBody(request, collapse, showBlank)
each item, index in request.headers
!= self.highlight(item.name + ': ' + item.value, 'http')
if index < request.headers.length - 1
br
br
div(style="height: 1px;")
if request.body
h5 Body
pre: code
!= self.highlight(request.body, null, ['json', 'yaml', 'xml', 'javascript'])
div(style="height: 1px;")
if request.schema
h5 Schema
pre: code
!= self.highlight(request.schema, null, ['json', 'yaml', 'xml'])
div(style="height: 1px;")
if showSchema && request.schema
- var schema = JSON.parse(request.schema)
table(style="width: 100%;")
thead
tr
th Attribute name
th Type
th Required
th Description
th Constraints
each description, name in schema.properties || []
tr
td #{name}
td #{description.type}
td #{schema.required && schema.required.indexOf(name) >= 0 ? 'true' : ''}
td #{description.description}
td
+Constraints(name, schema)
div.title
.collapse-button
span.close Hide
span.open Show
span Schema
div.collapse-content: .inner
pre: code
!= self.highlight(request.schema, null, ['json', 'yaml', 'xml'])
div(style="height: 1px;")
if !request.hasContent
.description.text-muted This response has no content.
div(style="height: 1px;")

mixin Examples(resourceGroup, resource, action)
each example in action.examples
each request in example.requests
+RequestResponse('Request', request, true)
+RequestResponse('Request', request, false, true)
each response in example.responses
+RequestResponse('Response', response, true)

Expand Down Expand Up @@ -190,8 +217,8 @@ mixin Content()
span.method(class=action.methodLower)= action.method
| &nbsp;
span.uri
span.hostname= self.api.host
!= action.colorizedUriTemplate
span.hostname= self.api.host
!= action.colorizedUriTemplate

//- A list of sub-sections for parameters, requests
//- and responses.
Expand Down Expand Up @@ -238,43 +265,43 @@ mixin ContentTriple()
each action in resource.actions || []
if action.examples
.right
.definition
span.method(class=action.methodLower)= action.method
| &nbsp;
span.uri
span.hostname= self.api.host
!= action.colorizedUriTemplate
.tabs
if action.hasRequest
.example-names
span Requests
- var requestCount = 0
each example in action.examples
each request in example.requests
- requestCount++
span.tab-button= request.name || 'example ' + requestCount
each example in action.examples
each request in example.requests
.tab
+RequestResponseBody(request, false, true)
.tabs
.example-names
span Responses
each response in example.responses
span.tab-button= response.name
each response in example.responses
.tab
+RequestResponseBody(response, false, true)
else
each example in action.examples
.tabs
.example-names
span Responses
each response in example.responses
span.tab-button= response.name
each response in example.responses
.definition
span.method(class=action.methodLower)= action.method
| &nbsp;
span.uri
span.hostname= self.api.host
!= action.colorizedUriTemplate
.tabs
if action.hasRequest
.example-names
span Requests
- var requestCount = 0
each example in action.examples
each request in example.requests
- requestCount++
span.tab-button= request.name || 'example ' + requestCount
each example in action.examples
each request in example.requests
.tab
+RequestResponseBody(response, false, true)
+RequestResponseBody(request, false, true)
.tabs
.example-names
span Responses
each response in example.responses
span.tab-button= response.name
each response in example.responses
.tab
+RequestResponseBody(response, false, true)
else
each example in action.examples
.tabs
.example-names
span Responses
each response in example.responses
span.tab-button= response.name
each response in example.responses
.tab
+RequestResponseBody(response, false, true)
.middle
.action(class=action.methodLower, id=action.elementId)
h4.action-heading
Expand Down
2 changes: 1 addition & 1 deletion templates/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function init() {
init();

window.onload = function () {
autoCollapse();
// autoCollapse();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this was commented out? Looks like it might be causing the issue with the collapsables that @OrangeDog mentioned.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That string just collapses the left menu on page load. Returned it too for clarity.

// Remove the `preload` class to enable animations
document.querySelector('body').className = '';
};