-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from jaredwray/moving-to-async-createHandlebar…
…s-function-to-do-dynamic-import moving to async createHandlebars function to do dynamic import
- Loading branch information
Showing
10 changed files
with
150 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"exclude": [ | ||
"test/**", | ||
"dist/**", | ||
"**/*.test.js", | ||
"**/*.spec.ts", | ||
"node_modules/**" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as HandlebarsLib from 'handlebars'; | ||
import helpersLib from './helpers.js'; | ||
|
||
/** | ||
* Handlebars library not initiated with helpers | ||
* @type {Handlebars} | ||
*/ | ||
export const Handlebars = HandlebarsLib; | ||
|
||
/** | ||
* Fumanchu Handlebars instance not initiated with helpers | ||
* @type {Handlebars} | ||
*/ | ||
export const handlebars = HandlebarsLib.create(); | ||
/** | ||
* Fumanchu Handlebars helpers | ||
*/ | ||
export const helpers = helpersLib; | ||
|
||
/** | ||
* Create a new Handlebars instance with Fumanchu helpers | ||
* @returns {Promise<Handlebars>} | ||
*/ | ||
export async function createHandlebars() { | ||
const handlebars = HandlebarsLib.create(); | ||
const helpersFunction = await import('./helpers.js'); | ||
helpersFunction.default({ handlebars: handlebars }); | ||
return handlebars; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
import handlebars from '../index.js'; | ||
import {createHandlebars, helpers, handlebars, Handlebars} from '../dist/index.js'; | ||
import {expect} from 'chai'; | ||
|
||
describe('testing es6 examples', function() { | ||
it('should get the handlebars from an es6 import', function() { | ||
it('should get the handlebars from an es6 import', async function() { | ||
const fumanchu = await createHandlebars(); | ||
|
||
// Use Fumanchu instead of Handlebars | ||
const source = 'Hello, {{name}}!'; | ||
const template = handlebars.compile(source); | ||
const template = fumanchu.compile(source); | ||
// Render the template with a context | ||
const result = template({ name: 'John' }); | ||
|
||
// Assert the rendered output | ||
expect(result).to.equal('Hello, John!'); | ||
|
||
//testing the export of handlebarHelpers | ||
const {handlebarHelpers} = handlebars; | ||
expect(handlebarHelpers).to.be.a('function'); | ||
expect(helpers).to.be.a('function'); | ||
|
||
//testing the export of handlebarHelpers | ||
expect(handlebars.compile).to.not.be.undefined; | ||
|
||
//test the Handlebars object | ||
expect(Handlebars.create).to.not.be.undefined; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES6", // or your preferred target version | ||
"module": "commonjs", // or your preferred module type | ||
"allowJs": true, // Enable JavaScript files in the project | ||
"checkJs": false, // Set to true if you want type-checking for JS files | ||
"outDir": "./dist", // Specify output directory | ||
"strict": true, // Enable strict type checking options | ||
"esModuleInterop": true, // Required if you are using ES modules | ||
"skipLibCheck": true, // Skipping type checks on declaration files | ||
"declaration": true // Generate corresponding .d.ts file | ||
}, | ||
"include": [ | ||
"helpers.js", | ||
"src/**/*.js", | ||
"index.ts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"test/**/*.js", // Exclude test files or other JS files you don't want to compile | ||
] | ||
} |