Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
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'
5 changes: 5 additions & 0 deletions lib/engineFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand All @@ -19,6 +20,10 @@ class EngineFactory {
return renderHandlebars;
}

getPugEngine() {
return renderPug;
}

}

export const engineFactory = new EngineFactory();
12 changes: 12 additions & 0 deletions lib/engines/engines_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()"),
Expand Down Expand Up @@ -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 = `<p>Timothy's Pug source code!</p>`
assertEquals(actual, expect)
},
});
16 changes: 16 additions & 0 deletions lib/engines/pug.ts
Original file line number Diff line number Diff line change
@@ -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;
}
};
3 changes: 2 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
export { renderHandlebars, hbs } from "./lib/engines/handlebars.ts";
export { renderPug } from "./lib/engines/pug.ts";