UNPKG

alfred-bear

Version:

Alfred Workflow to handle bear templates

27 lines (26 loc) 1.13 kB
import path from "path"; export class AlfredTemplate { constructor(template, templateDir) { const filepath = path.join(templateDir, template.file); const newWindow = template.newWindow ? "yes" : "no"; const script = template.script ? path.join(templateDir, template.script) : ""; const variables = template.var ? JSON.stringify(template.var) : '""'; const question = template.question ? template.question : ""; const subtitle = this.createSubtitle(template.newWindow, !!template.question); this.title = template.title; this.subtitle = subtitle; this.arg = `${filepath}^${script}^${newWindow}^${variables}^${question}`; } createSubtitle(newWindow, question) { const newWindowSubtitle = newWindow ? "Opens new Window" : ""; const questionSubtitle = question ? "Asks Question" : ""; if (newWindowSubtitle && questionSubtitle) { return `${newWindowSubtitle} and ${questionSubtitle}`; } else { return `${newWindowSubtitle}${questionSubtitle}`; } } }