zig-pug 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +266 -226
  2. package/binding.gyp +5 -8
  3. package/index.js +11 -33
  4. package/package.json +24 -24
package/README.md CHANGED
@@ -1,19 +1,22 @@
1
1
  # zig-pug
2
2
 
3
- High-performance Pug template engine powered by Zig and mujs - Native N-API addon with ES5.1 JavaScript support.
3
+ High-performance Pug template engine powered by Zig and mujs.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/zig-pug.svg)](https://www.npmjs.com/package/zig-pug)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![license](https://img.shields.io/npm/l/zig-pug.svg)](https://github.com/carlos-sweb/zig-pug/blob/main/LICENSE)
7
7
 
8
8
  ## Features
9
9
 
10
- - **Blazing Fast**: Written in Zig with native N-API bindings
11
- - **Lightweight**: ~500KB total (includes mujs JavaScript engine)
12
- - **Modern**: Zig 0.15 best practices with StaticStringMap O(1) lookups
13
- - **Secure**: Built-in XSS protection with automatic HTML escaping
14
- - **Simple API**: Easy-to-use JavaScript interface
15
- - **Cross-Platform**: Precompiled binaries for Linux, macOS, and Windows
16
- - **Node.js Compatible**: Works with Node.js 14+ and Bun.js
10
+ - **Pug syntax** - Tags, attributes, classes, IDs
11
+ - **JavaScript expressions** - ES5.1 interpolation powered by mujs
12
+ - **Full UTF-8 support** - Emoji 🎉, accents (á é ñ ü), all Unicode
13
+ - **Documentation comments** - `//!` for file metadata (ignored by parser)
14
+ - **Conditionals** - if/else/unless
15
+ - **Mixins** - Reusable components
16
+ - **Bun.js compatible** - 2-5x faster than Node.js
17
+ - ⚡ **Native performance** - Written in Zig, compiled to native code
18
+ - 🔋 **Zero dependencies** - Only Zig and embedded mujs
19
+ - 🌍 **i18n ready** - Spanish, Portuguese, French, German, and more
17
20
 
18
21
  ## Installation
19
22
 
@@ -21,326 +24,363 @@ High-performance Pug template engine powered by Zig and mujs - Native N-API addo
21
24
  npm install zig-pug
22
25
  ```
23
26
 
24
- Precompiled binaries are automatically downloaded for your platform. If no binary is available, it will build from source (requires Zig 0.15+).
27
+ **Requirements:**
28
+ - Node.js >= 14.0.0
29
+ - C/C++ compiler (GCC, Clang, or MSVC)
30
+ - Python (for node-gyp)
31
+
32
+ The addon will compile automatically during installation.
25
33
 
26
34
  ## Quick Start
27
35
 
28
- ```javascript
29
- const { compile } = require('zig-pug');
36
+ ### Simple API
30
37
 
31
- // Simple template
32
- const html = compile('h1 Hello, World!');
33
- console.log(html); // <h1>Hello, World!</h1>
38
+ ```javascript
39
+ const zigpug = require('zig-pug');
34
40
 
35
- // With variables
36
- const html2 = compile('h1 Hello, #{name}!', { name: 'Alice' });
37
- console.log(html2); // <h1>Hello, Alice!</h1>
41
+ const html = zigpug.compile('p Hello #{name}!', { name: 'World' });
42
+ console.log(html);
43
+ // <p>Hello World!</p>
38
44
  ```
39
45
 
40
- ## API Reference
41
-
42
- ### compile(template, variables)
43
-
44
- Compile a Pug template string to HTML.
46
+ ### Object-Oriented API
45
47
 
46
48
  ```javascript
47
- const { compile } = require('zig-pug');
49
+ const { PugCompiler } = require('zig-pug');
48
50
 
49
- const html = compile('p Hello, #{name}!', { name: 'Bob' });
50
- console.log(html); // <p>Hello, Bob!</p>
51
- ```
51
+ const compiler = new PugCompiler();
52
+ compiler
53
+ .set('title', 'My Page')
54
+ .set('version', 1.5)
55
+ .setBool('isDev', false);
52
56
 
53
- **Parameters:**
54
- - `template` (string): Pug template string
55
- - `variables` (object, optional): Variables to interpolate
57
+ const html = compiler.compile('h1 #{title}');
58
+ console.log(html);
59
+ // <h1>My Page</h1>
60
+ ```
56
61
 
57
- **Returns:** Compiled HTML string
62
+ ### Express Integration
58
63
 
59
- ### compileFile(filename, variables)
64
+ ```javascript
65
+ const express = require('express');
66
+ const zigpug = require('zig-pug');
67
+ const fs = require('fs');
60
68
 
61
- Compile a Pug template file to HTML.
69
+ const app = express();
62
70
 
63
- ```javascript
64
- const { compileFile } = require('zig-pug');
71
+ // Load template once at startup
72
+ const homeTemplate = fs.readFileSync('./views/home.pug', 'utf-8');
65
73
 
66
- const html = compileFile('./views/index.pug', {
67
- title: 'My Page',
68
- user: 'Alice'
74
+ app.get('/', (req, res) => {
75
+ const html = zigpug.compile(homeTemplate, {
76
+ title: 'Home',
77
+ user: req.user
78
+ });
79
+ res.send(html);
69
80
  });
81
+
82
+ app.listen(3000);
70
83
  ```
71
84
 
72
- **Parameters:**
73
- - `filename` (string): Path to Pug template file
74
- - `variables` (object, optional): Variables to interpolate
85
+ ## Bun.js Support
75
86
 
76
- **Returns:** Compiled HTML string
87
+ zig-pug works seamlessly with Bun, the ultra-fast JavaScript runtime:
88
+
89
+ ```bash
90
+ bun install zig-pug
91
+ bun run app.js
92
+ ```
77
93
 
78
- ### ZigPugCompiler Class
94
+ **Performance:** Bun is 2-5x faster than Node.js for template compilation.
79
95
 
80
- For multiple compilations, use the `ZigPugCompiler` class to reuse the context:
96
+ See [examples/bun/](https://github.com/carlos-sweb/zig-pug/tree/main/examples/bun) for complete examples.
81
97
 
82
- ```javascript
83
- const { ZigPugCompiler } = require('zig-pug');
98
+ ## Pug Syntax
84
99
 
85
- const compiler = new ZigPugCompiler();
100
+ ### Tags and Attributes
86
101
 
87
- // Set variables
88
- compiler.setString('name', 'Alice');
89
- compiler.setNumber('age', 30);
90
- compiler.setBool('premium', true);
102
+ ```pug
103
+ div.container
104
+ h1#title Hello World
105
+ p.text(data-id="123") Content
106
+ a(href="/" target="_blank") Link
107
+ ```
91
108
 
92
- // Or set multiple at once
93
- compiler.setVariables({
94
- name: 'Bob',
95
- age: 25,
96
- premium: false
97
- });
109
+ ### JavaScript Interpolation
98
110
 
99
- // Compile templates
100
- const html1 = compiler.compile('p Hello, #{name}!');
101
- const html2 = compiler.compile('p Age: #{age}');
111
+ ```pug
112
+ p Hello #{name}!
113
+ p Age: #{age + 1}
114
+ p Email: #{email.toLowerCase()}
115
+ p Status: #{age >= 18 ? 'Adult' : 'Minor'}
116
+ p Max: #{Math.max(10, 20)}
102
117
  ```
103
118
 
104
- **Methods:**
105
- - `setString(key, value)` - Set a string variable
106
- - `setNumber(key, value)` - Set a number variable
107
- - `setBool(key, value)` - Set a boolean variable
108
- - `set(key, value)` - Auto-detect type and set variable
109
- - `setVariables(obj)` - Set multiple variables from object
110
- - `compile(template)` - Compile template with current variables
111
- - `render(template, variables)` - Set variables and compile in one call
119
+ **Supported JavaScript (ES5.1):**
120
+ - String methods: `toLowerCase()`, `toUpperCase()`, `split()`, etc.
121
+ - Math: `Math.max()`, `Math.min()`, `Math.random()`, etc.
122
+ - Operators: `+`, `-`, `*`, `/`, `%`, `&&`, `||`, `?:`
123
+ - Object/Array access: `obj.prop`, `arr[0]`, `arr.length`
112
124
 
113
- ### version()
125
+ ### Conditionals
114
126
 
115
- Get the zig-pug version.
127
+ ```pug
128
+ if isLoggedIn
129
+ p Welcome back!
130
+ else
131
+ p Please log in
116
132
 
117
- ```javascript
118
- const { version } = require('zig-pug');
119
- console.log(version()); // 0.2.0
133
+ unless isAdmin
134
+ p Access denied
120
135
  ```
121
136
 
122
- ## Pug Syntax Support
123
-
124
- ### Tags
137
+ ### Mixins
125
138
 
126
139
  ```pug
127
- div
128
- p Hello, World!
129
- span.class-name#id-name Text content
130
- ```
140
+ mixin button(text)
141
+ button.btn= text
131
142
 
132
- ```html
133
- <div>
134
- <p>Hello, World!</p>
135
- <span class="class-name" id="id-name">Text content</span>
136
- </div>
143
+ +button('Click me')
144
+ +button('Submit')
137
145
  ```
138
146
 
139
- ### Attributes
147
+ ### UTF-8 & Unicode Support
148
+
149
+ Full support for international characters, emoji, and symbols:
140
150
 
141
151
  ```pug
142
- a(href="https://example.com" target="_blank") Link
143
- input(type="text" name="username" required)
152
+ //! File: index.pug
153
+ //! Author: Carlos
154
+ doctype html
155
+ html(lang="es")
156
+ head
157
+ title #{titulo}
158
+ body
159
+ h1 ¡Bienvenido! 🎉
160
+
161
+ section.español
162
+ p.información Información sobre José y María
163
+ p#descripción Este párrafo tiene ID con acento
164
+
165
+ section.português
166
+ h2 Programação em português
167
+ p Características: ã, õ, ç
168
+
169
+ section.français
170
+ h2 Génération française
171
+ p Avec é, è, ê, ç
172
+
173
+ footer
174
+ p © 2025 - Creado con zig-pug 🚀
144
175
  ```
145
176
 
146
- ```html
147
- <a href="https://example.com" target="_blank">Link</a>
148
- <input type="text" name="username" required />
149
- ```
177
+ **Supported everywhere:**
178
+ - Text content: `p José, María, Ángel`
179
+ - Class names: `.información .português`
180
+ - ✅ ID attributes: `#descripción #größe`
181
+ - ✅ Comments: `// útil para depuración`
182
+ - ✅ Emoji: `h1 Hello 🎉 🚀 ✨`
183
+ - ✅ Symbols: `p © ™ € £ ¥`
150
184
 
151
- ### Interpolation
185
+ ### Documentation Comments
186
+
187
+ Use `//!` for file metadata that won't appear in output:
152
188
 
153
189
  ```pug
154
- p Hello, #{name}!
155
- p Age: #{age}
156
- p Premium: #{premium}
190
+ //! Template: homepage.pug
191
+ //! Author: John Doe
192
+ //! Version: 1.0
193
+ //! Description: Main landing page
194
+ doctype html
195
+ html
196
+ body
197
+ // Regular comment (appears in --pretty mode)
198
+ //- Code comment (never appears)
157
199
  ```
158
200
 
159
- With variables: `{ name: 'Alice', age: 30, premium: true }`
201
+ | Syntax | Name | In HTML? | Use Case |
202
+ |--------|------|----------|----------|
203
+ | `//!` | Documentation | ❌ Never | File metadata, notes |
204
+ | `//` | Buffered | ✅ Dev mode | Development debugging |
205
+ | `//-` | Unbuffered | ❌ Never | Code comments |
160
206
 
161
- ```html
162
- <p>Hello, Alice!</p>
163
- <p>Age: 30</p>
164
- <p>Premium: true</p>
165
- ```
207
+ ## API Reference
208
+
209
+ ### `compile(template, data)`
166
210
 
167
- ### HTML Escaping
211
+ Compile a template with data.
168
212
 
169
- Automatic XSS protection:
213
+ **Parameters:**
214
+ - `template` (string) - Pug template source
215
+ - `data` (object) - Variables to interpolate
216
+
217
+ **Returns:** (string) Compiled HTML
170
218
 
171
219
  ```javascript
172
- const html = compile('p #{userInput}', {
173
- userInput: '<script>alert("XSS")</script>'
174
- });
175
- // <p>&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;</p>
220
+ const html = zigpug.compile(
221
+ 'p Hello #{name}!',
222
+ { name: 'Alice' }
223
+ );
176
224
  ```
177
225
 
178
- ### Void Elements
226
+ ### `PugCompiler`
179
227
 
180
- Self-closing tags are handled automatically:
228
+ Reusable compiler with state.
181
229
 
182
- ```pug
183
- br
184
- hr
185
- img(src="logo.png")
186
- input(type="text")
187
- ```
230
+ ```javascript
231
+ const { PugCompiler } = require('zig-pug');
188
232
 
189
- ```html
190
- <br />
191
- <hr />
192
- <img src="logo.png" />
193
- <input type="text" />
233
+ const compiler = new PugCompiler();
234
+ compiler.set('key', 'value'); // String/Number
235
+ compiler.setBool('flag', true); // Boolean
236
+
237
+ const html = compiler.compile(template);
194
238
  ```
195
239
 
196
- ## Usage Examples
240
+ **Methods:**
241
+ - `set(key, value)` - Set string or number variable
242
+ - `setBool(key, value)` - Set boolean variable
243
+ - `compile(template)` - Compile template with current variables
197
244
 
198
- ### Express Integration
245
+ ### `version()`
246
+
247
+ Get zig-pug version.
199
248
 
200
249
  ```javascript
201
- const express = require('express');
202
- const { compileFile } = require('zig-pug');
203
- const app = express();
250
+ console.log(zigpug.version()); // "0.2.0"
251
+ ```
204
252
 
205
- app.get('/', (req, res) => {
206
- const html = compileFile('./views/index.pug', {
207
- title: 'Home Page',
208
- user: req.user
209
- });
210
- res.send(html);
211
- });
253
+ ## Platform Support
212
254
 
213
- app.listen(3000);
214
- ```
255
+ ### Supported Platforms
215
256
 
216
- ### Koa Integration
257
+ - **Linux** (x64, ARM64)
258
+ - ✅ **macOS** (x64, Apple Silicon)
259
+ - ✅ **Windows** (x64)
260
+ - ✅ **Bun.js** (all platforms)
217
261
 
218
- ```javascript
219
- const Koa = require('koa');
220
- const { compileFile } = require('zig-pug');
221
- const app = new Koa();
222
-
223
- app.use(async ctx => {
224
- const html = compileFile('./views/index.pug', {
225
- title: 'Home Page',
226
- path: ctx.path
227
- });
228
- ctx.body = html;
229
- });
262
+ ### Termux/Android
230
263
 
231
- app.listen(3000);
232
- ```
264
+ The addon compiles on Termux but cannot be loaded due to Android namespace restrictions. Use the standalone CLI binary instead:
233
265
 
234
- ### Bun.js Integration
266
+ ```bash
267
+ # Install Zig
268
+ pkg install zig
235
269
 
236
- ```javascript
237
- import { compile } from 'zig-pug';
238
-
239
- Bun.serve({
240
- port: 3000,
241
- fetch(req) {
242
- const html = compile('h1 Hello from Bun!');
243
- return new Response(html, {
244
- headers: { 'Content-Type': 'text/html' }
245
- });
246
- }
247
- });
270
+ # Clone and build
271
+ git clone https://github.com/yourusername/zig-pug
272
+ cd zig-pug
273
+ zig build
274
+
275
+ # Use CLI
276
+ ./zig-out/bin/zig-pug template.pug
248
277
  ```
249
278
 
279
+ See [docs/TERMUX.md](https://github.com/yourusername/zig-pug/blob/main/docs/TERMUX.md) for details.
280
+
250
281
  ## Performance
251
282
 
252
- zig-pug is designed for performance:
283
+ ### Benchmark
284
+
285
+ ```javascript
286
+ const iterations = 10000;
287
+ const start = Date.now();
253
288
 
254
- - **O(1) lookups**: StaticStringMap for void element checks
255
- - **Optimized I/O**: Writer pattern reduces allocations
256
- - **Native code**: Zig compiles to machine code
257
- - **Lightweight**: No heavy dependencies
258
- - **Fast startup**: mujs has minimal overhead
289
+ for (let i = 0; i < iterations; i++) {
290
+ zigpug.compile(template, data);
291
+ }
259
292
 
260
- ## Security
293
+ const elapsed = Date.now() - start;
294
+ console.log(`${iterations} in ${elapsed}ms`);
295
+ // ~100-250k ops/sec depending on runtime
296
+ ```
261
297
 
262
- - **Automatic HTML escaping**: All interpolated values are escaped by default
263
- - **XSS prevention**: Built-in protection against cross-site scripting
264
- - **Safe parsing**: Zig's memory safety prevents buffer overflows
265
- - **No eval()**: Templates are compiled, not evaluated
298
+ ### Tips
266
299
 
267
- ## Building from Source
300
+ 1. **Reuse PugCompiler** - Faster than creating new context each time
301
+ 2. **Pre-load templates** - Read files once at startup
302
+ 3. **Use Bun.js** - 2-5x faster than Node.js
268
303
 
269
- If precompiled binaries are not available for your platform:
304
+ ## Examples
270
305
 
271
- ### Prerequisites
306
+ See the [examples](https://github.com/yourusername/zig-pug/tree/main/examples) directory:
272
307
 
273
- - Node.js 14+
274
- - Zig 0.15+
275
- - Python 3
276
- - C compiler (gcc/clang)
308
+ - **Node.js**: `examples/nodejs/`
309
+ - **Bun.js**: `examples/bun/`
310
+ - **Express**: `examples/nodejs/05-express-integration.js`
277
311
 
278
- ### Build Steps
312
+ ## Documentation
279
313
 
280
- From the repository root:
314
+ - **[Getting Started](https://github.com/yourusername/zig-pug/blob/main/docs/GETTING-STARTED.md)**
315
+ - **[Node.js Integration](https://github.com/yourusername/zig-pug/blob/main/docs/NODEJS-INTEGRATION.md)**
316
+ - **[Pug Syntax Reference](https://github.com/yourusername/zig-pug/blob/main/docs/PUG-SYNTAX.md)**
317
+ - **[API Reference](https://github.com/yourusername/zig-pug/blob/main/docs/API-REFERENCE.md)**
281
318
 
282
- ```bash
283
- # Build the addon (builds library + addon + copies library to build dir)
284
- zig build node
319
+ ## Troubleshooting
285
320
 
286
- # Or from nodejs directory
287
- cd nodejs && npm run build
288
- ```
321
+ ### Installation fails
322
+
323
+ **Error:** `node-gyp rebuild` fails
289
324
 
290
- ### Running Examples and Tests
325
+ **Solution:** Install build tools:
291
326
 
292
327
  ```bash
293
- # From nodejs directory
294
- npm test # Run test suite
295
- npm run example # Run example
328
+ # Ubuntu/Debian
329
+ sudo apt-get install build-essential python3
296
330
 
297
- # Or directly with node (after building)
298
- node test/test.js
299
- node example.js
331
+ # macOS
332
+ xcode-select --install
333
+
334
+ # Windows
335
+ npm install --global windows-build-tools
300
336
  ```
301
337
 
302
- **Note:** The build process automatically copies `libzigpug.so` to the `build/Release/` directory, so you don't need to set `LD_LIBRARY_PATH` manually.
338
+ ### Module not found
303
339
 
304
- See [BUILD_GUIDE.md](BUILD_GUIDE.md) for detailed build instructions.
340
+ **Error:** `Cannot find module 'zig-pug'`
305
341
 
306
- ## Architecture
342
+ **Solution:** Rebuild the addon:
307
343
 
344
+ ```bash
345
+ cd node_modules/zig-pug
346
+ npm run build
308
347
  ```
309
- ┌─────────────────────────────────────────────┐
310
- │ Node.js Application │
311
- │ (your code) │
312
- └────────────┬────────────────────────────────┘
313
- require('zig-pug')
314
-
315
- ┌─────────────────────────────────────────────┐
316
- │ N-API Addon (binding.c) │
317
- │ - JavaScript API wrapper │
318
- └────────────┬────────────────────────────────┘
319
- │ FFI calls
320
-
321
- ┌─────────────────────────────────────────────┐
322
- │ libzigpug.so (Zig + mujs) │
323
- │ - Tokenizer → Parser → Compiler → HTML │
324
- └─────────────────────────────────────────────┘
325
- ```
348
+
349
+ ### Compilation errors
350
+
351
+ If you encounter compilation errors, please [open an issue](https://github.com/yourusername/zig-pug/issues) with:
352
+ - Your OS and version
353
+ - Node.js version (`node --version`)
354
+ - Complete error output
326
355
 
327
356
  ## Contributing
328
357
 
329
- Contributions are welcome! Please see the main repository for contributing guidelines.
358
+ Contributions are welcome! Please:
359
+
360
+ 1. Fork the repository
361
+ 2. Create a feature branch
362
+ 3. Make your changes
363
+ 4. Run tests: `npm test`
364
+ 5. Submit a pull request
330
365
 
331
366
  ## License
332
367
 
333
- MIT License - see [LICENSE](LICENSE) for details.
368
+ MIT License - see [LICENSE](https://github.com/yourusername/zig-pug/blob/main/LICENSE) for details.
369
+
370
+ ## Credits
371
+
372
+ - **[Pug](https://pugjs.org/)** - Original inspiration
373
+ - **[Zig](https://ziglang.org/)** - Programming language
374
+ - **[mujs](https://mujs.com/)** - Embedded JavaScript engine
375
+ - **[Artifex Software](https://artifex.com/)** - Creators of mujs
334
376
 
335
377
  ## Links
336
378
 
337
- - [GitHub Repository](https://github.com/carlos-sweb/zig-pug)
338
- - [npm Package](https://www.npmjs.com/package/zig-pug)
339
- - [Issue Tracker](https://github.com/carlos-sweb/zig-pug/issues)
340
- - [Build Guide](BUILD_GUIDE.md)
379
+ - **GitHub**: https://github.com/yourusername/zig-pug
380
+ - **npm**: https://www.npmjs.com/package/zig-pug
381
+ - **Issues**: https://github.com/yourusername/zig-pug/issues
382
+ - **Documentation**: https://github.com/yourusername/zig-pug#readme
341
383
 
342
- ## Credits
384
+ ---
343
385
 
344
- - Built by [carlos-sweb](https://github.com/carlos-sweb)
345
- - Powered by [Zig](https://ziglang.org/) and [mujs](https://mujs.com/)
346
- - Inspired by the original [Pug](https://pugjs.org/) template engine
386
+ Made with ❤️ using Zig 0.15.2 and mujs
package/binding.gyp CHANGED
@@ -3,25 +3,22 @@
3
3
  {
4
4
  "target_name": "zigpug",
5
5
  "sources": [
6
- "binding.c"
6
+ "binding.c",
7
+ "vendor/mujs/one.c"
7
8
  ],
8
9
  "include_dirs": [
9
10
  "include",
10
- "../vendor/mujs"
11
+ "vendor/mujs"
11
12
  ],
12
13
  "libraries": [
13
- "-L<(module_root_dir)",
14
- "-lzigpug",
15
14
  "-lm"
16
15
  ],
17
16
  "cflags": [
18
- "-std=c99"
17
+ "-std=c99",
18
+ "-DHAVE_STRLCPY=0"
19
19
  ],
20
20
  "defines": [
21
21
  "NAPI_VERSION=8"
22
- ],
23
- "ldflags": [
24
- "-Wl,-rpath,'$$ORIGIN'"
25
22
  ]
26
23
  }
27
24
  ]
package/index.js CHANGED
@@ -3,32 +3,12 @@
3
3
  * Powered by Zig and mujs
4
4
  */
5
5
 
6
- const binary = require('@mapbox/node-pre-gyp');
7
- const path = require('path');
8
- const fs = require('fs');
9
-
10
- // Try to find precompiled binary first, fallback to development build
11
- let binding;
12
- try {
13
- const binding_path = binary.find(path.resolve(path.join(__dirname, './package.json')));
14
- binding = require(binding_path);
15
- } catch (err) {
16
- // Fallback to development build location
17
- const dev_path = path.join(__dirname, 'build', 'Release', 'zigpug.node');
18
- if (fs.existsSync(dev_path)) {
19
- binding = require(dev_path);
20
- } else {
21
- throw new Error(
22
- 'zig-pug native addon not found. ' +
23
- 'Please build it with: cd .. && zig build node'
24
- );
25
- }
26
- }
6
+ const binding = require('./build/Release/zigpug.node');
27
7
 
28
8
  /**
29
- * ZigPugCompiler class - High-level API for compiling Pug templates
9
+ * PugCompiler class - High-level API for compiling Pug templates
30
10
  */
31
- class ZigPugCompiler {
11
+ class PugCompiler {
32
12
  constructor() {
33
13
  this.context = binding.createContext();
34
14
  if (!this.context) {
@@ -40,7 +20,7 @@ class ZigPugCompiler {
40
20
  * Set a string variable in the template context
41
21
  * @param {string} key - Variable name
42
22
  * @param {string} value - String value
43
- * @returns {ZigPugCompiler} - Returns this for chaining
23
+ * @returns {PugCompiler} - Returns this for chaining
44
24
  */
45
25
  setString(key, value) {
46
26
  if (typeof key !== 'string') {
@@ -61,7 +41,7 @@ class ZigPugCompiler {
61
41
  * Set a number variable in the template context
62
42
  * @param {string} key - Variable name
63
43
  * @param {number} value - Number value
64
- * @returns {ZigPugCompiler} - Returns this for chaining
44
+ * @returns {PugCompiler} - Returns this for chaining
65
45
  */
66
46
  setNumber(key, value) {
67
47
  if (typeof key !== 'string') {
@@ -82,7 +62,7 @@ class ZigPugCompiler {
82
62
  * Set a boolean variable in the template context
83
63
  * @param {string} key - Variable name
84
64
  * @param {boolean} value - Boolean value
85
- * @returns {ZigPugCompiler} - Returns this for chaining
65
+ * @returns {PugCompiler} - Returns this for chaining
86
66
  */
87
67
  setBool(key, value) {
88
68
  if (typeof key !== 'string') {
@@ -103,7 +83,7 @@ class ZigPugCompiler {
103
83
  * Set a variable (automatically detects type)
104
84
  * @param {string} key - Variable name
105
85
  * @param {string|number|boolean} value - Value of any supported type
106
- * @returns {ZigPugCompiler} - Returns this for chaining
86
+ * @returns {PugCompiler} - Returns this for chaining
107
87
  */
108
88
  set(key, value) {
109
89
  if (typeof value === 'string') {
@@ -120,7 +100,7 @@ class ZigPugCompiler {
120
100
  /**
121
101
  * Set multiple variables from an object
122
102
  * @param {Object} variables - Object with key-value pairs
123
- * @returns {ZigPugCompiler} - Returns this for chaining
103
+ * @returns {PugCompiler} - Returns this for chaining
124
104
  */
125
105
  setVariables(variables) {
126
106
  if (typeof variables !== 'object' || variables === null) {
@@ -171,7 +151,7 @@ class ZigPugCompiler {
171
151
  * @returns {string} - Compiled HTML
172
152
  */
173
153
  function compile(template, variables = {}) {
174
- const compiler = new ZigPugCompiler();
154
+ const compiler = new PugCompiler();
175
155
  return compiler.render(template, variables);
176
156
  }
177
157
 
@@ -196,10 +176,8 @@ function version() {
196
176
  }
197
177
 
198
178
  module.exports = {
199
- ZigPugCompiler,
179
+ PugCompiler,
200
180
  compile,
201
181
  compileFile,
202
- version,
203
- // Backward compatibility alias
204
- PugCompiler: ZigPugCompiler
182
+ version
205
183
  };
package/package.json CHANGED
@@ -1,20 +1,14 @@
1
1
  {
2
2
  "name": "zig-pug",
3
- "version": "0.2.0",
4
- "description": "High-performance Pug template engine powered by Zig and mujs - Native N-API addon with ES5.1 JavaScript support",
3
+ "version": "0.3.0",
4
+ "description": "High-performance Pug template engine powered by Zig and mujs. Native N-API addon with ES5.1 JavaScript support, full UTF-8 (emoji, accents), documentation comments (//!), and fast compilation. Compatible with Node.js and Bun.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "install": "node-pre-gyp install --fallback-to-build || (cd .. && zig build node)",
8
- "build": "cd .. && zig build node",
9
- "build:from-source": "cd .. && zig build node",
10
- "rebuild": "node-gyp rebuild && npm run postbuild",
11
- "postbuild": "cp ../zig-out/nodejs/libzigpug.* build/Release/ 2>/dev/null || true",
12
- "clean": "node-gyp clean && rm -rf ../zig-out/nodejs lib/binding",
13
- "test": "LD_LIBRARY_PATH=../zig-out/nodejs:$LD_LIBRARY_PATH node test/test.js",
14
- "example": "LD_LIBRARY_PATH=../zig-out/nodejs:$LD_LIBRARY_PATH node example.js",
15
- "package": "node-pre-gyp package",
16
- "upload": "node-pre-gyp publish",
17
- "upload:github": "node scripts/upload-binary.js",
7
+ "install": "node-gyp rebuild",
8
+ "build": "node-gyp configure build",
9
+ "rebuild": "node-gyp rebuild",
10
+ "clean": "node-gyp clean",
11
+ "test": "node test/test.js",
18
12
  "prepublishOnly": "npm run build"
19
13
  },
20
14
  "keywords": [
@@ -40,11 +34,22 @@
40
34
  "view-engine",
41
35
  "express",
42
36
  "jade",
43
- "haml"
37
+ "haml",
38
+ "utf-8",
39
+ "utf8",
40
+ "unicode",
41
+ "emoji",
42
+ "i18n",
43
+ "internationalization",
44
+ "multilingual",
45
+ "spanish",
46
+ "portuguese",
47
+ "french",
48
+ "german"
44
49
  ],
45
50
  "author": {
46
- "name": "carlos-sweb",
47
- "url": "https://github.com/carlos-sweb"
51
+ "name": "zig-pug contributors",
52
+ "url": "https://github.com/carlos-sweb/zig-pug/graphs/contributors"
48
53
  },
49
54
  "license": "MIT",
50
55
  "repository": {
@@ -59,19 +64,14 @@
59
64
  "engines": {
60
65
  "node": ">=14.0.0"
61
66
  },
62
- "dependencies": {
63
- "@mapbox/node-pre-gyp": "^1.0.11"
64
- },
67
+ "dependencies": {},
65
68
  "devDependencies": {
66
- "node-gyp": "^10.0.0",
67
- "aws-sdk": "^2.1691.0"
69
+ "node-gyp": "^10.0.0"
68
70
  },
69
71
  "gypfile": true,
70
72
  "binary": {
71
73
  "module_name": "zigpug",
72
- "module_path": "./lib/binding/{configuration}/{node_abi}-{platform}-{arch}",
73
- "remote_path": "./{version}",
74
- "package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz",
74
+ "module_path": "./build/Release/",
75
75
  "host": "https://github.com/carlos-sweb/zig-pug/releases/download/"
76
76
  },
77
77
  "files": [