Server IP : 92.205.26.207 / Your IP : 216.73.216.16 Web Server : Apache System : Linux 207.26.205.92.host.secureserver.net 4.18.0-553.60.1.el8_10.x86_64 #1 SMP Thu Jul 10 04:01:16 EDT 2025 x86_64 User : zikryat ( 1002) PHP Version : 8.3.23 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/zikryat/public_html/node_modules/pug-attrs/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
# pug-attrs Generate code for Pug attributes [](https://travis-ci.org/pugjs/pug-attrs) [](https://david-dm.org/pugjs/pug?path=packages/pug-attrs) [](https://www.npmjs.org/package/pug-attrs) ## Installation npm install pug-attrs ## Usage ```js var compileAttrs = require('pug-attrs'); ``` ### `compileAttrs(attrs, options)` Compile `attrs` to a JavaScript string that evaluates to the attributes in the desired format. `options` MUST include the following properties: - `terse`: whether or not to use HTML5-style terse boolean attributes - `runtime`: callback that takes a runtime function name and returns the source code that will evaluate to that function at runtime - `format`: output format; must be `html` or `object` `attrs` is an array of attributes, with each attribute having the form of `{ name, val, mustEscape }`. `val` represents a JavaScript string that evaluates to the value of the attribute, either statically or dynamically. ```js var compileAttrs = require('pug-attrs'); var pugRuntime = require('pug-runtime'); function getBaz () { return 'baz<>'; } var attrs = [ {name: 'foo', val: '"bar"', mustEscape: true }, {name: 'baz', val: 'getBaz()', mustEscape: true }, {name: 'quux', val: true, mustEscape: false} ]; var result, finalResult; // HTML MODE result = compileAttrs(attrs, { terse: true, format: 'html', runtime: function (name) { return 'pugRuntime.' + name; } }); //=> '" foo=\\"bar\\"" + pugRuntime.attr("baz", getBaz(), true, true) + " quux"' finalResult = Function('pugRuntime, getBaz', 'return (' + result + ');' ); finalResult(pugRuntime, getBaz); // => ' foo="bar" baz="baz<>" quux' // OBJECT MODE result = compileAttrs(attrs, { terse: true, format: 'object', runtime: function (name) { return 'pugRuntime.' + name; } }); //=> '{"foo": "bar","baz": pugRuntime.escape(getBaz()),"quux": true}' finalResult = Function('pugRuntime, getBaz', 'return (' + result + ');' ); finalResult(pugRuntime, getBaz); //=> { foo: 'bar', baz: 'baz<>', quux: true } ``` ## License MIT