{"id":13471955,"url":"https://github.com/neuland/jade4j","last_synced_at":"2025-05-15T22:11:59.669Z","repository":{"id":3032269,"uuid":"4052581","full_name":"neuland/jade4j","owner":"neuland","description":"a pug implementation written in Java (formerly known as jade)","archived":false,"fork":false,"pushed_at":"2022-05-20T20:52:34.000Z","size":2478,"stargazers_count":705,"open_issues_count":9,"forks_count":116,"subscribers_count":57,"default_branch":"master","last_synced_at":"2025-04-08T09:11:12.222Z","etag":null,"topics":[],"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/neuland.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-04-17T13:11:56.000Z","updated_at":"2024-11-21T15:18:59.000Z","dependencies_parsed_at":"2022-08-30T10:51:34.875Z","dependency_job_id":null,"html_url":"https://github.com/neuland/jade4j","commit_stats":null,"previous_names":[],"tags_count":57,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuland%2Fjade4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuland%2Fjade4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuland%2Fjade4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuland%2Fjade4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neuland","download_url":"https://codeload.github.com/neuland/jade4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254430331,"owners_count":22069909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-07-31T16:00:50.664Z","updated_at":"2025-05-15T22:11:54.659Z","avatar_url":"https://github.com/neuland.png","language":"Java","funding_links":[],"categories":["Java","Projects","项目","模板引擎"],"sub_categories":["Template Engine","模板引擎"],"readme":"[![Build Status](https://secure.travis-ci.org/neuland/jade4j.png?branch=master)](http://travis-ci.org/neuland/jade4j)\n# Attention: jade4j is now pug4j\nIn alignment with the javascript template engine we renamed jade4j to pug4j. You will find it under https://github.com/neuland/pug4j\nThis is also a new release which supports almost the entire pug 2 syntax.\n\nPlease report pug4j issues in the new repository.\n \n# jade4j - a jade implementation written in Java\njade4j's intention is to be able to process jade templates in Java without the need of a JavaScript environment, while being **fully compatible** with the original jade syntax.\n\n## Contents\n\n- [Example](#example)\n- [Syntax](#syntax)\n- [Usage](#usage)\n- [Simple static API](#simple-api)\n- [Full API](#api)\n    - [Caching](#api-caching)\n    - [Output Formatting](#api-output)\n    - [Filters](#api-filters)\n    - [Helpers](#api-helpers)\n    - [Model Defaults](#api-model-defaults)\n    - [Template Loader](#api-template-loader)\n- [Expressions](#expressions)\n- [Reserved Words](#reserved-words)\n- [Framework Integrations](#framework-integrations)\n- [Breaking Changes](#breaking-changes)\n- [Authors](#authors)\n- [License](#license)\n\n\n## Example\n\nindex.jade\n\n```\ndoctype html\nhtml\n  head\n    title= pageName\n  body\n    ol#books\n      for book in books\n        if book.available\n          li #{book.name} for #{book.price} €\n```\n\nJava model\n\n```java\nList\u003cBook\u003e books = new ArrayList\u003cBook\u003e();\nbooks.add(new Book(\"The Hitchhiker's Guide to the Galaxy\", 5.70, true));\nbooks.add(new Book(\"Life, the Universe and Everything\", 5.60, false));\nbooks.add(new Book(\"The Restaurant at the End of the Universe\", 5.40, true));\n\nMap\u003cString, Object\u003e model = new HashMap\u003cString, Object\u003e();\nmodel.put(\"books\", books);\nmodel.put(\"pageName\", \"My Bookshelf\");\n```\n\nRunning the above code through `String html = Jade4J.render(\"./index.jade\", model)` will result in the following output:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eMy Bookshelf\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003col id=\"books\"\u003e\n      \u003cli\u003eThe Hitchhiker's Guide to the Galaxy for 5,70 €\u003c/li\u003e\n      \u003cli\u003eThe Restaurant at the End of the Universe for 5,40 €\u003c/li\u003e\n    \u003c/ol\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Syntax\n\nWe have put up an [interactive jade documentation](http://naltatis.github.com/jade-syntax-docs/).\n\nSee also the original [visionmedia/jade documentation](https://github.com/visionmedia/jade#a6).\n\n## Usage\n\n### via Maven\n\nAs of release 0.4.1, we have changed maven hosting to sonatype. Using Github Maven Repository is no longer\nrequired.\n\nPlease be aware that we had to change the group id from 'de.neuland' to 'de.neuland-bfi' in order to\nmeet sonatype conventions for group naming.\n\nJust add following dependency definitions to your `pom.xml`.\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ede.neuland-bfi\u003c/groupId\u003e\n  \u003cartifactId\u003ejade4j\u003c/artifactId\u003e\n  \u003cversion\u003e1.3.2\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Build it yourself\n\nClone this repository ...\n\n```bash\ngit clone https://github.com/neuland/jade4j.git\n```\n\n... build it using `maven` ...\n\n```bash\ncd jade4j\nmvn install\n```\n\n... and use the `jade4j-1.x.x.jar` located in your target directory.\n\n\u003ca name=\"simple-api\"\u003e\u003c/a\u003e\n## Simple static API\n\nParsing template and generating template in one step.\n\n```java\nString html = Jade4J.render(\"./index.jade\", model);\n```\n\nIf you use this in production you would probably do the template parsing only once per template and call the render method with different models.\n\n```java\nJadeTemplate template = Jade4J.getTemplate(\"./index.jade\");\nString html = Jade4J.render(template, model);\n```\n\nStreaming output using a `java.io.Writer`\n\n```java\nJade4J.render(template, model, writer);\n```\n\n\u003ca name=\"api\"\u003e\u003c/a\u003e\n## Full API\n\nIf you need more control you can instantiate a `JadeConfiguration` object.\n\n```java\nJadeConfiguration config = new JadeConfiguration();\n\nJadeTemplate template = config.getTemplate(\"index\");\n\nMap\u003cString, Object\u003e model = new HashMap\u003cString, Object\u003e();\nmodel.put(\"company\", \"neuland\");\n\nconfig.renderTemplate(template, model);\n```\n\n\u003ca name=\"api-caching\"\u003e\u003c/a\u003e\n### Caching\n\nThe `JadeConfiguration` handles template caching for you. If you request the same unmodified template twice you'll get the same instance and avoid unnecessary parsing.\n\n```java\nJadeTemplate t1 = config.getTemplate(\"index.jade\");\nJadeTemplate t2 = config.getTemplate(\"index.jade\");\nt1.equals(t2) // true\n```\n\nYou can clear the template and expression cache by calling the following:\n\n```java\nconfig.clearCache();\n```\n\nFor development mode, you can also disable caching completely:\n\n```java\nconfig.setCaching(false);\n```\n\n\u003ca name=\"api-output\"\u003e\u003c/a\u003e\n### Output Formatting\n\nBy default, Jade4J produces compressed HTML without unneeded whitespace. You can change this behaviour by enabling PrettyPrint:\n\n```java\nconfig.setPrettyPrint(true);\n```\n\nJade detects if it has to generate (X)HTML or XML code by your specified [doctype](https://github.com/visionmedia/jade#a6-11).\n\nIf you are rendering partial templates that don't include a doctype jade4j generates HTML code. You can also set the `mode` manually:\n\n```\nconfig.setMode(Jade4J.Mode.HTML);   // \u003cinput checked\u003e\nconfig.setMode(Jade4J.Mode.XHTML);  // \u003cinput checked=\"true\" /\u003e\nconfig.setMode(Jade4J.Mode.XML);    // \u003cinput checked=\"true\"\u003e\u003c/input\u003e\n```\n\n\u003ca name=\"api-filters\"\u003e\u003c/a\u003e\n### Filters\n\nFilters allow embedding content like `markdown` or `coffeescript` into your jade template:\n\n    script\n      :coffeescript\n        sayHello -\u003e alert \"hello world\"\n\nwill generate\n\n    \u003cscript\u003e\n      sayHello(function() {\n        return alert(\"hello world\");\n      });\n    \u003c/script\u003e\n\njade4j comes with a `plain` and `cdata` filter. `plain` takes your input to pass it directly through, `cdata` wraps your content in `\u003c![CDATA[...]]\u003e`. You can add your custom filters to your configuration.\n\n    config.setFilter(\"coffeescript\", new CoffeeScriptFilter());\n\nTo implement your own filter, you have to implement the `Filter` Interface. If your filter doesn't use any data from the model you can inherit from the abstract `CachingFilter` and also get caching for free. See the [neuland/jade4j-coffeescript-filter](https://github.com/neuland/jade4j-coffeescript-filter) project as an example.\n\n\u003ca name=\"api-helpers\"\u003e\u003c/a\u003e\n### Helpers\n\nIf you need to call custom java functions the easiest way is to create helper classes and put an instance into the model.\n\n```java\npublic class MathHelper {\n    public long round(double number) {\n        return Math.round(number);\n    }\n}\n```\n\n```java\nmodel.put(\"math\", new MathHelper());\n```\n\nNote: Helpers don't have their own namespace, so you have to be careful not to overwrite them with other variables.\n\n```\np= math.round(1.44)\n```\n\n\u003ca name=\"api-model-defaults\"\u003e\u003c/a\u003e\n### Model Defaults\n\nIf you are using multiple templates you might have the need for a set of default objects that are available in all templates.\n\n```java\nMap\u003cString, Object\u003e defaults = new HashMap\u003cString, Object\u003e();\ndefaults.put(\"city\", \"Bremen\");\ndefaults.put(\"country\", \"Germany\");\ndefaults.put(\"url\", new MyUrlHelper());\nconfig.setSharedVariables(defaults);\n```\n\n\u003ca name=\"api-template-loader\"\u003e\u003c/a\u003e\n### Template Loader\n\nBy default, jade4j searches for template files in your work directory. By specifying your own `FileTemplateLoader`, you can alter that behavior. You can also implement the `TemplateLoader` interface to create your own.\n\n```java\nTemplateLoader loader = new FileTemplateLoader(\"/templates/\", \"UTF-8\");\nconfig.setTemplateLoader(loader);\n```\n\n\u003ca name=\"expressions\"\u003e\u003c/a\u003e\n## Expressions\n\nThe original jade implementation uses JavaScript for expression handling in `if`, `unless`, `for`, `case` commands, like this\n\n    - var book = {\"price\": 4.99, \"title\": \"The Book\"}\n    if book.price \u003c 5.50 \u0026\u0026 !book.soldOut\n      p.sale special offer: #{book.title}\n\n    each author in [\"artur\", \"stefan\", \"michael\"]\n      h2= author\n\nAs of version 0.3.0, jade4j uses [JEXL](http://commons.apache.org/jexl/) instead of [OGNL](http://en.wikipedia.org/wiki/OGNL) for parsing and executing these expressions.\n\nWe decided to switch to JEXL because its syntax and behavior is more similar to ECMAScript/JavaScript and so closer to the original jade.js implementation. JEXL runs also much faster than OGNL. In our benchmark, it showed a **performance increase by factor 3 to 4**.\n\nWe are using a slightly modified JEXL version which to have better control of the exception handling. JEXL now runs in a semi-strict mode, where non existing values and properties silently evaluate to `null`/`false` where as invalid method calls lead to a `JadeCompilerException`.\n\n\u003ca name=\"reserved-words\"\u003e\u003c/a\u003e\n## Reserved Words\n\nJEXL comes with the three builtin functions `new`, `size` and `empty`. For properties with this name the `.` notation does not work, but you can access them with `[]`.\n\n```\n- var book = {size: 540}\nbook.size // does not work\nbook[\"size\"] // works\n```\n\nYou can read more about this in the [JEXL documentation](http://commons.apache.org/proper/commons-jexl/reference/syntax.html#Language_Elements).\n\n\u003ca name=\"framework-integrations\"\u003e\u003c/a\u003e\n## Framework Integrations\n- [neuland/spring-jade4j](https://github.com/neuland/spring-jade4j) jade4j for Spring.\n- [jooby-jade](https://github.com/jooby-project/jooby/tree/master/jooby-jade) jade4j for [Jooby](http://jooby.org).\n- [vertx-web](http://vertx.io/docs/vertx-web/js/#_jade_template_engine) jade4j for [Vert.X](http://vertx.io/)\n\n\u003ca name=\"breaking-changes\"\u003e\u003c/a\u003e\n## Breaking Changes\n\n### 1.3.1\n- Fixed a mayor scoping bug in loops. Use this version and not 1.3.0\n\n### 1.3.0\n- setBasePath has been removed from JadeConfiguration. Set folderPath on FileTemplateLoader instead.\n- Scoping of variables in loops changed, so its more in line with jade. This could break your template.\n\n### 1.2.0\n- Breaking change in filter interface: if you use filters outside of the project, they need to be adapted to new interface\n\n### 1.0.0\nIn Version 1.0.0 we added a lot of features of JadeJs 1.11. There are also some Breaking Changes:\n- Instead of 'id = 5' you must use '- var id = 5'\n- Instead of 'h1(attributes, class = \"test\")' you must use 'h1(class= \"test\")\u0026attributes(attributes)'\n- Instead of '!!! 5' you must use 'doctype html'\n- Jade Syntax for Conditional Comments is not supported anymore\n- Thanks to rzara for contributing to issue-108\n\n\u003ca name=\"authors\"\u003e\u003c/a\u003e\n## Authors\n\n- Artur Tomas / [atomiccoder](https://github.com/atomiccoder)\n- Stefan Kuper / [planetk](https://github.com/planetk)\n- Michael Geers / [naltatis](https://github.com/naltatis)\n- Christoph Blömer / [chbloemer](https://github.com/chbloemer)\n\nSpecial thanks to [TJ Holowaychuk](https://github.com/visionmedia) the creator of jade!\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n## License\n\nThe MIT License\n\nCopyright (C) 2011-2019 [neuland Büro für Informatik](http://www.neuland-bfi.de/), Bremen, Germany\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuland%2Fjade4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneuland%2Fjade4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuland%2Fjade4j/lists"}