Skip to content

Commit

Permalink
test: add test for habdlebars helpers used in comple mode
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Dec 8, 2024
1 parent d71644f commit eb941a1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<p>Hello {{#bold}}{{helloName}}{{/bold}}!</p>
{{#h1}}Header{{/h1}}
<p>{{#italic}}Hello{{/italic}} {{#bold}}{{helloName}}{{/bold}}!</p>
{{> 'footer'}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//import Handlebars from 'handlebars'; // not works!
const Handlebars = require('handlebars');

export const h1 = function (options) {
return new Handlebars.SafeString(`<h1>${options.fn(this)}</h1>`);
};

export const italic = function (options) {
return new Handlebars.SafeString(`<i>${options.fn(this)}</i>`);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');
const Handlebars = require('handlebars');
import { h1, italic } from './src/helpers-esm/html-helpers';

module.exports = {
mode: 'production',
Expand All @@ -23,12 +24,16 @@ module.exports = {

preprocessor: 'handlebars',
preprocessorOptions: {
//knownHelpersOnly: false,
// define helpers manually
// define helpers as an object
helpers: {
// WARNING: don't use the arrow function with `this` otherwise webpack compile `this` into `void 0`
//bold: (options) => new Handlebars.SafeString(`<strong>${options.fn(this)}</strong>`),

// imported helpers
h1,
italic,

// helper defined as the function
bold(options) {
return new Handlebars.SafeString(`<strong>${options.fn(this)}</strong>`);
},
Expand Down

0 comments on commit eb941a1

Please sign in to comment.