{"id":31592943,"url":"https://github.com/hind-sagar-biswas/java-hypertext-preprocessor","last_synced_at":"2026-05-18T03:11:25.394Z","repository":{"id":318060319,"uuid":"1069862378","full_name":"hind-sagar-biswas/java-hypertext-preprocessor","owner":"hind-sagar-biswas","description":"A powerful, flexible template engine for Java applications. Inspired by PHP and modern template engines like Jinja2 and Blade, JHP provides an elegant syntax for embedding dynamic content in your HTML templates.","archived":false,"fork":false,"pushed_at":"2025-10-04T19:40:55.000Z","size":129,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-04T21:23:08.810Z","etag":null,"topics":["antlr4","hypertext-preprocessor","maven","preprocessor"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hind-sagar-biswas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-04T19:11:48.000Z","updated_at":"2025-10-04T19:40:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"4ac18617-7d96-4803-9886-f29d87a91eaf","html_url":"https://github.com/hind-sagar-biswas/java-hypertext-preprocessor","commit_stats":null,"previous_names":["hind-sagar-biswas/java-hypertext-preprocessor"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hind-sagar-biswas/java-hypertext-preprocessor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hind-sagar-biswas%2Fjava-hypertext-preprocessor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hind-sagar-biswas%2Fjava-hypertext-preprocessor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hind-sagar-biswas%2Fjava-hypertext-preprocessor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hind-sagar-biswas%2Fjava-hypertext-preprocessor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hind-sagar-biswas","download_url":"https://codeload.github.com/hind-sagar-biswas/java-hypertext-preprocessor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hind-sagar-biswas%2Fjava-hypertext-preprocessor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33163444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T22:39:12.733Z","status":"online","status_checked_at":"2026-05-18T02:00:06.436Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["antlr4","hypertext-preprocessor","maven","preprocessor"],"created_at":"2025-10-06T03:35:51.521Z","updated_at":"2026-05-18T03:11:25.371Z","avatar_url":"https://github.com/hind-sagar-biswas.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Java Hypertext Preprocessor (JHP)\n\n[![GitHub Packages](https://img.shields.io/badge/GitHub%20Packages-1.0.0-blue)](https://github.com/hind-sagar-biswas/java-hypertext-preprocessor/packages)\n[![Java](https://img.shields.io/badge/Java-25-orange.svg)](https://www.oracle.com/java/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n[![GitHub Release](https://img.shields.io/github/v/release/hind-sagar-biswas/java-hypertext-preprocessor?include_prereleases)](https://github.com/hind-sagar-biswas/java-hypertext-preprocessor/releases)\n\nA powerful, flexible template engine for Java applications. Inspired by PHP and modern template engines like Jinja2 and Blade, JHP provides an elegant syntax for embedding dynamic content in your HTML templates.\n\n## Features\n\n- **Intuitive Syntax** - Clean, readable template syntax with `{{ }}` for output and `{% %}` for logic\n- **HTML Escaping** - Automatic HTML escaping by default to prevent XSS attacks\n- **Control Structures** - Full support for if/else, for, foreach, and while loops\n- **Template Includes** - Modular templates with include directives\n- **Built-in Functions** - Common string and utility functions out of the box\n- **Extensible** - Easy to add custom functions\n- **Thread-Safe** - Built for concurrent environments\n- **Template Caching** - Automatic AST caching for improved performance\n- **Flexible Error Handling** - Multiple modes for handling runtime issues\n\n## Quick Start\n\n### Installation\n\nAdd the dependency to your `pom.xml`:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.hindbiswas.jhp\u003c/groupId\u003e\n    \u003cartifactId\u003ejhp\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nThe artifact is available on [Maven Central](https://search.maven.org/artifact/com.hindbiswas.jhp/jhp).\n\n### Basic Usage\n\n```java\nimport com.hindbiswas.jhp.*;\nimport com.hindbiswas.jhp.engine.*;\n\n// Create engine\nSettings settings = Settings.builder()\n    .base(\"/path/to/templates\")\n    .build();\nFunctionLibrary lib = new FunctionLibrary();\nJhpEngine engine = new JhpEngine(settings, lib);\n\n// Prepare context\nContext ctx = new Context();\nctx.add(\"name\", \"Alice\");\nctx.add(\"age\", 25);\n\n// Render template\nString output = engine.render(\"welcome.jhp\", ctx);\n```\n\n**Template (welcome.jhp):**\n```html\n\u003ch1\u003eHello {{ name }}!\u003c/h1\u003e\n{% if (age \u003e= 18) %}\n    \u003cp\u003eYou are an adult.\u003c/p\u003e\n{% else %}\n    \u003cp\u003eYou are a minor.\u003c/p\u003e\n{% endif %}\n```\n\n## Template Syntax\n\n### Output Variables\n\n```html\n{{ variable }}           \u003c!-- HTML-escaped output --\u003e\n{{{ rawHtml }}}         \u003c!-- Raw output (not escaped) --\u003e\n```\n\n### Control Structures\n\n```html\n\u003c!-- If Statement --\u003e\n{% if (condition) %}\n    Content\n{% elseif (otherCondition) %}\n    Other content\n{% else %}\n    Default content\n{% endif %}\n\n\u003c!-- For Loop --\u003e\n{% for (i = 0; i \u003c 10; i++) %}\n    \u003cp\u003eItem {{ i }}\u003c/p\u003e\n{% endfor %}\n\n\u003c!-- Foreach Loop --\u003e\n{% foreach (item in items) %}\n    \u003cli\u003e{{ item }}\u003c/li\u003e\n{% endforeach %}\n\n\u003c!-- Include Template --\u003e\n{% include 'header.jhp' %}\n```\n\n### Functions\n\n```html\n{{ touppercase(name) }}\n{{ tolowercase(email) }}\n{{ trim(input) }}\n{{ len(items) }}\n{{ now() }}\n```\n\n## Documentation\n\nComprehensive documentation is available in the [`docs/`](docs/) directory:\n\n- [Installation Guide](docs/installation.md)\n- [Getting Started](docs/getting-started.md)\n- [Template Syntax](docs/template-syntax.md)\n- [Control Structures](docs/control-structures.md)\n- [Functions](docs/functions.md)\n- [Context \u0026 Variables](docs/context-variables.md)\n- [Configuration](docs/configuration.md)\n- [Advanced Usage](docs/advanced-usage.md)\n- [API Reference](docs/api-reference.md)\n- [Examples](docs/examples.md)\n\n## Building from Source\n\n```bash\n# Clone the repository\ngit clone https://github.com/hind-sagar-biswas/java-hypertext-preprocessor.git\ncd java-hypertext-preprocessor\n\n# Build with Maven\nmvn clean install\n\n# Run tests\nmvn test\n```\n\n## Requirements\n\n- Java 25 or higher (Java 24 supported)\n- Maven 3.6+\n- ANTLR 4.13.2 (automatically managed)\n\n## Testing\n\nThe project includes comprehensive unit tests using JUnit Jupiter:\n\n```bash\nmvn test\n```\n\n**Test Coverage:**\n- 88 unit tests\n- Context and variable management\n- Settings and configuration\n- Function library (built-in and custom)\n- Template rendering and integration\n- AST node structures\n\n## Examples\n\n### Web Application\n\n```java\n@GetMapping(\"/profile/{username}\")\npublic ResponseEntity\u003cString\u003e profile(@PathVariable String username) {\n    User user = userService.findByUsername(username);\n    \n    Context ctx = new Context();\n    ctx.add(\"user\", user.toMap());\n    \n    String html = engine.render(\"profile.jhp\", ctx);\n    return ResponseEntity.ok().contentType(MediaType.TEXT_HTML).body(html);\n}\n```\n\n### Email Templates\n\n```java\npublic void sendWelcomeEmail(User user) throws Exception {\n    Context ctx = new Context();\n    ctx.add(\"userName\", user.getName());\n    ctx.add(\"activationLink\", generateActivationLink(user));\n    \n    String html = engine.render(\"welcome-email.jhp\", ctx);\n    emailClient.send(user.getEmail(), \"Welcome!\", html);\n}\n```\n\n### Custom Functions\n\n```java\nFunctionLibrary lib = new FunctionLibrary();\n\nlib.register(\"formatprice\", (args, scopes) -\u003e {\n    Number price = (Number) args.get(0);\n    return String.format(\"$%.2f\", price.doubleValue());\n});\n\nJhpEngine engine = new JhpEngine(settings, lib);\n```\n\n**Template:**\n```html\n\u003cspan class=\"price\"\u003e{{ formatprice(product.price) }}\u003c/span\u003e\n```\n\n## Configuration\n\n```java\nSettings settings = Settings.builder()\n    .base(\"/var/www/templates\")           // Base directory\n    .escape(true)                          // HTML escaping (default: true)\n    .maxIncludeDepth(15)                   // Max include depth (default: 15)\n    .issueHandleMode(IssueHandleMode.COMMENT)  // Error handling mode\n    .build();\n```\n\n### Issue Handling Modes\n\n- **COMMENT** - Render issues as HTML comments (default)\n- **THROW** - Throw exceptions for issues\n- **DEBUG** - Render detailed debug information\n- **IGNORE** - Silently ignore issues\n\n## Contributing\n\nContributions are welcome! Please feel free to submit pull requests or open issues.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Links\n\n- **Documentation**: [docs/](docs/)\n- **GitHub**: [java-hypertext-preprocessor](https://github.com/hind-sagar-biswas/java-hypertext-preprocessor/)\n- **Maven Central**: [com.hindbiswas.jhp:jhp](https://search.maven.org/artifact/com.hindbiswas.jhp/jhp)\n- **Issues**: [Issue Tracker](https://github.com/hind-sagar-biswas/java-hypertext-preprocessor/issues)\n- **Publishing Guide**: [PUBLISHING.md](PUBLISHING.md)\n- **Changelog**: [CHANGELOG.md](CHANGELOG.md)\n\n## Acknowledgments\n\nInspired by:\n- PHP's template syntax\n- Jinja2 (Python)\n- Blade (Laravel)\n- Twig (Symfony)\n\n---\n\nMade with ❤️ by [Hind Sagar Biswas](https://github.com/hind-sagar-biswas)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhind-sagar-biswas%2Fjava-hypertext-preprocessor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhind-sagar-biswas%2Fjava-hypertext-preprocessor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhind-sagar-biswas%2Fjava-hypertext-preprocessor/lists"}