Skip to content

Commit

Permalink
0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeGeneva committed Oct 25, 2024
1 parent a75a302 commit 7c0fa53
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions dispense.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const IMPORT_REGEX = /\{\{\s*import (\w+\.html)\s*\}\}/g;
const IMPORT_WITH_CONTENT_REGEX =
/\{\{\s*import\s+((\w+|\-+|_+)*.html)\s*\}\}\s*((.|\s)*)\{\{\s*\/\1\s*\}\}/g;

function dispense(filepath, options, callback) {
function dispense(filepath, options) {
let content = fs.readFileSync(filepath, 'utf-8');
const dir = path.dirname(filepath);

Expand All @@ -33,7 +33,7 @@ function dispense(filepath, options, callback) {
}

const rendered = render(content, options);
return callback(null, rendered);
return rendered;
}

module.exports = { dispense };
18 changes: 6 additions & 12 deletions dispense.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
const { dispense } = require('./dispense');

let callback;

beforeEach(() => {
callback = jest.fn();
});

test('that files can be imported', () => {
dispense('./test/views/import-test.html', {}, callback);
const html = '<header><nav>Navigation</nav>\n</header>\n';
expect(callback).toHaveBeenCalledWith(null, html);
const output = dispense('./test/views/import-test.html', {});
expect(output).toEqual(html);
});

test('that imported views can container inner markup', () => {
dispense('./test/views/inner-markup.html', {}, callback);
const html = '<div><div>inner</div>\n</div>\n';
expect(callback).toHaveBeenCalledWith(null, html);
const output = dispense('./test/views/inner-markup.html', {});
expect(output).toEqual(html);
});

test('that imported views can contain imported views', () => {
dispense('./test/views/nested-import.html', {}, callback);
const html = '<div><nav>Navigation</nav>\n<div>test</div>\n</div>\n';
expect(callback).toHaveBeenCalledWith(null, html);
const output = dispense('./test/views/nested-import.html', {});
expect(output).toEqual(html);
});
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare function dispense(filepath: string, options: any): string;

export { dispense };
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "nutrimatic-html-dispenser",
"version": "0.1.0",
"version": "0.2.0",
"description": "A simple HTML template engine.",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "jest",
"test:watch": "jest --watch"
Expand Down

0 comments on commit 7c0fa53

Please sign in to comment.