Carrot

Carrot is a Jinja-like templating library for Java.

Лицензия

Лицензия

Группа

Группа

au.com.codeka
Идентификатор

Идентификатор

carrot
Последняя версия

Последняя версия

2.4.5
Дата

Дата

Тип

Тип

jar
Описание

Описание

Carrot
Carrot is a Jinja-like templating library for Java.
Ссылка на сайт

Ссылка на сайт

https://github.com/codeka/carrot
Система контроля версий

Система контроля версий

https://github.com/codeka/carrot

Скачать carrot

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/au.com.codeka/carrot/ -->
<dependency>
    <groupId>au.com.codeka</groupId>
    <artifactId>carrot</artifactId>
    <version>2.4.5</version>
</dependency>
// https://jarcasting.com/artifacts/au.com.codeka/carrot/
implementation 'au.com.codeka:carrot:2.4.5'
// https://jarcasting.com/artifacts/au.com.codeka/carrot/
implementation ("au.com.codeka:carrot:2.4.5")
'au.com.codeka:carrot:jar:2.4.5'
<dependency org="au.com.codeka" name="carrot" rev="2.4.5">
  <artifact name="carrot" type="jar" />
</dependency>
@Grapes(
@Grab(group='au.com.codeka', module='carrot', version='2.4.5')
)
libraryDependencies += "au.com.codeka" % "carrot" % "2.4.5"
[au.com.codeka/carrot "2.4.5"]

Зависимости

runtime (1)

Идентификатор библиотеки Тип Версия
com.google.code.findbugs : jsr305 jar 3.0.1

Модули Проекта

Данный проект не имеет модулей.

Carrot

Build Status Code Coverage

Carrot is a templating library for Java that is similar to the Jinja library from python. Jinja -> Ginger -> Carrot, geddit?

It was originally a fork of http://jangod.googlecode.com/, but that project appears to be abandoned, so I've renamed it, and subsequently (in version 2.x) rewritten it.

Getting Started

With Maven:

<dependency>
  <groupId>au.com.codeka</groupId>
  <artifactId>carrot</artifactId>
  <version>2.4.5</version>
</dependency>

With Gradle:

compile 'au.com.codeka:carrot:2.4.5'

First, you need to create a CarrotEngine, which will hold the environment for parsing templates and processing them:

CarrotEngine engine = new CarrotEngine(new Configuration.Builder()
     .setResourceLocator(new FileResourceLocator.Builder("path/to/templates"))
     .build());

Typically, you'll have a "skeleton" template and a "body" template, where the skeleton defines the overall HTML structure that all your pages share, and the body template is the custom things just for that page. The way you do this is by having your body template extend the skeleton template, like so:

skeleton.html:

<!DOCTYPE html>
<html>
  <head>
    <title>{% block "title" %}{% end %}</title>
  </head>
  <body>
    {% block "content" %}{% end %}
  </body>
</html>

index.html:

{% extends "skeleton.html" %}
{% block "title" %}Hello World{% end %}
{% block "content" %}
  <h1>Hello, World!</h1>
{% end %}

Finally to process a template, you use the process method:

System.out.println(engine.process("index.html", new EmptyBindings()));

Now how do you actually pass data from your application to the template? That's what the bindings are for. Say you have the following in your template:

<p>Hello, {{ name }}!</p>

You'd pass data to that via Bindings, like so:

Map<String, Object> bindings = new TreeMap<>();
bindings.put("name", "Dean");
System.out.println(engine.process("index.html", new MapBindings(bindings)));

Documentation

The documentation is currently pretty sparse, but you can head over to codeka.github.io/carrot to view what there is. Please do not hesitate to open an issue if you have any questions.

Contributing

I love contributions! In general, follow the standard GitHub process for pull requests.

To build locally, you can just do:

gradlew build

Which will put a .jar in build/libs. From there just copy it to your project, test it and so on.

To build the documentation:

gradlew buildDocs

Which will put the docs in build/docs.

Версии библиотеки

Версия
2.4.5
2.4.4
2.4.3
2.4.2
2.4.1
2.4.0
2.3.0
2.2.2
2.2.1
2.2.0
2.1.0
2.0.0
1.0.1
1.0.0