├── .gitattributes ├── .github └── workflows │ └── test.yml ├── .gitignore ├── .jshintrc ├── .npmrc ├── AUTHORS ├── CHANGELOG ├── CONTRIBUTING.md ├── Gruntfile.js ├── LICENSE-MIT ├── README.md ├── docs ├── overview.md ├── pug-examples.md ├── pug-options.md └── pug-overview.md ├── package-lock.json ├── package.json ├── tasks ├── lib │ └── pug.js └── pug.js └── test ├── expected ├── amd │ ├── pug.js │ ├── pug2.js │ ├── pugInclude.js │ └── pugTemplate.js ├── jst │ ├── pug.js │ ├── pug2.js │ ├── pugInclude.js │ └── pugTemplate.js ├── pug.html ├── pug2.html ├── pugAdvancedFilters.html ├── pugCodeBlock.html ├── pugDynamicData.html ├── pugFilters.html ├── pugInclude.html ├── pugTemplate.html └── pugUsingmixin.html ├── fixtures ├── inc │ ├── advancedFilters.js │ ├── filters.js │ ├── head.pug │ └── locals.json ├── mixins.pug ├── pug.pug ├── pug2.pug ├── pugAdvancedFilters.pug ├── pugCodeBlock.pug ├── pugDynamicData.pug ├── pugFilters.pug ├── pugInclude.pug ├── pugTemplate.pug └── pugUsingmixin.pug ├── helpers.js ├── pug_amd_test.js ├── pug_jst_test.js └── pug_test.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text=auto eol=lf 3 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - "**" 7 | - "!dependabot/**" 8 | pull_request: 9 | workflow_dispatch: 10 | 11 | env: 12 | FORCE_COLOR: 2 13 | 14 | jobs: 15 | run: 16 | name: Node ${{ matrix.node }} on ${{ matrix.os }} 17 | runs-on: ${{ matrix.os }} 18 | 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | os: [ubuntu-latest, windows-latest] 23 | node: [16, 18, 20, 22] 24 | 25 | steps: 26 | - name: Clone repository 27 | uses: actions/checkout@v3 28 | with: 29 | persist-credentials: false 30 | 31 | - name: Set up Node.js 32 | uses: actions/setup-node@v3 33 | with: 34 | node-version: ${{ matrix.node }} 35 | 36 | - name: Install npm dependencies 37 | run: npm ci 38 | 39 | - name: Run tests 40 | run: npm test 41 | 42 | # We test multiple Windows shells because of prior stdout buffering issues 43 | # filed against Grunt. https://github.com/joyent/node/issues/3584 44 | - name: Run PowerShell tests 45 | run: "npm test # PowerShell" # Pass comment to PS for easier debugging 46 | shell: powershell 47 | if: startsWith(matrix.os, 'windows') 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | tmp -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "boss": true, 3 | "curly": true, 4 | "eqeqeq": true, 5 | "eqnull": true, 6 | "immed": true, 7 | "latedef": true, 8 | "newcap": true, 9 | "noarg": true, 10 | "node": true, 11 | "sub": true, 12 | "undef": true, 13 | "unused": true 14 | } 15 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | lockfile-version=2 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Eric Woroshow (http://ericw.ca/) 2 | Tyler Kellen (http://goingslowly.com/) 3 | Chris Talkington (http://christalkington.com/) 4 | Ariel Falduto (http://outa.im/) 5 | John Goodall (http://jgoodall.me/) 6 | Kyle Robinson Young (http://twitter.com/shamakry) 7 | Conrad Zimmerman (https://github.com/conradz) 8 | Andrey Mereskin (https://github.com/mereskin) -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | v3.0.1: 2 | date: 2022-04-12 3 | changes: 4 | - Update dependencies. 5 | v3.0.0: 6 | date: 2021-02-23 7 | changes: 8 | - Update to pug 3.0.0 9 | - Drop Node.js < 10 support. 10 | v2.0.0: 11 | date: 2018-09-07 12 | changes: 13 | - Drop Node.js < 6 support. 14 | - Update dependencies. 15 | v1.0.0: 16 | date: 2016-03-04 17 | changes: 18 | - Point main to task and remove peerDeps. 19 | - Update docs and tests. 20 | v0.15.0: 21 | date: 2015-07-08 22 | changes: 23 | - Update to jade 1.11.0. 24 | - Add test for Codeblocks 25 | v0.14.1: 26 | date: 2014-02-02 27 | changes: 28 | - Add filename to `processContent` arguments. 29 | v0.14.0: 30 | date: 2014-12-23 31 | changes: 32 | - Update to jade 1.8.2. 33 | v0.13.0: 34 | date: 2014-09-30 35 | changes: 36 | - Update to jade 1.7.0. 37 | v0.12.0: 38 | date: 2014-05-29 39 | changes: 40 | - Update to jade 1.3. 41 | - Make jade task fail on an error. 42 | v0.11.0: 43 | date: 2014-03-02 44 | changes: 45 | - Document `processContent`. 46 | - Bump to jade 1.2. 47 | - Update copyright to 2014. 48 | - Remove lodash-node module. 49 | v0.10.0: 50 | date: 2014-01-20 51 | changes: 52 | - Bump jade version to ~1.1.5. 53 | - Fix AUTHORS. 54 | v0.9.1: 55 | date: 2014-01-04 56 | changes: 57 | - Bump jade version to 1.0.2. 58 | - Use node-lodash instead of `grunt.util._`. 59 | v0.9.0: 60 | date: 2013-12-24 61 | changes: 62 | - Bump jade version to 1.0.0. 63 | v0.8.0: 64 | date: 2013-07-29 65 | changes: 66 | - Bump jade version to 0.34.1. 67 | v0.7.0: 68 | date: 2013-06-06 69 | changes: 70 | - Bump jade version / fix tests. 71 | v0.6.0: 72 | date: 2013-05-15 73 | changes: 74 | - Bump jade version / fix tests. 75 | v0.5.1: 76 | date: 2013-05-06 77 | changes: 78 | - Allow `options.data` to be a function. 79 | v0.5.0: 80 | date: 2013-03-07 81 | changes: 82 | - Allow compilation to JS functions. 83 | - Support JST and AMD formats. 84 | v0.4.0: 85 | date: 2013-02-15 86 | changes: 87 | - First official release for Grunt 0.4.0. 88 | v0.4.0rc7: 89 | date: 2013-01-24 90 | changes: 91 | - Updating grunt/gruntplugin dependencies to rc7. 92 | - Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions. 93 | v0.4.0rc5: 94 | date: 2013-01-09 95 | changes: 96 | - Updating to work with grunt v0.4.0rc5. 97 | - Switching to `this.files` API. 98 | v0.3.1: 99 | date: 2012-10-12 100 | changes: 101 | - Rename grunt-contrib-lib dep to grunt-lib-contrib. 102 | v0.3.0: 103 | date: 2012-09-24 104 | changes: 105 | - Options no longer accepted from global config key. 106 | v0.2.0: 107 | date: 2012-09-10 108 | changes: 109 | - Refactored from grunt-contrib into individual repo. 110 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Please see the [Contributing to grunt](https://gruntjs.com/contributing) guide for information on contributing to this project. 2 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * grunt-contrib-pug 3 | * https://gruntjs.com/ 4 | * 5 | * Copyright (c) 2016 Eric Woroshow, contributors 6 | * Licensed under the MIT license. 7 | */ 8 | 9 | 'use strict'; 10 | 11 | module.exports = function(grunt) { 12 | 13 | // Project configuration. 14 | grunt.initConfig({ 15 | jshint: { 16 | all: [ 17 | 'Gruntfile.js', 18 | 'tasks/**/*.js', 19 | '<%= nodeunit.tests %>' 20 | ], 21 | options: { 22 | jshintrc: '.jshintrc' 23 | } 24 | }, 25 | 26 | // Before generating any new files, remove any previously-created files. 27 | clean: { 28 | test: ['tmp'] 29 | }, 30 | 31 | // Configuration to be run (and then tested). 32 | pug: { 33 | compile: { 34 | files: { 35 | 'tmp/pug.html': ['test/fixtures/pug.pug'], 36 | 'tmp/pug2.html': ['test/fixtures/pug2.pug'], 37 | 'tmp/pugInclude.html': ['test/fixtures/pugInclude.pug'], 38 | 'tmp/pugTemplate.html': ['test/fixtures/pugTemplate.pug'], 39 | 'tmp/pugUsingmixin.html': ['test/fixtures/pugUsingmixin.pug'], 40 | 'tmp/pugCodeBlock.html': ['test/fixtures/pugCodeBlock.pug'] 41 | }, 42 | options: { 43 | data: { 44 | test: true, 45 | year: '<%= grunt.template.today("yyyy") %>' 46 | } 47 | } 48 | }, 49 | 50 | compile_amd: { 51 | files: { 52 | 'tmp/amd/pug.js': ['test/fixtures/pug.pug'], 53 | 'tmp/amd/pug2.js': ['test/fixtures/pug2.pug'], 54 | 'tmp/amd/pugInclude.js': ['test/fixtures/pugInclude.pug'], 55 | 'tmp/amd/pugTemplate.js': ['test/fixtures/pugTemplate.pug'] 56 | }, 57 | options: { 58 | client: true, 59 | amd: true, 60 | namespace: false, 61 | compileDebug: false, 62 | data: { 63 | test: true, 64 | year: '<%= grunt.template.today("yyyy") %>' 65 | } 66 | } 67 | }, 68 | 69 | compile_jst: { 70 | files: { 71 | 'tmp/jst/pug.js': ['test/fixtures/pug.pug'], 72 | 'tmp/jst/pug2.js': ['test/fixtures/pug2.pug'], 73 | 'tmp/jst/pugInclude.js': ['test/fixtures/pugInclude.pug'], 74 | 'tmp/jst/pugTemplate.js': ['test/fixtures/pugTemplate.pug'] 75 | }, 76 | options: { 77 | client: true, 78 | compileDebug: false, 79 | processName: function(str) { 80 | return str.match(/^test\/fixtures\/(.*)\.pug$/)[1]; 81 | }, 82 | data: { 83 | test: true, 84 | year: '<%= grunt.template.today("yyyy") %>' 85 | } 86 | } 87 | }, 88 | compile_dynamic_data: { 89 | files: { 90 | 'tmp/pugDynamicData.html': ['test/fixtures/pugDynamicData.pug'] 91 | }, 92 | options: { 93 | compileDebug: false, 94 | data: function(dest, src) { 95 | return { 96 | dest: dest, 97 | src: src 98 | }; 99 | } 100 | } 101 | }, 102 | compile_inline_filters: { 103 | files: { 104 | 'tmp/inlineFilters.html': ['test/fixtures/pugFilters.pug'] 105 | }, 106 | options: { 107 | filters: { 108 | some: function(block) { 109 | return 'some: ' + block; 110 | }, 111 | another: function(block) { 112 | return 'another: ' + block; 113 | } 114 | }, 115 | data: function(dest, src) { 116 | return { 117 | dest: dest, 118 | src: src 119 | }; 120 | } 121 | } 122 | }, 123 | compile_exported_filters: { 124 | files: { 125 | 'tmp/exportedFilters.html': ['test/fixtures/pugFilters.pug'] 126 | }, 127 | options: { 128 | filters: require('./test/fixtures/inc/filters.js'), 129 | data: function(dest, src) { 130 | return { 131 | dest: dest, 132 | src: src 133 | }; 134 | } 135 | } 136 | }, 137 | compile_advanced_filters: { 138 | files: { 139 | 'tmp/pugAdvancedFilters.html': ['test/fixtures/pugAdvancedFilters.pug'] 140 | }, 141 | options: { 142 | filters: require('./test/fixtures/inc/advancedFilters.js'), 143 | data: function() { 144 | return require('./test/fixtures/inc/locals.json'); 145 | } 146 | } 147 | } 148 | }, 149 | 150 | // Unit tests. 151 | nodeunit: { 152 | tests: ['test/*_test.js'] 153 | } 154 | }); 155 | 156 | // Actually load this plugin's task(s). 157 | grunt.loadTasks('tasks'); 158 | 159 | // These plugins provide necessary tasks. 160 | grunt.loadNpmTasks('grunt-contrib-clean'); 161 | grunt.loadNpmTasks('grunt-contrib-jshint'); 162 | grunt.loadNpmTasks('grunt-contrib-nodeunit'); 163 | grunt.loadNpmTasks('grunt-contrib-internal'); 164 | 165 | // Whenever the "test" task is run, first clean the "tmp" dir, then run this 166 | // plugin's task(s), then test the result. 167 | grunt.registerTask('test', ['jshint', 'clean', 'pug', 'nodeunit']); 168 | 169 | // By default, lint and run all tests. 170 | grunt.registerTask('default', ['test', 'build-contrib']); 171 | 172 | }; 173 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Eric Woroshow, contributors 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # grunt-contrib-pug v3.0.0 [![Build Status](https://github.com/gruntjs/grunt-contrib-pug/workflows/Tests/badge.svg)](https://github.com/gruntjs/grunt-contrib-pug/actions?workflow=Tests) 2 | 3 | > Compile Pug templates 4 | 5 | 6 | 7 | ## Getting Started 8 | 9 | If you haven't used [Grunt](https://gruntjs.com/) before, be sure to check out the [Getting Started](https://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](https://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: 10 | 11 | ```shell 12 | npm install grunt-contrib-pug --save-dev 13 | ``` 14 | 15 | Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: 16 | 17 | ```js 18 | grunt.loadNpmTasks('grunt-contrib-pug'); 19 | ``` 20 | 21 | 22 | 23 | 24 | ## Pug task 25 | _Run this task with the `grunt pug` command._ 26 | 27 | Task targets, files and options may be specified according to the grunt [Configuring tasks](https://gruntjs.com/configuring-tasks) guide. 28 | ### Options 29 | 30 | #### pretty 31 | Type: `Boolean` 32 | Default: `false` 33 | 34 | Output indented HTML. 35 | 36 | #### data 37 | Type: `Object` 38 | 39 | Sets the data passed to Pug during template compilation. Any data can be passed to the template (including grunt templates). 40 | 41 | This value also might be a function taking source and destination path as arguments and returning a data object. Within the function, `this` is bound to the file configuration object. 42 | 43 | ```js 44 | options: { 45 | data: function(dest, src) { 46 | return { 47 | from: src, 48 | to: dest 49 | }; 50 | } 51 | } 52 | ``` 53 | 54 | or you can have options from a required JSON file: 55 | 56 | ```js 57 | options: { 58 | data: function(dest, src) { 59 | // Return an object of data to pass to templates 60 | return require('./locals.json'); 61 | } 62 | } 63 | ``` 64 | 65 | #### filters 66 | Type: `Object` 67 | 68 | If you want to use filters you have two ways to do it. First you can write your filters inline within your Gruntfile.js or define filters in separate file and export it. 69 | 70 | Filters are given a context with the `pug` instance and local variables: `{pug: pug, data: data}`, where `pug` is global pug instance and `data` is options passed to `options.data`. You can use `this.pug.render()` inside your filters to render the content of a block and locals as `#{variable}` from your data. 71 | 72 | ##### Inline filters 73 | 74 | *Gruntfile.js:* 75 | ```js 76 | options: { 77 | filters: { 78 | some: function(block) {}, 79 | another: function(block) {} 80 | } 81 | } 82 | ``` 83 | 84 | ##### Exported filters 85 | 86 | *Gruntfile.js:* 87 | ```js 88 | options: { 89 | filters: require('./filters.js') 90 | } 91 | ``` 92 | 93 | *filters.js:* 94 | ```js 95 | var pugfilters = module.exports = {}; 96 | pugfilters.some = function(block) {}; 97 | pugfilters.another = function(block) {}; 98 | ``` 99 | 100 | #### compileDebug 101 | Type: `Boolean` 102 | Default: `true` 103 | 104 | Add Pug debug instructions to generated JS templates. 105 | 106 | #### client 107 | Type: `Boolean` 108 | Default: `false` 109 | 110 | Compile to JS template functions for client-side use rather than directly to HTML. 111 | 112 | Make sure to also include the Pug runtime (only `runtime.js`) as described in the [Pug documentation](https://github.com/visionmedia/pug#browser-support). 113 | 114 | #### namespace 115 | Type: `String`, `Boolean` 116 | Default: `'JST'` 117 | 118 | The namespace in which the precompiled templates will be assigned. Use dot notation (*e.g.* `App.Templates`) for nested namespaces or `false` for no namespace wrapping. 119 | 120 | When set to `false` with **amd** option set to `true`, the templates will be returned directly from the AMD wrapper. 121 | 122 | 123 | #### amd 124 | Type: `Boolean` 125 | Default: `false` 126 | 127 | Wraps the output file with an AMD define function and returns the compiled template namespace unless namespace has been explicitly set to false in which case the template function will be returned directly. 128 | 129 | ```js 130 | define(function() { 131 | //...// 132 | returns this['[template namespace]']; 133 | }); 134 | ``` 135 | 136 | #### processName 137 | Type: `Function` 138 | 139 | This option accepts a function which takes one argument (the template filepath) and returns a string which will be used as the key for the precompiled template object. 140 | 141 | **Example** 142 | Store all template on the default JST namespace in capital letters. 143 | 144 | ```js 145 | options: { 146 | processName: function(filename) { 147 | return filename.toUpperCase(); 148 | } 149 | } 150 | ``` 151 | 152 | #### processContent 153 | Type: `Function` 154 | Default: `function(content, filename) { return content; };` 155 | 156 | This option accepts a function that lets you perform additional content processing. 157 | 158 | ### Usage Examples 159 | 160 | ```js 161 | pug: { 162 | compile: { 163 | options: { 164 | data: { 165 | debug: false 166 | } 167 | }, 168 | files: { 169 | 'path/to/dest.html': ['path/to/templates/*.pug', 'another/path/tmpl.pug'] 170 | } 171 | } 172 | } 173 | ``` 174 | 175 | If you want to generate a debug file and a release file from the same template: 176 | 177 | ```js 178 | pug: { 179 | debug: { 180 | options: { 181 | data: { 182 | debug: true 183 | } 184 | }, 185 | files: { 186 | 'debug.html': 'test.pug' 187 | } 188 | }, 189 | release: { 190 | options: { 191 | data: { 192 | debug: false 193 | } 194 | }, 195 | files: { 196 | 'release.html': 'test.pug' 197 | } 198 | } 199 | } 200 | ``` 201 | 202 | If you want to use `grunt` template in `options.data`: 203 | 204 | ```js 205 | pug: { 206 | debug: { 207 | options: { 208 | data: { 209 | debug: true, 210 | timestamp: '<%= new Date().getTime() %>' 211 | } 212 | }, 213 | files: { 214 | 'debug.html': 'test.pug' 215 | } 216 | } 217 | } 218 | ``` 219 | 220 | or you can use `grunt` helpers (grunt object was exposed at template context): 221 | 222 | ```js 223 | pug: { 224 | debug: { 225 | options: { 226 | data: { 227 | debug: true, 228 | timestamp: '<%= grunt.template.today() %>' 229 | } 230 | }, 231 | files: { 232 | 'debug.html': 'test.pug' 233 | } 234 | } 235 | } 236 | ``` 237 | 238 | 239 | ## Release History 240 | 241 | * 2022-04-12   v3.0.1   Update dependencies. 242 | * 2021-02-23   v3.0.0   Update to pug 3.0.0 Drop Node.js < 10 support. 243 | * 2018-09-07   v2.0.0   Drop Node.js < 6 support. Update dependencies. 244 | * 2016-03-04   v1.0.0   Point main to task and remove peerDeps. Update docs and tests. 245 | * 2015-07-08   v0.15.0   Update to jade 1.11.0. Add test for Codeblocks 246 | * 2014-02-02   v0.14.1   Add filename to `processContent` arguments. 247 | * 2014-12-23   v0.14.0   Update to jade 1.8.2. 248 | * 2014-09-30   v0.13.0   Update to jade 1.7.0. 249 | * 2014-05-29   v0.12.0   Update to jade 1.3. Make jade task fail on an error. 250 | * 2014-03-02   v0.11.0   Document `processContent`. Bump to jade 1.2. Update copyright to 2014. Remove lodash-node module. 251 | * 2014-01-20   v0.10.0   Bump jade version to ~1.1.5. Fix AUTHORS. 252 | * 2014-01-04   v0.9.1   Bump jade version to 1.0.2. Use node-lodash instead of `grunt.util._`. 253 | * 2013-12-24   v0.9.0   Bump jade version to 1.0.0. 254 | * 2013-07-29   v0.8.0   Bump jade version to 0.34.1. 255 | * 2013-06-06   v0.7.0   Bump jade version / fix tests. 256 | * 2013-05-15   v0.6.0   Bump jade version / fix tests. 257 | * 2013-05-06   v0.5.1   Allow `options.data` to be a function. 258 | * 2013-03-07   v0.5.0   Allow compilation to JS functions. Support JST and AMD formats. 259 | * 2013-02-15   v0.4.0   First official release for Grunt 0.4.0. 260 | * 2013-01-24   v0.4.0rc7   Updating grunt/gruntplugin dependencies to rc7. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions. 261 | * 2013-01-09   v0.4.0rc5   Updating to work with grunt v0.4.0rc5. Switching to `this.files` API. 262 | * 2012-10-12   v0.3.1   Rename grunt-contrib-lib dep to grunt-lib-contrib. 263 | * 2012-09-24   v0.3.0   Options no longer accepted from global config key. 264 | * 2012-09-10   v0.2.0   Refactored from grunt-contrib into individual repo. 265 | 266 | --- 267 | 268 | Task submitted by [Eric Woroshow](http://ericw.ca/) 269 | 270 | *This is a generated file.* 271 | -------------------------------------------------------------------------------- /docs/overview.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntjs/grunt-contrib-pug/d99773197d6f6e3ed819565e29c2e45aeaac7daa/docs/overview.md -------------------------------------------------------------------------------- /docs/pug-examples.md: -------------------------------------------------------------------------------- 1 | # Usage Examples 2 | 3 | ```js 4 | pug: { 5 | compile: { 6 | options: { 7 | data: { 8 | debug: false 9 | } 10 | }, 11 | files: { 12 | 'path/to/dest.html': ['path/to/templates/*.pug', 'another/path/tmpl.pug'] 13 | } 14 | } 15 | } 16 | ``` 17 | 18 | If you want to generate a debug file and a release file from the same template: 19 | 20 | ```js 21 | pug: { 22 | debug: { 23 | options: { 24 | data: { 25 | debug: true 26 | } 27 | }, 28 | files: { 29 | 'debug.html': 'test.pug' 30 | } 31 | }, 32 | release: { 33 | options: { 34 | data: { 35 | debug: false 36 | } 37 | }, 38 | files: { 39 | 'release.html': 'test.pug' 40 | } 41 | } 42 | } 43 | ``` 44 | 45 | If you want to use `grunt` template in `options.data`: 46 | 47 | ```js 48 | pug: { 49 | debug: { 50 | options: { 51 | data: { 52 | debug: true, 53 | timestamp: '<%= new Date().getTime() %>' 54 | } 55 | }, 56 | files: { 57 | 'debug.html': 'test.pug' 58 | } 59 | } 60 | } 61 | ``` 62 | 63 | or you can use `grunt` helpers (grunt object was exposed at template context): 64 | 65 | ```js 66 | pug: { 67 | debug: { 68 | options: { 69 | data: { 70 | debug: true, 71 | timestamp: '<%= grunt.template.today() %>' 72 | } 73 | }, 74 | files: { 75 | 'debug.html': 'test.pug' 76 | } 77 | } 78 | } 79 | ``` 80 | -------------------------------------------------------------------------------- /docs/pug-options.md: -------------------------------------------------------------------------------- 1 | # Options 2 | 3 | ## pretty 4 | Type: `Boolean` 5 | Default: `false` 6 | 7 | Output indented HTML. 8 | 9 | ## data 10 | Type: `Object` 11 | 12 | Sets the data passed to Pug during template compilation. Any data can be passed to the template (including grunt templates). 13 | 14 | This value also might be a function taking source and destination path as arguments and returning a data object. Within the function, `this` is bound to the file configuration object. 15 | 16 | ```js 17 | options: { 18 | data: function(dest, src) { 19 | return { 20 | from: src, 21 | to: dest 22 | }; 23 | } 24 | } 25 | ``` 26 | 27 | or you can have options from a required JSON file: 28 | 29 | ```js 30 | options: { 31 | data: function(dest, src) { 32 | // Return an object of data to pass to templates 33 | return require('./locals.json'); 34 | } 35 | } 36 | ``` 37 | 38 | ## filters 39 | Type: `Object` 40 | 41 | If you want to use filters you have two ways to do it. First you can write your filters inline within your Gruntfile.js or define filters in separate file and export it. 42 | 43 | Filters are given a context with the `pug` instance and local variables: `{pug: pug, data: data}`, where `pug` is global pug instance and `data` is options passed to `options.data`. You can use `this.pug.render()` inside your filters to render the content of a block and locals as `#{variable}` from your data. 44 | 45 | ### Inline filters 46 | 47 | *Gruntfile.js:* 48 | ```js 49 | options: { 50 | filters: { 51 | some: function(block) {}, 52 | another: function(block) {} 53 | } 54 | } 55 | ``` 56 | 57 | ### Exported filters 58 | 59 | *Gruntfile.js:* 60 | ```js 61 | options: { 62 | filters: require('./filters.js') 63 | } 64 | ``` 65 | 66 | *filters.js:* 67 | ```js 68 | var pugfilters = module.exports = {}; 69 | pugfilters.some = function(block) {}; 70 | pugfilters.another = function(block) {}; 71 | ``` 72 | 73 | ## compileDebug 74 | Type: `Boolean` 75 | Default: `true` 76 | 77 | Add Pug debug instructions to generated JS templates. 78 | 79 | ## client 80 | Type: `Boolean` 81 | Default: `false` 82 | 83 | Compile to JS template functions for client-side use rather than directly to HTML. 84 | 85 | Make sure to also include the Pug runtime (only `runtime.js`) as described in the [Pug documentation](https://github.com/visionmedia/pug#browser-support). 86 | 87 | ## namespace 88 | Type: `String`, `Boolean` 89 | Default: `'JST'` 90 | 91 | The namespace in which the precompiled templates will be assigned. Use dot notation (*e.g.* `App.Templates`) for nested namespaces or `false` for no namespace wrapping. 92 | 93 | When set to `false` with **amd** option set to `true`, the templates will be returned directly from the AMD wrapper. 94 | 95 | 96 | ## amd 97 | Type: `Boolean` 98 | Default: `false` 99 | 100 | Wraps the output file with an AMD define function and returns the compiled template namespace unless namespace has been explicitly set to false in which case the template function will be returned directly. 101 | 102 | ```js 103 | define(function() { 104 | //...// 105 | returns this['[template namespace]']; 106 | }); 107 | ``` 108 | 109 | ## processName 110 | Type: `Function` 111 | 112 | This option accepts a function which takes one argument (the template filepath) and returns a string which will be used as the key for the precompiled template object. 113 | 114 | **Example** 115 | Store all template on the default JST namespace in capital letters. 116 | 117 | ```js 118 | options: { 119 | processName: function(filename) { 120 | return filename.toUpperCase(); 121 | } 122 | } 123 | ``` 124 | 125 | ## processContent 126 | Type: `Function` 127 | Default: `function(content, filename) { return content; };` 128 | 129 | This option accepts a function that lets you perform additional content processing. 130 | -------------------------------------------------------------------------------- /docs/pug-overview.md: -------------------------------------------------------------------------------- 1 | Task targets, files and options may be specified according to the grunt [Configuring tasks](https://gruntjs.com/configuring-tasks) guide. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grunt-contrib-pug", 3 | "description": "Compile Pug templates", 4 | "version": "3.0.0", 5 | "author": { 6 | "name": "Grunt Team", 7 | "url": "https://gruntjs.com/" 8 | }, 9 | "repository": "gruntjs/grunt-contrib-pug", 10 | "license": "MIT", 11 | "engines": { 12 | "node": ">=16" 13 | }, 14 | "main": "tasks/pug.js", 15 | "scripts": { 16 | "test": "grunt test --verbose" 17 | }, 18 | "dependencies": { 19 | "chalk": "^2.4.2", 20 | "pug": "^3.0.3" 21 | }, 22 | "devDependencies": { 23 | "grunt": "^1.6.1", 24 | "grunt-contrib-clean": "^2.0.1", 25 | "grunt-contrib-internal": "^9.0.0", 26 | "grunt-contrib-jshint": "^3.2.0", 27 | "grunt-contrib-nodeunit": "^5.0.0" 28 | }, 29 | "keywords": [ 30 | "gruntplugin" 31 | ], 32 | "files": [ 33 | "tasks" 34 | ], 35 | "appveyor_id": "aso1brjxx79khb41" 36 | } 37 | -------------------------------------------------------------------------------- /tasks/lib/pug.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.getNamespaceDeclaration = function(ns) { 4 | var output = []; 5 | var curPath = 'this'; 6 | if (ns !== 'this') { 7 | var nsParts = ns.split('.'); 8 | nsParts.forEach(function(curPart) { 9 | if (curPart !== 'this') { 10 | curPath += '[' + JSON.stringify(curPart) + ']'; 11 | output.push(curPath + ' = ' + curPath + ' || {};'); 12 | } 13 | }); 14 | } 15 | 16 | return { 17 | namespace: curPath, 18 | declaration: output.join('\n') 19 | }; 20 | }; 21 | -------------------------------------------------------------------------------- /tasks/pug.js: -------------------------------------------------------------------------------- 1 | /* 2 | * grunt-contrib-pug 3 | * https://gruntjs.com/ 4 | * 5 | * Copyright (c) 2016 Eric Woroshow, contributors 6 | * Licensed under the MIT license. 7 | */ 8 | 9 | 'use strict'; 10 | 11 | module.exports = function(grunt) { 12 | var lib = require('./lib/pug'); 13 | var chalk = require('chalk'); 14 | 15 | // content conversion for templates 16 | var defaultProcessContent = function(content) { 17 | return content; 18 | }; 19 | 20 | // filename conversion for templates 21 | var defaultProcessName = function(name) { 22 | return name.replace('.pug', ''); 23 | }; 24 | 25 | grunt.registerMultiTask('pug', 'Compile pug templates.', function() { 26 | var options = this.options({ 27 | namespace: 'JST', 28 | separator: grunt.util.linefeed + grunt.util.linefeed, 29 | amd: false 30 | }); 31 | 32 | var data = options.data; 33 | delete options.data; 34 | 35 | var nsInfo; 36 | 37 | if (options.namespace !== false) { 38 | nsInfo = lib.getNamespaceDeclaration(options.namespace); 39 | } 40 | 41 | // assign transformation functions 42 | var processContent = options.processContent || defaultProcessContent; 43 | var processName = options.processName || defaultProcessName; 44 | 45 | this.files.forEach(function(f) { 46 | var templates = []; 47 | 48 | f.src.filter(function(filepath) { 49 | // warn on and remove invalid source files (if nonull was set) 50 | if (!grunt.file.exists(filepath)) { 51 | grunt.log.warn('Source file "' + filepath + '" not found.'); 52 | return false; 53 | } 54 | return true; 55 | }) 56 | .forEach(function(filepath) { 57 | var src = processContent(grunt.file.read(filepath), filepath); 58 | var compiled, filename; 59 | filename = processName(filepath); 60 | 61 | options.filename = filepath; 62 | 63 | try { 64 | var pug = f.orig.pug = require('pug'); 65 | if (typeof data === 'function') { 66 | // if data is function, bind to f.orig, passing f.dest and f.src 67 | f.orig.data = data.call(f.orig, f.dest, f.src); 68 | } else { 69 | // Defaults data to an empty object {} 70 | f.orig.data = data || {}; 71 | } 72 | if (options.filters) { 73 | if (!f.orig.data.filters) { 74 | f.orig.data.filters = {}; 75 | } 76 | Object.keys(options.filters).forEach(function(filter) { 77 | f.orig.data.filters[filter] = options.filters[filter].bind(f.orig); 78 | options.filters[filter] = options.filters[filter].bind(f.orig); 79 | }); 80 | } 81 | // if in client mode, return function source 82 | if (options.client) { 83 | compiled = pug.compileClient(src, options).toString(); 84 | } else { 85 | compiled = pug.compile(src, options)(f.orig.data); 86 | } 87 | 88 | // if configured for AMD and the namespace has been explicitly set 89 | // to false, the Pug template will be directly returned 90 | if (options.client && options.amd && options.namespace === false) { 91 | compiled = 'return ' + compiled; 92 | } 93 | } catch (e) { 94 | grunt.log.error(e); 95 | grunt.fail.warn('Pug failed to compile "' + filepath + '".'); 96 | return false; 97 | } 98 | 99 | if (options.client && options.namespace !== false) { 100 | templates.push(nsInfo.namespace + '[' + JSON.stringify(filename) + '] = ' + compiled + ';'); 101 | } else { 102 | templates.push(compiled); 103 | } 104 | }); 105 | 106 | var output = templates; 107 | if (output.length < 1) { 108 | grunt.log.warn('Destination not written because compiled files were empty.'); 109 | } else { 110 | if (options.client && options.namespace !== false) { 111 | output.unshift(nsInfo.declaration); 112 | 113 | if (options.node) { 114 | output.unshift('var pug = pug || require(\'pug/lib/runtime\');'); 115 | 116 | var nodeExport = 'if (typeof exports === \'object\' && exports) {'; 117 | nodeExport += 'module.exports = ' + nsInfo.namespace + ';}'; 118 | 119 | output.push(nodeExport); 120 | } 121 | } 122 | 123 | if (options.amd) { 124 | // wrap the file in an AMD define function 125 | output.unshift('define([\'pug\'], function(pug) { if(pug && pug[\'runtime\'] !== undefined) { pug = pug.runtime; }'); 126 | if (options.namespace !== false) { 127 | // namespace has not been explicitly set to false; 128 | // the AMD wrapper will return the object containing the template 129 | output.push('return ' + nsInfo.namespace + ';'); 130 | } 131 | output.push('});'); 132 | } 133 | 134 | grunt.file.write(f.dest, output.join(grunt.util.normalizelf(options.separator))); 135 | grunt.verbose.writeln('File ' + chalk.cyan(f.dest) + ' created.'); 136 | } 137 | }); 138 | 139 | grunt.log.ok(this.files.length + ' ' + grunt.util.pluralize(this.files.length, 'file/files') + ' created.'); 140 | 141 | }); 142 | 143 | }; 144 | -------------------------------------------------------------------------------- /test/expected/amd/pug.js: -------------------------------------------------------------------------------- 1 | define(['pug'], function(pug) { if(pug && pug['runtime'] !== undefined) { pug = pug.runtime; } 2 | 3 | return function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;; 4 | var locals_for_with = (locals || {}); 5 | 6 | (function (test) { 7 | pug_html = pug_html + "\u003Cdiv class=\"test\" id=\"test\"\u003E\u003Cspan id=\"data\"\u003Edata\u003C\u002Fspan\u003E"; 8 | if (test) { 9 | pug_html = pug_html + "\u003Cdiv\u003Etesting\u003C\u002Fdiv\u003E"; 10 | } 11 | pug_html = pug_html + "\u003C\u002Fdiv\u003E"; 12 | }.call(this, "test" in locals_for_with ? 13 | locals_for_with.test : 14 | typeof test !== 'undefined' ? test : undefined)); 15 | ;;return pug_html;} 16 | 17 | }); -------------------------------------------------------------------------------- /test/expected/amd/pug2.js: -------------------------------------------------------------------------------- 1 | define(['pug'], function(pug) { if(pug && pug['runtime'] !== undefined) { pug = pug.runtime; } 2 | 3 | return function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;; 4 | var locals_for_with = (locals || {}); 5 | 6 | (function (test) { 7 | pug_html = pug_html + "\u003Cdiv class=\"test\" id=\"test\"\u003E\u003Cspan id=\"data\"\u003Edata\u003C\u002Fspan\u003E"; 8 | if (test) { 9 | pug_html = pug_html + "\u003Cdiv\u003Etesting 2\u003C\u002Fdiv\u003E"; 10 | } 11 | pug_html = pug_html + "\u003C\u002Fdiv\u003E"; 12 | }.call(this, "test" in locals_for_with ? 13 | locals_for_with.test : 14 | typeof test !== 'undefined' ? test : undefined)); 15 | ;;return pug_html;} 16 | 17 | }); -------------------------------------------------------------------------------- /test/expected/amd/pugInclude.js: -------------------------------------------------------------------------------- 1 | define(['pug'], function(pug) { if(pug && pug['runtime'] !== undefined) { pug = pug.runtime; } 2 | 3 | return function pug_escape(e){var a=""+e,t=pug_match_html.exec(a);if(!t)return e;var r,c,n,s="";for(r=t.index,c=0;r]/;function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;; 5 | var locals_for_with = (locals || {}); 6 | 7 | (function (a) { 8 | pug_html = pug_html + "\u003Chtml\u003E\u003Chead\u003E\u003Ctitle\u003ETEST\u003C\u002Ftitle\u003E\u003C\u002Fhead\u003E\u003Cbody\u003E\u003C\u002Fbody\u003E\u003C\u002Fhtml\u003E"; 9 | var a = 'hello pug test' 10 | pug_html = pug_html + "\u003Cp\u003E" + (pug_escape(null == (pug_interp = a) ? "" : pug_interp)) + "\u003C\u002Fp\u003E"; 11 | }.call(this, "a" in locals_for_with ? 12 | locals_for_with.a : 13 | typeof a !== 'undefined' ? a : undefined)); 14 | ;;return pug_html;} 15 | 16 | }); -------------------------------------------------------------------------------- /test/expected/amd/pugTemplate.js: -------------------------------------------------------------------------------- 1 | define(['pug'], function(pug) { if(pug && pug['runtime'] !== undefined) { pug = pug.runtime; } 2 | 3 | return function pug_escape(e){var a=""+e,t=pug_match_html.exec(a);if(!t)return e;var r,c,n,s="";for(r=t.index,c=0;r]/;function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;; 5 | var locals_for_with = (locals || {}); 6 | 7 | (function (year) { 8 | pug_html = pug_html + "\u003Cdiv\u003E" + (pug_escape(null == (pug_interp = year) ? "" : pug_interp)) + "\u003C\u002Fdiv\u003E"; 9 | }.call(this, "year" in locals_for_with ? 10 | locals_for_with.year : 11 | typeof year !== 'undefined' ? year : undefined)); 12 | ;;return pug_html;} 13 | 14 | }); -------------------------------------------------------------------------------- /test/expected/jst/pug.js: -------------------------------------------------------------------------------- 1 | this["JST"] = this["JST"] || {}; 2 | 3 | this["JST"]["pug"] = function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;; 4 | var locals_for_with = (locals || {}); 5 | 6 | (function (test) { 7 | pug_html = pug_html + "\u003Cdiv class=\"test\" id=\"test\"\u003E\u003Cspan id=\"data\"\u003Edata\u003C\u002Fspan\u003E"; 8 | if (test) { 9 | pug_html = pug_html + "\u003Cdiv\u003Etesting\u003C\u002Fdiv\u003E"; 10 | } 11 | pug_html = pug_html + "\u003C\u002Fdiv\u003E"; 12 | }.call(this, "test" in locals_for_with ? 13 | locals_for_with.test : 14 | typeof test !== 'undefined' ? test : undefined)); 15 | ;;return pug_html;}; -------------------------------------------------------------------------------- /test/expected/jst/pug2.js: -------------------------------------------------------------------------------- 1 | this["JST"] = this["JST"] || {}; 2 | 3 | this["JST"]["pug2"] = function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;; 4 | var locals_for_with = (locals || {}); 5 | 6 | (function (test) { 7 | pug_html = pug_html + "\u003Cdiv class=\"test\" id=\"test\"\u003E\u003Cspan id=\"data\"\u003Edata\u003C\u002Fspan\u003E"; 8 | if (test) { 9 | pug_html = pug_html + "\u003Cdiv\u003Etesting 2\u003C\u002Fdiv\u003E"; 10 | } 11 | pug_html = pug_html + "\u003C\u002Fdiv\u003E"; 12 | }.call(this, "test" in locals_for_with ? 13 | locals_for_with.test : 14 | typeof test !== 'undefined' ? test : undefined)); 15 | ;;return pug_html;}; -------------------------------------------------------------------------------- /test/expected/jst/pugInclude.js: -------------------------------------------------------------------------------- 1 | this["JST"] = this["JST"] || {}; 2 | 3 | this["JST"]["pugInclude"] = function pug_escape(e){var a=""+e,t=pug_match_html.exec(a);if(!t)return e;var r,c,n,s="";for(r=t.index,c=0;r]/;function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;; 5 | var locals_for_with = (locals || {}); 6 | 7 | (function (a) { 8 | pug_html = pug_html + "\u003Chtml\u003E\u003Chead\u003E\u003Ctitle\u003ETEST\u003C\u002Ftitle\u003E\u003C\u002Fhead\u003E\u003Cbody\u003E\u003C\u002Fbody\u003E\u003C\u002Fhtml\u003E"; 9 | var a = 'hello pug test' 10 | pug_html = pug_html + "\u003Cp\u003E" + (pug_escape(null == (pug_interp = a) ? "" : pug_interp)) + "\u003C\u002Fp\u003E"; 11 | }.call(this, "a" in locals_for_with ? 12 | locals_for_with.a : 13 | typeof a !== 'undefined' ? a : undefined)); 14 | ;;return pug_html;}; -------------------------------------------------------------------------------- /test/expected/jst/pugTemplate.js: -------------------------------------------------------------------------------- 1 | this["JST"] = this["JST"] || {}; 2 | 3 | this["JST"]["pugTemplate"] = function pug_escape(e){var a=""+e,t=pug_match_html.exec(a);if(!t)return e;var r,c,n,s="";for(r=t.index,c=0;r]/;function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;; 5 | var locals_for_with = (locals || {}); 6 | 7 | (function (year) { 8 | pug_html = pug_html + "\u003Cdiv\u003E" + (pug_escape(null == (pug_interp = year) ? "" : pug_interp)) + "\u003C\u002Fdiv\u003E"; 9 | }.call(this, "year" in locals_for_with ? 10 | locals_for_with.year : 11 | typeof year !== 'undefined' ? year : undefined)); 12 | ;;return pug_html;}; -------------------------------------------------------------------------------- /test/expected/pug.html: -------------------------------------------------------------------------------- 1 |
data
testing
-------------------------------------------------------------------------------- /test/expected/pug2.html: -------------------------------------------------------------------------------- 1 |
data
testing 2
-------------------------------------------------------------------------------- /test/expected/pugAdvancedFilters.html: -------------------------------------------------------------------------------- 1 | {Nested}{Fiters}{Are}{Working}filter data is working{/Working}{/Are}{/Fiters}{/Nested} -------------------------------------------------------------------------------- /test/expected/pugCodeBlock.html: -------------------------------------------------------------------------------- 1 |
  • Uno
  • Dos
  • Tres
  • Cuatro
  • Cinco
  • Seis
  • -------------------------------------------------------------------------------- /test/expected/pugDynamicData.html: -------------------------------------------------------------------------------- 1 |
    file test/fixtures/pugDynamicData.pug compiled into tmp/pugDynamicData.html
    -------------------------------------------------------------------------------- /test/expected/pugFilters.html: -------------------------------------------------------------------------------- 1 |
    some: test
    another: test2
    -------------------------------------------------------------------------------- /test/expected/pugInclude.html: -------------------------------------------------------------------------------- 1 | TEST

    hello pug test

    -------------------------------------------------------------------------------- /test/expected/pugTemplate.html: -------------------------------------------------------------------------------- 1 |
    2024
    -------------------------------------------------------------------------------- /test/expected/pugUsingmixin.html: -------------------------------------------------------------------------------- 1 | dodo -------------------------------------------------------------------------------- /test/fixtures/inc/advancedFilters.js: -------------------------------------------------------------------------------- 1 | var pugfilters = module.exports = {}; 2 | 3 | pugfilters.Nested = function(block) { 4 | return '{Nested}' + this.pug.render(block, this.data) + '{/Nested}'; 5 | }; 6 | 7 | pugfilters.Fiters = function(block) { 8 | return '{Fiters}' + this.pug.render(block, this.data) + '{/Fiters}'; 9 | }; 10 | 11 | pugfilters.Are = function(block) { 12 | return '{Are}' + this.pug.render(block, this.data) + '{/Are}'; 13 | }; 14 | 15 | pugfilters.Working = function(block) { 16 | return '{Working}' + this.pug.render(block, this.data) + '{/Working}'; 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/inc/filters.js: -------------------------------------------------------------------------------- 1 | var pugfilters = module.exports = {}; 2 | 3 | pugfilters.some = function(block) { 4 | return 'some: ' + block; 5 | }; 6 | 7 | pugfilters.another = function(block) { 8 | return 'another: ' + block; 9 | }; -------------------------------------------------------------------------------- /test/fixtures/inc/head.pug: -------------------------------------------------------------------------------- 1 | html 2 | head 3 | title TEST 4 | body -------------------------------------------------------------------------------- /test/fixtures/inc/locals.json: -------------------------------------------------------------------------------- 1 | { 2 | "test": "filter data is working" 3 | } -------------------------------------------------------------------------------- /test/fixtures/mixins.pug: -------------------------------------------------------------------------------- 1 | mixin themixin 2 | +anothermixin 3 | 4 | mixin anothermixin 5 | b dodo 6 | -------------------------------------------------------------------------------- /test/fixtures/pug.pug: -------------------------------------------------------------------------------- 1 | #test.test 2 | span#data data 3 | if test 4 | div testing 5 | -------------------------------------------------------------------------------- /test/fixtures/pug2.pug: -------------------------------------------------------------------------------- 1 | #test.test 2 | span#data data 3 | if test 4 | div testing 2 5 | -------------------------------------------------------------------------------- /test/fixtures/pugAdvancedFilters.pug: -------------------------------------------------------------------------------- 1 | :Nested 2 | :Fiters 3 | :Are 4 | :Working 5 | | #{test} 6 | -------------------------------------------------------------------------------- /test/fixtures/pugCodeBlock.pug: -------------------------------------------------------------------------------- 1 | - 2 | list = ["Uno", "Dos", "Tres", 3 | "Cuatro", "Cinco", "Seis"] 4 | 5 | each item in list 6 | li= item 7 | -------------------------------------------------------------------------------- /test/fixtures/pugDynamicData.pug: -------------------------------------------------------------------------------- 1 | #test 2 | | file 3 | code #{src} 4 | | compiled into 5 | code #{dest} 6 | -------------------------------------------------------------------------------- /test/fixtures/pugFilters.pug: -------------------------------------------------------------------------------- 1 | div 2 | div 3 | :some 4 | test 5 | div 6 | :another 7 | test2 8 | -------------------------------------------------------------------------------- /test/fixtures/pugInclude.pug: -------------------------------------------------------------------------------- 1 | include inc/head.pug 2 | 3 | - var a = 'hello pug test' 4 | p= a 5 | -------------------------------------------------------------------------------- /test/fixtures/pugTemplate.pug: -------------------------------------------------------------------------------- 1 | div= year 2 | -------------------------------------------------------------------------------- /test/fixtures/pugUsingmixin.pug: -------------------------------------------------------------------------------- 1 | include mixins.pug 2 | +themixin 3 | -------------------------------------------------------------------------------- /test/helpers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var helpers = module.exports = {}; 4 | 5 | var grunt = require('grunt'); 6 | 7 | helpers.read = function(src) { 8 | var result = grunt.util.normalizelf(grunt.file.read(src)); 9 | if (result.slice(-1) === '\n') { 10 | result = result.slice(0, -1); 11 | } 12 | return result; 13 | }; 14 | -------------------------------------------------------------------------------- /test/pug_amd_test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var read = require('./helpers').read; 4 | 5 | exports.pug = { 6 | compile: function(test) { 7 | 8 | test.expect(4); 9 | 10 | var actual = read('tmp/amd/pug.js'); 11 | var expected = read('test/expected/amd/pug.js'); 12 | test.equal(expected, actual, 'should compile pug templates to js'); 13 | 14 | actual = read('tmp/amd/pug2.js'); 15 | expected = read('test/expected/amd/pug2.js'); 16 | test.equal(expected, actual, 'should compile pug templates to js (multiple files support)'); 17 | 18 | actual = read('tmp/amd/pugInclude.js'); 19 | expected = read('test/expected/amd/pugInclude.js'); 20 | test.equal(expected, actual, 'should compile pug templates to js with an include'); 21 | 22 | actual = read('tmp/amd/pugTemplate.js'); 23 | expected = read('test/expected/amd/pugTemplate.js'); 24 | test.equal(expected, actual, 'should compile pug templates to js with grunt template support'); 25 | 26 | test.done(); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /test/pug_jst_test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var read = require('./helpers').read; 4 | 5 | exports.pug = { 6 | compile: function(test) { 7 | 8 | test.expect(4); 9 | 10 | var actual = read('tmp/jst/pug.js'); 11 | var expected = read('test/expected/jst/pug.js'); 12 | test.equal(expected, actual, 'should compile pug templates to JST template'); 13 | 14 | actual = read('tmp/jst/pug2.js'); 15 | expected = read('test/expected/jst/pug2.js'); 16 | test.equal(expected, actual, 'should compile pug templates to JST template (multiple files support)'); 17 | 18 | actual = read('tmp/jst/pugInclude.js'); 19 | expected = read('test/expected/jst/pugInclude.js'); 20 | test.equal(expected, actual, 'should compile pug templates to JST template with an include'); 21 | 22 | actual = read('tmp/jst/pugTemplate.js'); 23 | expected = read('test/expected/jst/pugTemplate.js'); 24 | test.equal(expected, actual, 'should compile pug templates to JST template with grunt template support'); 25 | 26 | test.done(); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /test/pug_test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var read = require('./helpers').read; 4 | 5 | exports.pug = { 6 | compile: function(test) { 7 | 8 | test.expect(10); 9 | 10 | var actual = read('tmp/pug.html'); 11 | var expected = read('test/expected/pug.html'); 12 | test.equal(expected, actual, 'should compile pug templates to html'); 13 | 14 | actual = read('tmp/pug2.html'); 15 | expected = read('test/expected/pug2.html'); 16 | test.equal(expected, actual, 'should compile pug templates to html (multiple files support)'); 17 | 18 | actual = read('tmp/pugInclude.html'); 19 | expected = read('test/expected/pugInclude.html'); 20 | test.equal(expected, actual, 'should compile pug templates to html with an include'); 21 | 22 | actual = read('tmp/pugTemplate.html'); 23 | expected = read('test/expected/pugTemplate.html'); 24 | test.equal(expected, actual, 'should compile pug templates to html with grunt template support'); 25 | 26 | actual = read('tmp/pugDynamicData.html'); 27 | expected = read('test/expected/pugDynamicData.html'); 28 | test.equal(expected, actual, 'should allow options.data to be a function'); 29 | 30 | actual = read('tmp/inlineFilters.html'); 31 | expected = read('test/expected/pugFilters.html'); 32 | test.equal(expected, actual, 'should compile pug with inline filters'); 33 | 34 | actual = read('tmp/exportedFilters.html'); 35 | expected = read('test/expected/pugFilters.html'); 36 | test.equal(expected, actual, 'should compile pug with exported filters'); 37 | 38 | actual = read('tmp/pugAdvancedFilters.html'); 39 | expected = read('test/expected/pugAdvancedFilters.html'); 40 | test.equal(expected, actual, 'should compile pug with nested filters with access to locals'); 41 | 42 | actual = read('tmp/pugUsingmixin.html'); 43 | expected = read('test/expected/pugUsingmixin.html'); 44 | test.equal(expected, actual, 'should compile pug with nested mixins'); 45 | 46 | actual = read('tmp/pugCodeBlock.html'); 47 | expected = read('test/expected/pugCodeBlock.html'); 48 | test.equal(expected, actual, 'should compile pug with codeblock'); 49 | 50 | test.done(); 51 | } 52 | }; 53 | --------------------------------------------------------------------------------