Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexy-os/bun-hbs
Library for integrating Handlebars templates into BunJs
https://github.com/alexy-os/bun-hbs
bun bunjs handlebars handlebars-js handlebarsjs hbs
Last synced: 14 days ago
JSON representation
Library for integrating Handlebars templates into BunJs
- Host: GitHub
- URL: https://github.com/alexy-os/bun-hbs
- Owner: alexy-os
- Created: 2024-09-29T20:03:04.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-10-04T21:18:18.000Z (about 1 month ago)
- Last Synced: 2024-10-14T14:42:08.505Z (23 days ago)
- Topics: bun, bunjs, handlebars, handlebars-js, handlebarsjs, hbs
- Homepage: https://www.npmjs.com/package/bun-hbs
- Size: 295 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bun-hbs
Library for integrating Handlebars templates into BunJs.
## Installation
```bash
bun add bun-hbs
```## Usage
```typescript
import { setConfig, initHandlebars, render } from 'bun-hbs';
import { join } from 'path';// Configuring the configuration
setConfig({
VIEWS_DIR: join(__dirname, 'views'),
PARTIALS_DIR: join(__dirname, 'views/partials'),
LAYOUTS_DIR: join(__dirname, 'views/layouts'),
LOG_LEVEL: 'debug'
});// Initializing the template engine
await initHandlebars();// Rendering a template
const result = await render('home.hbs', { title: 'Home' }, 'main.hbs');
console.log(result);
```## API
- `setConfig(config: Partial)`: Sets the engine configuration.
- `initHandlebars()`: Initializes the template engine.
- `render(template: string, context?: object, layout?: string)`: Renders a template with the specified context and layout.
- `clearCache()`: Clears the template cache.
- `registerHelper(name: string, helper: Function)`: Registers a custom helper.
- `setCaching(enabled: boolean)`: Enables or disables caching.
- `setCacheTTL(ttl: number)`: Sets the cache TTL.## License
MIT