|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Jinjava is a Java-based template engine that implements Django template syntax, adapted for rendering Jinja templates. It's used in production to render thousands of websites with hundreds of millions of page views on the HubSpot CMS. |
| 8 | + |
| 9 | +## Core Architecture |
| 10 | + |
| 11 | +### Main Components |
| 12 | +- **`Jinjava.java`** - Main API entry point for template rendering |
| 13 | +- **`JinjavaConfig.java`** - Configuration for template engine behavior |
| 14 | +- **`interpret/`** - Core interpretation engine including `JinjavaInterpreter` and `Context` |
| 15 | +- **`lib/`** - Template language features: |
| 16 | + - `tag/` - Template tags (if, for, extends, include, etc.) |
| 17 | + - `filter/` - Template filters for data transformation |
| 18 | + - `fn/` - Functions available in templates |
| 19 | + - `exptest/` - Expression tests (is defined, is even, etc.) |
| 20 | +- **`tree/`** - AST nodes and parsing (`TreeParser`, `ExpressionNode`, `TagNode`, etc.) |
| 21 | +- **`loader/`** - Template loading system (`ResourceLocator` implementations) |
| 22 | +- **`el/`** - Expression language evaluation with custom extensions |
| 23 | +- **`objects/`** - Python-like object wrappers (`PyList`, `PyMap`, `SafeString`, etc.) |
| 24 | + |
| 25 | +### Execution Modes |
| 26 | +- **Default mode** - Standard template execution |
| 27 | +- **Eager mode** - Advanced execution mode for handling deferred expressions and macro optimization |
| 28 | + - Located in `mode/EagerExecutionMode.java` and various `eager/` subdirectories |
| 29 | + - Complex system for optimizing template rendering with deferred value resolution |
| 30 | + |
| 31 | +## Development Commands |
| 32 | + |
| 33 | +### Building and Testing |
| 34 | +```bash |
| 35 | +# Build the project |
| 36 | +mvn clean compile |
| 37 | + |
| 38 | +# Run all tests |
| 39 | +mvn test |
| 40 | + |
| 41 | +# Run specific test |
| 42 | +mvn test -Dtest=TestClassName |
| 43 | + |
| 44 | +# Run test with debug output |
| 45 | +mvn test -Dtest=TestClassName -X |
| 46 | + |
| 47 | +# Package with shaded dependencies |
| 48 | +mvn clean package |
| 49 | + |
| 50 | +# Check code style |
| 51 | +mvn checkstyle:check |
| 52 | + |
| 53 | +# Run SpotBugs analysis |
| 54 | +mvn spotbugs:check |
| 55 | +``` |
| 56 | + |
| 57 | +### Code Quality |
| 58 | +The project uses: |
| 59 | +- **Checkstyle** - Code style validation (config in `checkstyle.xml`) |
| 60 | +- **SpotBugs** - Static analysis (exclusions in `spotbugs-exclude-filter.xml`) |
| 61 | +- **JaCoCo** - Test coverage reporting |
| 62 | + |
| 63 | +## Key Dependencies |
| 64 | +- **Guava** - Core utility library |
| 65 | +- **Immutables** - Immutable object generation with HubSpot style |
| 66 | +- **JUEL** - Expression language implementation (shaded) |
| 67 | +- **JSoup** - HTML parsing (shaded) |
| 68 | +- **Jackson** - JSON/YAML processing |
| 69 | +- **AssertJ** - Test assertions |
| 70 | +- **JUnit 4** - Testing framework |
| 71 | + |
| 72 | +## Template Engine Features |
| 73 | + |
| 74 | +### Template Loading |
| 75 | +Templates are loaded via `ResourceLocator` implementations: |
| 76 | +- `ClasspathResourceLocator` - Load from classpath |
| 77 | +- `FileLocator` - Load from filesystem |
| 78 | +- `CascadingResourceLocator` - Chain multiple locators |
| 79 | + |
| 80 | +### Custom Extensions |
| 81 | +The engine supports custom: |
| 82 | +- **Tags** - Implement `Tag` interface for custom template syntax |
| 83 | +- **Filters** - Implement `Filter` interface for data transformation |
| 84 | +- **Functions** - Register static methods as template functions |
| 85 | +- **Expression Tests** - Implement `ExpTest` interface for custom boolean tests |
| 86 | + |
| 87 | +### Security Considerations |
| 88 | +- Template paths are resolved through `ResourceLocator` to prevent unauthorized file access |
| 89 | +- Output size limits prevent memory exhaustion |
| 90 | +- Expression evaluation has recursion depth limits |
| 91 | + |
| 92 | +## Testing Strategy |
| 93 | +- Unit tests in `src/test/java/` mirror the main source structure |
| 94 | +- Integration tests use template files in `src/test/resources/` |
| 95 | +- Eager execution mode has extensive test coverage in `src/test/resources/eager/` |
| 96 | +- Test naming follows `itShouldDescribeExpectedBehavior()` pattern |
0 commit comments