diff --git a/deps.ts b/deps.ts index 3550e57..95af434 100644 --- a/deps.ts +++ b/deps.ts @@ -2,4 +2,5 @@ export * from "https://deno.land/x/oak@v6.5.0/mod.ts"; export {existsSync} from 'https://deno.land/std@0.84.0/fs/exists.ts' -export * as path from 'https://deno.land/std@0.84.0/path/mod.ts' \ No newline at end of file +export * as path from 'https://deno.land/std@0.84.0/path/mod.ts' +export * as pug from 'https://raw.githubusercontent.com/lumeland/pug/v0.1.1/mod.js' \ No newline at end of file diff --git a/lib/engineFactory.ts b/lib/engineFactory.ts index 7606f41..a28bdcb 100644 --- a/lib/engineFactory.ts +++ b/lib/engineFactory.ts @@ -3,6 +3,7 @@ import type { Engine } from "./types/index.ts"; import { renderDenjuck } from "./engines/denjuck.ts"; import { renderEjs } from "./engines/ejs.ts"; import { renderHandlebars } from "./engines/handlebars.ts"; +import { renderPug } from "./engines/pug.ts"; class EngineFactory { constructor() {} @@ -19,6 +20,10 @@ class EngineFactory { return renderHandlebars; } + getPugEngine() { + return renderPug; + } + } export const engineFactory = new EngineFactory(); diff --git a/lib/engines/engines_test.ts b/lib/engines/engines_test.ts index a13db2a..9a35724 100644 --- a/lib/engines/engines_test.ts +++ b/lib/engines/engines_test.ts @@ -4,6 +4,7 @@ import { blue } from "https://deno.land/std/fmt/colors.ts"; import { renderDenjuck } from "./denjuck.ts"; import { renderEjs } from "./ejs.ts"; import { renderHandlebars } from "./handlebars.ts"; +import { renderPug } from "./pug.ts"; Deno.test({ name: blue("Testing renderDenjuck()"), @@ -58,3 +59,14 @@ Deno.test({ assertEquals(actual, expect); }, }); + +Deno.test({ + name: blue("Testing renderPug()"), + fn(): void { + const template = `p #{name}'s Pug source code!`; + + const actual = renderPug(template, { name: "Timothy" }); + const expect = `
Timothy's Pug source code!
` + assertEquals(actual, expect) + }, +}); \ No newline at end of file diff --git a/lib/engines/pug.ts b/lib/engines/pug.ts new file mode 100644 index 0000000..be0a776 --- /dev/null +++ b/lib/engines/pug.ts @@ -0,0 +1,16 @@ +import { pug } from '../../deps.ts'; +import type { Engine, ViewConfig } from "../types/index.ts"; +import * as path from "https://deno.land/std/path/mod.ts"; + +export const renderPug: Engine = ( + template: string, + data: object = {}, + config: ViewConfig = {}, + filename: string = "", +): string => { + if (config.viewRoot) { + return pug.compile(template , { filename: path.join(config.viewRoot, filename) })(data) as string; + } else { + return pug.compile(template, { filename: filename })(data) as string; + } +}; \ No newline at end of file diff --git a/mod.ts b/mod.ts index 65ff1be..f49afdd 100644 --- a/mod.ts +++ b/mod.ts @@ -7,4 +7,5 @@ export { viewEngine } from "./lib/viewEngine.ts"; export { renderDenjuck } from "./lib/engines/denjuck.ts"; export { renderEjs } from "./lib/engines/ejs.ts"; -export { renderHandlebars, hbs } from "./lib/engines/handlebars.ts"; \ No newline at end of file +export { renderHandlebars, hbs } from "./lib/engines/handlebars.ts"; +export { renderPug } from "./lib/engines/pug.ts"; \ No newline at end of file