This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Pug4j is a Java implementation of the Pug templating language (formerly Jade), providing full compatibility with Pug syntax without requiring a JavaScript environment. The project enables processing Pug templates in Java applications.
mvn compile- Compile source codemvn test- Run unit testsmvn verify- Run full test suite with integration testsmvn install- Build and install to local repositorymvn clean- Clean build artifacts
mvn test- Run all testsmvn --batch-mode --update-snapshots verify- Full verification with snapshot updates (used in CI)- Single test:
mvn test -Dtest=ClassName
./mvn-release.sh- Automated release script (requires GPG setup)
- Lexer (
lexer/): Tokenizes Pug template files into a stream of tokens - Parser (
parser/): Converts tokens into an Abstract Syntax Tree (AST) of nodes - Compiler (
compiler/): Transforms AST into HTML output with configurable formatting - Expression Handlers (
expression/): Evaluates expressions in templates- JexlExpressionHandler (default): Uses Apache Commons JEXL for JavaScript-like expressions
- GraalJsExpressionHandler (experimental): Uses GraalVM for native JavaScript execution
- Template Loaders (
template/): Handle template file loading from various sources - Filters (
filter/): Process embedded content (markdown, plain text, CDATA, etc.)
Pug4J: Main entry point for simple template renderingPugConfiguration: Central configuration object for advanced usagePugTemplate: Compiled template ready for rendering with different modelsPugModel: Model data container for template variables
Templates are loaded through a base path system:
- FileTemplateLoader: Loads from filesystem with configurable base directory
- ClasspathTemplateLoader: Loads from classpath resources
- ReaderTemplateLoader: Loads from Reader instances
Two expression evaluation strategies:
- JEXL (default): Faster, JavaScript-like syntax with some limitations
- GraalVM: True JavaScript compatibility but significantly slower
Built-in template caching using Caffeine cache:
- Templates cached by path and modification time
- Expression compilation results cached
- Configurable cache settings via PugConfiguration
- Extensive test suite with template files in
src/test/resources/ - Snapshot testing for output verification
- Benchmark tests using JMH framework
- Cross-platform testing (Windows/Linux) in CI
- Java 17+ required
- Core dependencies: Apache Commons (JEXL, IO, Lang, Text), Caffeine cache
- Optional: GraalVM for JavaScript expression handling
- Build: Maven 3.0+
- Package structure follows component boundaries
- Token classes in
lexer/token/ - AST node classes in
parser/node/ - Clear separation between lexing, parsing, and compilation phases
Configure expression handling via PugConfiguration:
// Default JEXL handler (recommended)
config.setExpressionHandler(new JexlExpressionHandler());
// GraalVM handler for JavaScript compatibility (slower)
config.setExpressionHandler(new GraalJsExpressionHandler());