{"id":14982442,"url":"https://github.com/bowheart/ejs-electron","last_synced_at":"2025-07-06T17:02:44.757Z","repository":{"id":57221138,"uuid":"53078532","full_name":"bowheart/ejs-electron","owner":"bowheart","description":"A lightweight, flexible module that allows ejs templating in an electronJS app.","archived":false,"fork":false,"pushed_at":"2024-05-02T17:06:24.000Z","size":35,"stargazers_count":32,"open_issues_count":4,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-24T07:40:08.068Z","etag":null,"topics":["ejs","electron","templating"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bowheart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-03T19:50:52.000Z","updated_at":"2025-05-18T11:14:41.000Z","dependencies_parsed_at":"2024-02-06T16:25:33.336Z","dependency_job_id":"9deab358-5227-45f5-b86b-d2370797f148","html_url":"https://github.com/bowheart/ejs-electron","commit_stats":{"total_commits":30,"total_committers":7,"mean_commits":4.285714285714286,"dds":0.6,"last_synced_commit":"8eb1524db84a93bc6632231f9f0e2726db1944cb"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/bowheart/ejs-electron","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowheart%2Fejs-electron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowheart%2Fejs-electron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowheart%2Fejs-electron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowheart%2Fejs-electron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bowheart","download_url":"https://codeload.github.com/bowheart/ejs-electron/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowheart%2Fejs-electron/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259695308,"owners_count":22897514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ejs","electron","templating"],"created_at":"2024-09-24T14:05:25.282Z","updated_at":"2025-06-13T18:09:06.291Z","avatar_url":"https://github.com/bowheart.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ejs-electron\n\n[![npm](https://img.shields.io/npm/v/ejs-electron.svg)](https://www.npmjs.com/package/ejs-electron)\n[![npm](https://img.shields.io/npm/dt/ejs-electron.svg)](https://www.npmjs.com/package/ejs-electron)\n\nA mega lightweight, completely flexible module that allows ejs templating in an Electron app.\n\nMakes use of the Electron `protocol` module to supply a custom handler for the `file:` protocol.  This handler intercepts all file requests, compiles any requested `.ejs` files, and serves the result.\n\n---\n\n## Installation\n\nInstall using [npm](https://www.npmjs.com/package/ejs-electron):\n\n```\n$ npm install ejs-electron\n```\n\n---\n\n## Usage\n\n```javascript\nconst ejse = require('ejs-electron')\n```\n\n---\n\n### Method API\n\n\u003e Note: All methods, unless otherwise specified, return the `ejs-electron` api for chaining.\n\n#### ejse.data()\n\nGet/set the data (context) that will be passed to `ejs.render()`.\n\nOverloads:\n- `ejse.data('key')` -- Retrieve the value of `'key'` in the current data set.\n- `ejse.data('key', 'val')` -- Set `'key'` to `'val' `in the current data set.\n- `ejse.data({key: 'val'})` -- Replace the current data set with a new one containing `{key: 'val'}`\n\n\u003e Note: The `ejs-electron` api is injected into the scope of all rendered ejs templates. Access it via the variable `ejse`, e.g. `\u003c% ejse.stopListening() %\u003e`.\n\n#### ejse.options()\n\nGet/set the options that will be passed to `ejs.render()`. These configure the behavior of ejs itself. See the [ejs docs](http://ejs.co/#docs) for a list of possible options.\n\nOverloads:\n- `ejse.options('key')` -- Retrieve the value of `'key'` in the current options set.\n- `ejse.options('key', 'val')` -- Set `'key'` to `'val' `in the current options set.\n- `ejse.options({key: 'val'})` -- Replace the current options set with a new one containing `{key: 'val'}`\n\n\u003e Note: `ejs-electron` sets the ejs `filename` option automatically every time it renders a file. This means you can go ahead and use ejs `include` right out of the box. One less thing you need to worry about :)\n\n#### ejse.listen()\n\nStart intercepting requests on the 'file:' protocol, looking for '.ejs' files.\n\n\u003e Note: It is not necessary to call this function up-front, as `ejs-electron` starts listening as soon as it's loaded.\nUse this only to start listening again after calling `ejse.stopListening()`.\n\n#### ejse.listening()\n\nReturns true if `ejs-electron` is currently intercepting requests on the `file:` protocol.\n\n#### ejse.stopListening()\n\nStop intercepting file requests, restoring the original `file:` protocol handler.\n\n___\n\n## Examples\n\nA simple Electron app with `ejs-electron` could look like this:\n\n##### main.js\n\n```javascript\nconst {app, BrowserWindow} = require('electron')\nconst ejse = require('ejs-electron')\n\nlet mainWindow\n\nejse.data('username', 'Some Guy')\n\napp.on('ready', () =\u003e {\n    mainWindow = new BrowserWindow()\n    mainWindow.loadURL('file://' + __dirname + '/index.ejs')\n})\n```\n\nYou can, of course, chain `data()`, `options()`, and whatnot to the `require()` call:\n\n```javascript\nconst ejse = require('ejs-electron')\n\t.data('username', 'Some Guy')\n\t.options('debug', true)\n```\n\n##### index.ejs\n\n```html\n\u003ch1\u003eHello, \u003c%= username %\u003e\u003c/h1\u003e \u003c!-- Outputs: '\u003ch1\u003eHello, Some Guy\u003c/h1\u003e' --\u003e\n\u003c% ejse.stopListening() %\u003e\n```\n\nSince you have access to the `ejs-electron` api in your templates, you can also use the getter overload of `ejse.data()` to access the root-level scope of your templates. This can be useful for providing constancy in nested ejs includes:\n\n##### main.js\n```javascript\nejse.data('name', 'Holmes')\n```\n\n##### profile.ejs\n```html\n\u003cp\u003eYour name: \u003c%= name %\u003e\u003c/p\u003e\n\u003c%- include('./dog', {name: 'Sparky'}) %\u003e\n```\n\n##### dog.ejs\n```html\n\u003cp\u003eThe dog's name: \u003c%= name %\u003e\u003c/p\u003e\n\u003cp\u003eThis dog belongs to: \u003c%= ejse.data('name')\u003c/p\u003e\n```\n\nA heavily contrived example, sure, but here's its output:\n\n```html\n\u003cp\u003eYour name: Holmes\u003c/p\u003e\n\u003cp\u003eThe dog's name: Sparky\u003c/p\u003e\n\u003cp\u003eThis dog belongs to: Holmes\u003c/p\u003e\n```\n\nThis also means that stuff like the following is also a possibility, though I've never yet found a use for it:\n\n```html\n\u003cp\u003eThe current file is: \u003c%= ejse.options('filename') %\u003e\u003c/p\u003e\n```\n\n---\n\n## Issues\n\nIssues may be submitted at https://github.com/bowheart/ejs-electron/issues\n\nThanks to all who have submitted issues.  The feedback has been extremely helpful (no, seriously, you guys rock).\n\nAlso, of course, feel free to fork and pull request.  Happy coding!\n\n---\n\n## License\n\nThe [MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowheart%2Fejs-electron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbowheart%2Fejs-electron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowheart%2Fejs-electron/lists"}