Skip to content

Commit

Permalink
allow localize object as a template
Browse files Browse the repository at this point in the history
  • Loading branch information
mrin9 committed Sep 7, 2019
1 parent 84b988b commit 28b18e4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
<rapi-pdf id='rapipdf' style="width:750px; height:40px; font-size:18px"
spec-url="https://api.apis.guru/v2/specs/bitbucket.org/2.0/swagger.json"
pdf-title="New API Reference"
>
>
<template>
{"index":"Translated INDEX"}
</template>
</rapi-pdf>


<button onclick="changeSpec()">Change Spec</button>
<script type="text/javascript">
function changeSpec(){
Expand Down
48 changes: 46 additions & 2 deletions src/rapipdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,53 @@ export default customElements.define('rapi-pdf', class RapiPdf extends HTMLEleme
// Initialize attributes if not defined
shadowRoot.appendChild(elFromTemplate);
}

static get properties() {
return {
localize: { type: Object }
};
}
connectedCallback() {
// Add Event Listeners
this.inputEl.addEventListener('change', e => this.onChangeInput(e) );
this.inputEl.addEventListener('keyup', e => this.onKeyUp(e) );
this.btnEl.addEventListener('click', e => this.generatePdf(e) );
if (this.children[0]){
let localizeStr = this.children[0].content.textContent;
let localizeObj = {};
try {
localizeObj = JSON.parse(localizeStr);
}
catch(e) {
localizeObj = {};
}
this.localize = Object.assign({
'index':'INDEX',
'api':'API',
'apiList':'API List',
'apiReference':'API Reference',
'apiVersion':'API Version',
'contact':'CONTACT',
'name':'NAME',
'email':'EMAIL',
'url':'URL',
'termsOfService':'Terms of service',
'securityAndAuthentication':'Security and Authentication',
'securitySchemes':'SECURITY SCHEMES',
'type':'TYPE',
'description':'DESCRIPTION',
'request':'REQUEST',
'requestBody':'REQUEST BODY',
'response':'RESPONSE',
'responseModel':'RESPONSE MODEL',
'statusCode':'STATUS CODE',
'deprecated':'DEPRECATED',
'allowed':'allowed',
'pattern':'pattern',
'parameters':'Parameters',
'noRequestParameters': 'No request parameters',
'method':'METHOD'
}, localizeObj)
}
}

disconnectedCallback() {
Expand Down Expand Up @@ -160,6 +201,8 @@ export default customElements.define('rapi-pdf', class RapiPdf extends HTMLEleme
let includeSecurity = this.getAttribute('include-security')==='false'?false:true;
let includeApiDetails = this.getAttribute('include-api-details')==='false'?false:true;
let includeApiList = this.getAttribute('include-api-list')==='true'?true:false;

/*
let localize = {
'index':'INDEX',
'api':'API',
Expand Down Expand Up @@ -187,7 +230,8 @@ export default customElements.define('rapi-pdf', class RapiPdf extends HTMLEleme
'noRequestParameters': 'No request parameters',
'method':'METHOD'
}

*/
let localize = this.localize;
let options = {
pdfPrimaryColor,
pdfAlternateColor,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/pdf-gen-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export function getApiDef(spec, filterPath, sectionHeading, tableLayout, localiz

}
else{
requestSetDef.push({ text: 'No request parameters', style:['small', 'gray'], margin:[0, 5, 0, 0]});
requestSetDef.push({ text: localize.noRequestParameters, style:['small', 'gray'], margin:[0, 5, 0, 0]});
}

operationContent.push({
Expand Down

0 comments on commit 28b18e4

Please sign in to comment.