binja 0.1.1 → 0.2.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.
package/README.md CHANGED
@@ -23,13 +23,15 @@
23
23
 
24
24
  ## Why binja?
25
25
 
26
- | Feature | binja | Other JS engines |
26
+ | Feature | Binja | Other JS engines |
27
27
  |---------|-----------|------------------|
28
28
  | **AOT Compilation** | ✅ 160x faster | ❌ |
29
29
  | Django DTL Compatible | ✅ 100% | ❌ Partial |
30
30
  | Jinja2 Compatible | ✅ Full | ⚠️ Limited |
31
31
  | Template Inheritance | ✅ | ⚠️ |
32
32
  | 50+ Built-in Filters | ✅ | ❌ |
33
+ | Debug Panel | ✅ | ❌ |
34
+ | CLI Tool | ✅ | ⚠️ |
33
35
  | Autoescape by Default | ✅ | ❌ |
34
36
  | TypeScript | ✅ Native | ⚠️ |
35
37
  | Bun Optimized | ✅ | ❌ |
@@ -402,6 +404,90 @@ const env = new Environment({
402
404
 
403
405
  ---
404
406
 
407
+ ## Debug Panel
408
+
409
+ Binja includes a professional debug panel for development, similar to Django Debug Toolbar:
410
+
411
+ ```typescript
412
+ const env = new Environment({
413
+ templates: './templates',
414
+ debug: true, // Enable debug panel
415
+ debugOptions: {
416
+ dark: true,
417
+ position: 'bottom-right',
418
+ },
419
+ })
420
+
421
+ // Debug panel is automatically injected into HTML responses
422
+ const html = await env.render('page.html', context)
423
+ ```
424
+
425
+ ### Features
426
+
427
+ - **Performance Metrics** - Lexer, Parser, Render timing with visual bars
428
+ - **Template Chain** - See extends/include hierarchy
429
+ - **Context Inspector** - Expandable tree view of all context variables
430
+ - **Filter Usage** - Which filters were used and how many times
431
+ - **Cache Stats** - Hit/miss rates
432
+ - **Warnings** - Optimization suggestions
433
+
434
+ ### Options
435
+
436
+ ```typescript
437
+ debugOptions: {
438
+ dark: true, // Dark/light theme
439
+ collapsed: true, // Start collapsed
440
+ position: 'bottom-right', // Panel position
441
+ width: 420, // Panel width
442
+ }
443
+ ```
444
+
445
+ ---
446
+
447
+ ## CLI Tool
448
+
449
+ Binja includes a CLI for template pre-compilation:
450
+
451
+ ```bash
452
+ # Compile all templates to JavaScript
453
+ binja compile ./templates -o ./dist
454
+
455
+ # Check templates for errors
456
+ binja check ./templates
457
+
458
+ # Watch mode for development
459
+ binja watch ./templates -o ./dist
460
+ ```
461
+
462
+ ### Pre-compiled Templates
463
+
464
+ ```typescript
465
+ // Generated: dist/home.js
466
+ import { render } from './dist/home.js'
467
+
468
+ const html = render({ title: 'Home', items: [...] })
469
+ ```
470
+
471
+ ---
472
+
473
+ ## Raw/Verbatim Tag
474
+
475
+ Output template syntax without processing:
476
+
477
+ ```django
478
+ {% raw %}
479
+ {{ this will not be processed }}
480
+ {% neither will this %}
481
+ {% endraw %}
482
+
483
+ {# Or Django-style #}
484
+ {% verbatim %}
485
+ {{ raw output }}
486
+ {% endverbatim %}
487
+ ```
488
+
489
+ ---
490
+
405
491
  ## Custom Filters
406
492
 
407
493
  ```typescript
@@ -556,8 +642,11 @@ env.loadTemplate(name) // Pre-load template (for cache warming)
556
642
  import { Elysia } from 'elysia'
557
643
  import { Environment } from 'binja'
558
644
 
645
+ // Development with debug panel
559
646
  const templates = new Environment({
560
647
  templates: './views',
648
+ debug: Bun.env.NODE_ENV !== 'production',
649
+ debugOptions: { dark: true },
561
650
  globals: {
562
651
  site_name: 'My App',
563
652
  current_year: new Date().getFullYear()
@@ -669,7 +758,13 @@ import { Hono } from 'hono'
669
758
  import { Environment } from 'binja'
670
759
 
671
760
  const app = new Hono()
672
- const templates = new Environment({ templates: './views' })
761
+
762
+ // Development with debug panel
763
+ const templates = new Environment({
764
+ templates: './views',
765
+ debug: process.env.NODE_ENV !== 'production',
766
+ debugOptions: { dark: true, position: 'bottom-right' }
767
+ })
673
768
 
674
769
  app.get('/', async (c) => {
675
770
  const html = await templates.render('index.html', {
package/dist/cli.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * binja CLI - Template pre-compilation tool
4
+ *
5
+ * Usage:
6
+ * binja compile <templates-dir> -o <output-dir>
7
+ * binja compile page.html -o dist/
8
+ * binja watch <templates-dir> -o <output-dir>
9
+ *
10
+ * Examples:
11
+ * binja compile ./templates -o ./dist/templates
12
+ * binja compile ./templates -o ./dist --minify
13
+ * binja compile ./views/home.html -o ./compiled --name renderHome
14
+ */
15
+ export {};
16
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;GAYG"}