Commit graph

25 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
435bb12ac3 Optimize expression evaluation to reduce allocations
- Implemented pooled slices for function arguments
- Added specialized pooling for variable node and literal node objects
- Modified array and hash node evaluation to reduce allocations
- Optimized test and filter evaluation with pooled resources
- Added comprehensive benchmarks to validate improvements
- Updated node pool implementation to remove duplicate declarations
- Fixed memory allocations in merge filter to correctly handle array manipulations

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-12 03:04:36 +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
f1add2d820 Implement efficient LRU eviction strategy for attribute cache
- Added tracking of last access time and access count to cache entries
- Implemented eviction policy to remove least recently/frequently used entries
- Cache now removes 10% of entries when the cache is full, prioritizing by usage
- Added benchmarks and tests to verify eviction strategy
- Fixed the previously ineffective eviction strategy
- Improved cache efficiency for applications with many diverse object types

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 14:20:47 +03:00
semihalev
520f70d8cc Optimize string handling and fix attribute cache
This commit introduces two major performance improvements:

1. Memory optimization in string handling
- Pre-allocates slice capacities to reduce reallocations
- Uses string builders with pre-allocated capacity
- Avoids unnecessary string concatenations and conversions
- Optimizes pattern matching code to reduce allocations
- Reuses memory for string slices where possible

2. Fixed unbounded attribute cache growth
- Added maximum cache size limit (1000 entries)
- Implemented simple cache eviction strategy
- Tracks current cache size with counter
- Prevents potential memory leaks in long-running applications

These changes significantly reduce memory allocations and improve
performance, especially for large templates.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 13:50:12 +03:00
semihalev
16c954898f Fix macro functionality and add comprehensive tests
- Fixed macro parameter parsing with improved tokenization handling
- Added support for proper module.function() syntax in templates
- Enhanced filter handling within macro variables
- Added support for variable interpolation in macro body
- Added comprehensive test suite for macros with various scenarios
- Improved overall coverage from 43.8% to 45.7%

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 13:15:07 +03:00
semihalev
a38fa8631a Fix array filters and add support for GetItemNode and array access
This commit fixes the TestArrayFilters tests by implementing proper support for array access and map literals in the template engine. Key improvements include:

1. Added support for GetItemNode to handle array access with square brackets
2. Implemented parseMapExpression to handle map/object literals with curly braces
3. Fixed string ordering in the Keys filter by adding proper sorting
4. Added support for array access in variable attributes
5. Improved the expression parsing to handle chained operators properly

These changes allow complex expressions like {{ people[0].name }} to work correctly
and ensure that array filters like sort, keys, and merge function properly.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 11:37:31 +03:00
semihalev
f7bb3e0d01 Improve regex handling for matches operator 2025-03-11 10:31:51 +03:00
semihalev
1915c0e8a1 Fix short-circuit evaluation for logical operators
This fixes expressions like {% if foo is defined and foo > 5 %} when foo is undefined.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 10:12:35 +03:00
semihalev
dee7b96067 Fix short-circuit evaluation in logical operators
- Implement proper short-circuit evaluation for 'and' and 'or' operators
- Fix issue with expressions like 'foo is defined and foo > 5' when foo is undefined
- Modify EvaluateExpression to skip evaluating right side of logical expressions when not needed
- Update documentation with findings and solutions

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-11 09:44:24 +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
98857eb47c Fix string rendering in scripts and JSON-style object handling in includes
- Enhance parseInclude to support JSON-style object literals with braces
- Add special handling for JavaScript values to ensure proper quoting
- Preserve CSS formatting for units, colors, and font-family values
- Fix type detection to avoid quoting numbers and booleans in scripts

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-10 13:09:56 +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
1148e71d11 Implement macro rendering functionality
- Added methods to execute macros and handle imported macros
- Implemented ImportNode and FromImportNode for template imports
- Added CallFunction method to support function and macro calls
- Enhanced PrintNode to handle callable macro results
- Updated parseMacro, parseImport, and parseFrom methods
- Added NullWriter for importing macros without output
- Fixed parser handling of endmacro tags

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-10 05:11:11 +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