mirror of
https://github.com/semihalev/twig.git
synced 2026-03-14 13:55:46 +01:00
- Add support for whitespace control modifiers ({{-, -}}, {%-, -%})
- Implement {% spaceless %} tag for HTML whitespace removal
- Add token types for whitespace control tokens
- Improve text node handling to preserve spaces between words
- Add comprehensive tests for whitespace control features
- Update documentation in README.md and PROGRESS.md
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
3.8 KiB
3.8 KiB
Twig Implementation Progress
Completed Features
-
Parser Improvements
- Added parser support for function syntax with arguments
- Added parser support for new operators: 'is', 'is not', 'matches', 'starts with', 'ends with', 'not in'
- Added parser support for test conditions ('is defined', 'is empty', etc.)
- Added conditional expressions (ternary operators)
- Added array literal support
- Added evaluator implementations for the new node types
-
Full Filter Support
- Fixed filter parsing and evaluation to properly handle the pipe (
|) character in the tokenizer/parser - Ensured filter arguments are passed correctly to filter functions
- Implemented support for chained filters (e.g.,
var|filter1|filter2) - Verified comprehensive set of standard Twig filters work correctly:
- Text manipulation:
upper,lower,capitalize,trim, etc. - Array manipulation:
join,split,slice,sort, etc. - Type conversion:
length/count,keys, etc. - Formatting:
date,number_format, etc.
- Text manipulation:
- Added extensive tests for all filter functionality
- Fixed filter parsing and evaluation to properly handle the pipe (
-
Documentation
- Updated README with filter information and examples
- Added comprehensive test suite for filters with various use cases
Recent Improvements
-
Custom Filter and Function Registration
- Added
AddFilter()method to easily register custom filters - Added
AddFunction()method to easily register custom functions - Added
AddTest()method to register custom tests - Created
CustomExtensiontype for comprehensive extensions - Added
RegisterExtension()method for registering extension bundles - Created example application demonstrating custom extensions
- Added
-
Development Mode and Template Caching
- Added
SetDevelopmentMode()method that sets appropriate debug/cache settings - Added
SetDebug()andSetCache()methods for individual control - Improved template loading to respect cache settings
- Templates are not cached when cache is disabled
- Added tests to verify caching behavior
- Added
-
Template Modification Checking
- Added
TimestampAwareLoaderinterface for loaders that support modification time checking - Implemented modification time tracking in the
FileSystemLoader - Added cache invalidation based on file modification times
- Automatic template reloading when files change and auto-reload is enabled
- Updated Template struct to track the source loader and modification time
- Added comprehensive tests for file modification detection
- Added example application demonstrating auto-reload in action
- Added
-
Optimized Filter Chain Processing
- Implemented a specialized filter chain detection and evaluation algorithm
- Added support for detecting and processing filter chains in a single pass
- Reduced the number of intermediate allocations for chained filters
- Improved performance for templates with multiple filters applied to the same value
- Added tests and benchmarks to verify correctness and performance gains
Recent Improvements
- Whitespace Control Features
- Added support for whitespace control modifiers (
{{-,-}},{%-,-%}) - Implemented the
{% spaceless %}tag to remove whitespace between HTML tags - Added direct tokenizer support for whitespace control tokens
- Improved text handling to preserve spaces between words
- Added tests for all whitespace control features
- Added support for whitespace control modifiers (
Future Improvements
-
More Tests
- Add more comprehensive tests for edge cases
- Add more benchmarks for different template scenarios
-
Error Handling
- Improve error messages for filter-related issues
- Add better debugging support
-
Template Compilation
- Implement a compiled template format for even faster rendering
- Add the ability to pre-compile templates for production use