{"id":18926809,"url":"https://github.com/ladjs/gulp-pug-job","last_synced_at":"2025-06-28T13:34:02.764Z","repository":{"id":42373028,"uuid":"61334306","full_name":"ladjs/gulp-pug-job","owner":"ladjs","description":"Wrap compiled Pug templates using Gulp and pug-runtime/wrap","archived":false,"fork":false,"pushed_at":"2024-02-02T16:49:32.000Z","size":9,"stargazers_count":0,"open_issues_count":5,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-24T03:18:17.438Z","etag":null,"topics":[],"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/ladjs.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-06-17T00:22:39.000Z","updated_at":"2022-03-17T19:19:28.000Z","dependencies_parsed_at":"2024-11-15T22:51:44.040Z","dependency_job_id":"6ebdce10-b151-4c3c-8927-694f215b6d30","html_url":"https://github.com/ladjs/gulp-pug-job","commit_stats":null,"previous_names":["niftylettuce/gulp-pug-job"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ladjs/gulp-pug-job","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fgulp-pug-job","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fgulp-pug-job/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fgulp-pug-job/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fgulp-pug-job/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ladjs","download_url":"https://codeload.github.com/ladjs/gulp-pug-job/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fgulp-pug-job/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261595838,"owners_count":23182258,"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":[],"created_at":"2024-11-08T11:17:13.065Z","updated_at":"2025-06-28T13:34:02.706Z","avatar_url":"https://github.com/ladjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# gulp-pug-job\n\n\u003e Wraps Pug compiled templates using `pug-runtime/wrap` from \u003chttps://github.com/pugjs/pug-runtime\u003e and binds the template functions to a global variable, such as `window.templates`.\n\n\n## Install\n\n```bash\nnpm install gulp-pug-job\n```\n\n\n## Example Usage\n\nThis will wrap an already compiled Pug template file to a namespace on an object.\n\nLets say you have a pug template, something like (e.g. filename is `example.pug`):\n\n```pug\np Hello #{foo} welcome to #{baz}\n```\n\nAnd you want to use this on the server-side, but fast using a pre-compiled Pug template... right?\n\nSo you will need to first add the following to your `gulpfile.js` script:\n\n```js\nvar gulp = require('gulp'),\n    pug = require('gulp-pug'),\n    job = require('gulp-pug-job');\n\ngulp.task('job', function () {\n  return gulp.src(['src/templates/*.pug'])\n    .pipe(pug({ client: true, externalRuntime: true }))\n    .pipe(job({\n      // default options:\n      parent: 'window',\n      namespace: 'templates',\n      separator: '-'\n    }))\n    .pipe(gulp.dest('public/templates'));\n```\n\nThen, in your HTML file, require the script using camel casing for the filename of the template (in our case it's simply `example`, but if the file was named `foo-baz.pug` you would use `fooBaz`):\n\n```html\n\u003cscript src=\"https://raw.githubusercontent.com/pugjs/pug/1.11.0/runtime.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"/templates/example.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n  var html = window.templates.example({ foo: 'bar', baz: 'beep' });\n  console.log('html', html);\n\u003c/script\u003e\n```\n\nIn the browser console, after running the gulp script and opening your HTML file in the browser, you will see the output:\n\n```js\nhtml, \"\u003cp\u003eHello foo welcome to beep\u003c/p\u003e\"\n```\n\n\n## Background\n\nBasically it takes your compiled Pug templates such as `my-example.js`:\n\n```js\nfunction template(locals) {\n  var buf = [];\n  var pug_mixins = {};\n  var pug_interp;\n\n  buf.push(\"\u003cp\u003eHello world\u003c/p\u003e\");\n  return buf.join(\"\");\n}\n```\n\nAnd wraps it using `pug-runtime/wrap` so it appears as:\n\n```js\n(function (window) {\n  window.templates = window.templates || {};\n  window.templates.myExample = function template(locals) {\n    var buf = [];\n    var pug_mixins = {};\n    var pug_interp;\n\n    buf.push(\"\u003cp\u003eHello world\u003c/p\u003e\");\n    return buf.join(\"\");\n}})(window);\n```\n\nWhich then, when included on your HTML file, will get loaded in the global window namespace.\n\n\n## Options\n\n`gulp-pug-job` accepts an options object with the following attributes\n\n\u003e #### parent _(string)_\n\n**default:** _'window'_\n\nThe object to bind to.\n\n\u003e #### namespace _(string)_\n\n**default:** _'templates'_\n\nThe namespace to bind to\n\n\u003e #### separator _(string)_\n\n**default:** _'-'_\n\nThe filename separator. This will be used for converting filenames to camel case object references.\n\ni.e with the default settings the template file my-example.js would be accessible with:\n\n```js\nwindow.templates.myExample(locals);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fgulp-pug-job","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladjs%2Fgulp-pug-job","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fgulp-pug-job/lists"}