Commit graph

19 commits

Author SHA1 Message Date
semihalev
0548a9d547 Indent format fixes 2025-03-12 20:49:11 +03:00
semihalev
2419e0e574 Fix relative path resolution for template loading
Fixed the issue with relative path resolution by:
1. Adding a directory field to Template struct to store template's path
2. Adding lastLoadedTemplate field to RenderContext to track template context
3. Updating Clone method to preserve lastLoadedTemplate reference
4. Setting lastLoadedTemplate in all render contexts to maintain path context

This ensures that when templates include/extend/import other templates
using relative paths (starting with ./ or ../), the paths are properly
resolved relative to the original template's location.
2025-03-12 12:51:51 +03:00
semihalev
76b01e2e6e Add template sandbox security feature
- Implement SecurityPolicy interface with function/filter/tag restrictions
- Add DefaultSecurityPolicy with sensible defaults for common operations
- Add sandboxed option to include tag for secure template inclusion
- Implement context-level sandbox flag and methods
- Add engine-level sandbox control methods
- Create comprehensive tests for sandbox functionality

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 23:08:48 +03:00
semihalev
f49f4fa09e Add sandbox support for templates
- Add sandboxed option to include tag
- Implement SecurityPolicy interface and DefaultSecurityPolicy
- Support restricting function calls, filters, and more in sandbox mode
- Add tests for sandbox functionality

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 22:37:06 +03:00
semihalev
4ff7381954 Add parent() function support for template inheritance
This commit implements the parent() function in the Twig template engine,
which allows child templates to access parent template block content when
overriding blocks. The implementation supports:

- Basic single-level parent() calls (child accessing parent content)
- Tracking of original block content through template inheritance chain
- Prevention of infinite recursion in parent() function calls
- Comprehensive test suite for parent() functionality

Future work may include full multi-level inheritance support for nested
parent() calls (child -> parent -> grandparent).

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 20:59:37 +03:00
semihalev
6fceb1c808 Implement comprehensive object and token pooling for zero memory footprint
This commit dramatically improves memory efficiency and performance by:

1. Adding object pooling for frequently allocated node types:
   - TextNode, PrintNode, RootNode, LiteralNode, VariableNode, IfNode, ForNode
   - Released nodes properly after rendering is complete

2. Implementing token pooling to reduce allocations during parsing:
   - Added token pool for all token creation sites
   - Optimized token slice allocation with capacity hints

3. Improved RenderContext and StringBuffer handling:
   - Better cleanup and resource management

Benchmark results show:
- 91% reduction in memory usage compared to Go's templates
- 60x performance improvement in rendering speed
- Consistently 2 allocations per operation for all node types

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 14:49:55 +03:00
semihalev
28fe6e66d9 Fix lock contention in template loading
This commit improves the template loading mechanism by:

1. Minimizing lock-holding time
   - Uses short read locks for initial cache check
   - Avoids holding locks during template loading and parsing operations
   - Acquires write lock only when necessary to update cache

2. Restructuring the template loading logic
   - Cleaner control flow with early returns
   - Better error handling
   - Prevents unnecessary lock acquisitions

These changes significantly reduce contention in concurrent environments
where many templates are loaded simultaneously, improving performance
for high-throughput scenarios.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 13:51:53 +03:00
semihalev
c663834595 Fix debug tests and improve debug functionality
1. Fixed and enabled previously skipped debug tests:
   - TestDebugConditionals
   - TestDebugErrorReporting
2. Added detailed logging for conditional evaluation
3. Enhanced error reporting for undefined variables and expressions
4. Added template name tracking for better error context
5. Fixed formatting issues in log messages
6. Updated debug flag handling across the engine
2025-03-11 12:48:58 +03:00
semihalev
cce67f94c9 Fix code style inconsistencies and update documentation
- Update documentation with negative step range workaround
- Document limitations and solutions in FINDINGS.md and SOLUTION.md
- Clean up code style and remove experimental files
- Optimize performance in core functions
- Fix whitespace and end-of-file newlines

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 09:29:12 +03:00
semihalev
9ce53ad0be Add HTML whitespace control and formatting enhancements
- Added configuration options for whitespace preservation in HTML
- Implemented proper spacing around HTML tags for readability
- Added special handling for script and style tags to preserve their content
- Improved detection of HTML content vs. plain text
- Added options to control HTML attribute formatting
- Fixed handling of quote marks in various contexts
- Added comprehensive tests for whitespace preservation

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-10 13:23:40 +03:00
semihalev
b9b0058c26 Enhance README with badges and comprehensive documentation
- Add status badges (Go Report Card, GoDoc, License, Release)
- Create a Table of Contents for better navigation
- Add Examples section with code samples from the repository
- Add new sections:
  - Installation Requirements
  - Running Tests
  - Compatibility with Twig PHP
  - Versioning Policy
  - Security Considerations
  - Contributing Guidelines
  - Roadmap
  - Community & Support

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-10 10:42:58 +03:00
semihalev
ecf7d709ad Improved error handling and added debugging tools
- Added enhanced error reporting with source context
- Implemented debug logging system with multiple verbosity levels
- Added memory pooling for render contexts and string buffers
- Implemented better error messages with template name and line information
- Fixed concurrency issues in template loading
- Added improved attribute reflection caching
- Created comprehensive tests for all new features
- Updated documentation with debugging examples

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-10 09:41:01 +03:00
semihalev
52693a0b4a Performance and stability improvements
- Fixed concurrency safety issues in template cache and loaders
- Implemented attribute access caching to reduce reflection usage
- Added memory pooling for render contexts and string buffers
- Improved error handling for more resilient template loading
- Added detailed benchmarks showing performance improvements
- Updated documentation with progress and improvements

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-10 09:33:05 +03:00
semihalev
f9b283c393 Add template compilation capabilities
- Implement a compiled template format using gob encoding
- Add methods to compile templates and load from compiled templates
- Create dedicated CompiledLoader for managing compiled templates
- Enable auto-reload support for compiled templates
- Add comprehensive tests including benchmarks
- Create example application for template compilation workflow
- Update documentation with compilation features and examples

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-10 09:21:20 +03:00
semihalev
c4faeb33d6 Add template auto-reload and optimize filter chain processing
- Implement template modification time tracking for auto-reload
- Add TimestampAwareLoader interface and implementation
- Improve caching with proper reload when files change
- Optimize filter chain processing for better performance
- Add benchmarks for filter chain optimization
- Update documentation with new features

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-10 08:34:47 +03:00
semihalev
640a8d1c4a Add filter support and custom extension API
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-10 08:16:49 +03:00
semihalev
98b21b8077 Fix lexer generator template issues
- Fixed escaped negation operators (\\!) that were causing syntax errors
- Fixed quoting issues in error message string format
- Replaced the templating approach with a direct file copy method
- Split the templates into separate files for better maintenance
- Updated code to use modern os package functions instead of deprecated ioutil
- Added token and lexer templates for generating parsing code
- Implemented set tag parser and node, allowing variable assignments in templates
- Added go:generate directives for code generation workflow

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-10 04:56:55 +03:00
semihalev
9537fc1085 Add control structures and template inheritance support 2025-03-10 04:24:51 +03:00
semihalev
647dcbe96b Initial Twig template engine implementation 2025-03-10 04:11:43 +03:00