Skip to content

Commit ae4e84a

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents e0f7722 + ef79693 commit ae4e84a

File tree

142 files changed

+4173
-2059
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+4173
-2059
lines changed

.github/dependabot.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: maven
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "09:00"
8+
open-pull-requests-limit: 10
9+
ignore:
10+
- dependency-name: org.springframework:spring-test
11+
versions:
12+
- ">= 5.a, < 6"
13+
- dependency-name: com.google.javascript:closure-compiler
14+
versions:
15+
- v20210106
16+
- v20210202
17+
- v20210302
18+
- dependency-name: org.eclipse.jetty:jetty-servlet
19+
versions:
20+
- 11.0.0
21+
- 11.0.1
22+
- dependency-name: org.eclipse.jetty:jetty-webapp
23+
versions:
24+
- 11.0.0
25+
- 11.0.1
26+
- dependency-name: org.eclipse.jetty:jetty-server
27+
versions:
28+
- 11.0.0
29+
- 11.0.1
30+
- dependency-name: org.yaml:snakeyaml
31+
versions:
32+
- "1.27"
33+
- dependency-name: org.apache.commons:commons-lang3
34+
versions:
35+
- "3.11"
36+
- dependency-name: org.apache.felix:maven-bundle-plugin
37+
versions:
38+
- 5.1.1

.github/workflows/build-matrix.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
java_version: [1.8, 11, 15, 17]
12+
os: [ubuntu-latest, windows-latest, macOS-latest]
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v1
17+
- name: Mustache Specs
18+
run: |
19+
git submodule update --init --recursive
20+
- name: Set up JDK ${{ matrix.java_version }}
21+
uses: actions/setup-java@v1
22+
with:
23+
java-version: ${{ matrix.java_version }}
24+
- name: Install
25+
run: mvn clean install -DskipTests --batch-mode --no-transfer-progress
26+
env:
27+
BUILD_PORT: 0
28+
BUILD_SECURE_PORT: 0
29+
- name: Build
30+
run: mvn clean package --batch-mode --no-transfer-progress
31+
env:
32+
BUILD_PORT: 0
33+
BUILD_SECURE_PORT: 0

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ dependency-reduced-pom.xml
2121
*.versionsBackup
2222
pom.xml.versionsBackup
2323

24-
jacoco.exec
24+
jacoco.exec
25+
26+
out

README.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
[![Become a Patreon](https://img.shields.io/badge/patreon-donate-orange.svg)](https://patreon.com/edgarespina)
2-
[![Build Status](https://travis-ci.org/jknack/handlebars.java.svg?branch=master)](https://travis-ci.org/jknack/handlebars.java)
3-
[![coveralls.io](https://img.shields.io/coveralls/jknack/handlebars.java.svg)](https://coveralls.io/r/jknack/handlebars.java?branch=master)
4-
[![codecov](https://codecov.io/gh/jknack/handlebars.java/branch/master/graph/badge.svg)](https://codecov.io/gh/jknack/handlebars.java)
52
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.jknack/handlebars/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.jknack/handlebars)
63
[![javadoc](https://javadoc.io/badge/com.github.jknack/handlebars.svg)](https://javadoc.io/doc/com.github.jknack/handlebars)
74

@@ -22,16 +19,21 @@ Output:
2219
Hello Handlebars.java!
2320
```
2421

25-
Handlebars.java is a Java port of [handlebars](http://handlebarsjs.com/).
22+
Handlebars.java is a Java port of [handlebars](https://handlebarsjs.com/).
2623

2724
Handlebars provides the power necessary to let you build semantic templates effectively with no frustration.
2825

29-
[Mustache](http://mustache.github.com/mustache.5.html) templates are compatible with Handlebars, so you can take a [Mustache](http://mustache.github.com) template, import it into Handlebars, and start taking advantage of the extra Handlebars features.
26+
[Mustache](https://mustache.github.io/mustache.5.html) templates are compatible with Handlebars, so you can take a [Mustache](https://mustache.github.io) template, import it into Handlebars, and start taking advantage of the extra Handlebars features.
27+
28+
# Requirements
29+
30+
- Handlebars 4.3+ requires Java 8 or higher.
31+
3032

3133
# Getting Started
32-
In general, the syntax of **Handlebars** templates is a superset of [Mustache](http://mustache.github.com) templates. For basic syntax, check out the [Mustache manpage](http://mustache.github.com).
34+
In general, the syntax of **Handlebars** templates is a superset of [Mustache](https://mustache.github.io) templates. For basic syntax, check out the [Mustache manpage](https://mustache.github.io).
3335

34-
The [Handlebars.java blog](http://jknack.github.io/handlebars.java) is a good place for getting started too. Javadoc is available at [javadoc.io](https://javadoc.io/doc/com.github.jknack/handlebars).
36+
The [Handlebars.java blog](https://jknack.github.io/handlebars.java) is a good place for getting started too. Javadoc is available at [javadoc.io](https://javadoc.io/doc/com.github.jknack/handlebars).
3537

3638
## Maven
3739
#### Stable version: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.jknack/handlebars/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.jknack/handlebars)
@@ -45,10 +47,6 @@ Handlebars provides the power necessary to let you build semantic templates effe
4547
</dependency>
4648
```
4749

48-
#### Development version
49-
50-
SNAPSHOT versions are NOT synchronized to Central. If you want to use a snapshot version you need to add the https://oss.sonatype.org/content/repositories/snapshots/ repository to your pom.xml.
51-
5250
### Loading templates
5351
Templates are loaded using the ```TemplateLoader``` class. Handlebars.java provides three implementations of a ```TemplateLoader```:
5452
* ClassPathTemplateLoader (default)
@@ -150,7 +148,7 @@ Example:
150148
or if you prefer YAML **myTemplates/home.yml**:
151149

152150
```yml
153-
list:
151+
items:
154152
- name: Handlebars.java rocks!
155153
```
156154
@@ -197,7 +195,7 @@ Please note you don't have to specify the extension file.
197195
* **conditional helpers**
198196

199197
### with, each, if, unless:
200-
See the [built-in helper documentation](http://handlebarsjs.com/block_helpers.html).
198+
See the [built-in helper documentation](https://handlebarsjs.com/guide/block-helpers.html).
201199

202200
### block and partial
203201
Block and partial helpers work together to provide you [Template Inheritance](http://jknack.github.io/handlebars.java/reuse.html).

TODO

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Java 15/17 Migration
2+
3+
- Replace pegdown with something else
4+
- Upgrade spring

handlebars-caffeine/pom.xml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<parent>
6+
<groupId>com.github.jknack</groupId>
7+
<artifactId>handlebars.java</artifactId>
8+
<version>4.3.1-SNAPSHOT</version>
9+
</parent>
10+
11+
<modelVersion>4.0.0</modelVersion>
12+
<groupId>com.github.jknack</groupId>
13+
<artifactId>handlebars-caffeine</artifactId>
14+
15+
<name>Handlebars Caffeine Cache</name>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.github.jknack</groupId>
20+
<artifactId>handlebars</artifactId>
21+
<version>${project.version}</version>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>com.github.ben-manes.caffeine</groupId>
26+
<artifactId>caffeine</artifactId>
27+
<version>2.9.2</version>
28+
</dependency>
29+
30+
<!-- Servlet API -->
31+
<dependency>
32+
<groupId>javax.servlet</groupId>
33+
<artifactId>servlet-api</artifactId>
34+
<scope>provided</scope>
35+
</dependency>
36+
37+
<!-- Test dependencies -->
38+
<dependency>
39+
<groupId>com.github.jknack</groupId>
40+
<artifactId>handlebars</artifactId>
41+
<version>${project.version}</version>
42+
<scope>test</scope>
43+
<classifier>tests</classifier>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>ch.qos.logback</groupId>
48+
<artifactId>logback-classic</artifactId>
49+
<scope>test</scope>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>junit</groupId>
54+
<artifactId>junit</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.mockito</groupId>
60+
<artifactId>mockito-core</artifactId>
61+
<scope>test</scope>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.apache.commons</groupId>
66+
<artifactId>commons-lang3</artifactId>
67+
<scope>test</scope>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>org.antlr</groupId>
72+
<artifactId>antlr4-runtime</artifactId>
73+
<version>4.9.2</version>
74+
<exclusions>
75+
<exclusion>
76+
<groupId>org.abego.treelayout</groupId>
77+
<artifactId>org.abego.treelayout.core</artifactId>
78+
</exclusion>
79+
</exclusions>
80+
<scope>test</scope>
81+
</dependency>
82+
83+
<dependency>
84+
<groupId>org.apache.commons</groupId>
85+
<artifactId>commons-text</artifactId>
86+
<scope>test</scope>
87+
</dependency>
88+
</dependencies>
89+
90+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Copyright (c) 2012-2015 Edgar Espina
3+
*
4+
* This file is part of Handlebars.java.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package com.github.jknack.handlebars.cache;
19+
20+
import static java.util.Objects.requireNonNull;
21+
22+
import java.io.IOException;
23+
import java.util.function.Function;
24+
25+
import com.github.benmanes.caffeine.cache.Cache;
26+
import com.github.jknack.handlebars.Handlebars;
27+
import com.github.jknack.handlebars.Parser;
28+
import com.github.jknack.handlebars.Template;
29+
import com.github.jknack.handlebars.io.TemplateSource;
30+
31+
/**
32+
* Caffeine template cache for handlebars.
33+
*
34+
* @author edgar
35+
* @since 4.3.0
36+
*/
37+
public class CaffeineTemplateCache implements TemplateCache {
38+
39+
/**
40+
* Internal cache.
41+
*/
42+
private final Cache<TemplateSource, Template> cache;
43+
44+
/**
45+
* Creates a new template cache.
46+
*
47+
* @param cache Cache.
48+
*/
49+
public CaffeineTemplateCache(final Cache<TemplateSource, Template> cache) {
50+
this.cache = requireNonNull(cache, "The cache is required.");
51+
}
52+
53+
@Override public void clear() {
54+
cache.invalidateAll();
55+
}
56+
57+
@Override public void evict(final TemplateSource source) {
58+
cache.invalidate(source);
59+
}
60+
61+
@Override public Template get(final TemplateSource source, final Parser parser) {
62+
return cache.get(source, parseTemplate(parser));
63+
}
64+
65+
/**
66+
* This method does nothing on Caffeine. Better option is to use a loading cache with a
67+
* eviction policy of your choice.
68+
*
69+
* Don't use this method.
70+
*
71+
* @param reload Ignored.
72+
* @return This template cache.
73+
*/
74+
@Override public TemplateCache setReload(final boolean reload) {
75+
// NOOP
76+
return this;
77+
}
78+
79+
private Function<? super TemplateSource, ? extends Template> parseTemplate(final Parser parser) {
80+
return source -> {
81+
try {
82+
return parser.parse(source);
83+
} catch (IOException ex) {
84+
throw Handlebars.Utils.propagate(ex);
85+
}
86+
};
87+
}
88+
}

0 commit comments

Comments
 (0)