Skip to content

Instantly share code, notes, and snippets.

@mittsh
Last active December 8, 2020 21:35
Show Gist options
  • Save mittsh/aa5cd67e9868d9a931d69897e467b71e to your computer and use it in GitHub Desktop.
Save mittsh/aa5cd67e9868d9a931d69897e467b71e to your computer and use it in GitHub Desktop.
// importScripts("https://cdn.jsdelivr.net/npm/mustache@4.0.1/mustache.min.js");
// importScripts("https://cdn.jsdelivr.net/npm/base64-js@1.3.1/index.min.js");
importScripts(
"https://cdn.jsdelivr.net/npm/handlebars@4.7.6/dist/handlebars.min.js"
);
const outTemplate = `
[Test 2020-12-08] a mock output of {{title}} v{{version}} using Handlebars. 🍇 🍓 🥝
---
Request Name: {{name}}
Method: {{method}}
Authorization: {{auth}}
`;
class cURLCodeGenerator {
constructor() {
this.label = "cURL Generator";
this.title = "cURLGenerator";
this.identifier = "com.mycompany.cURLGenerator";
this.version = "2.0.0";
}
generate(context, requests, options) {
if (!context && !request) {
return "ContextJS and RequestJS is not available.";
}
const req = requests[0]
const template = Handlebars.compile(outTemplate)({
title: this.title,
version: this.version,
name: req.name || '',
method: req.getMethod(false) || '',
auth: req.getHeaderByName('authorization'),
});
return template;
}
}
Paw.use(new cURLCodeGenerator());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment