Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dontgitit committed Aug 8, 2022
2 parents e0f7722 + ef79693 commit ae4e84a
Show file tree
Hide file tree
Showing 142 changed files with 4,173 additions and 2,059 deletions.
38 changes: 38 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: 2
updates:
- package-ecosystem: maven
directory: "/"
schedule:
interval: daily
time: "09:00"
open-pull-requests-limit: 10
ignore:
- dependency-name: org.springframework:spring-test
versions:
- ">= 5.a, < 6"
- dependency-name: com.google.javascript:closure-compiler
versions:
- v20210106
- v20210202
- v20210302
- dependency-name: org.eclipse.jetty:jetty-servlet
versions:
- 11.0.0
- 11.0.1
- dependency-name: org.eclipse.jetty:jetty-webapp
versions:
- 11.0.0
- 11.0.1
- dependency-name: org.eclipse.jetty:jetty-server
versions:
- 11.0.0
- 11.0.1
- dependency-name: org.yaml:snakeyaml
versions:
- "1.27"
- dependency-name: org.apache.commons:commons-lang3
versions:
- "3.11"
- dependency-name: org.apache.felix:maven-bundle-plugin
versions:
- 5.1.1
33 changes: 33 additions & 0 deletions .github/workflows/build-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build

on: [push]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
java_version: [1.8, 11, 15, 17]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- name: Checkout
uses: actions/checkout@v1
- name: Mustache Specs
run: |
git submodule update --init --recursive
- name: Set up JDK ${{ matrix.java_version }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java_version }}
- name: Install
run: mvn clean install -DskipTests --batch-mode --no-transfer-progress
env:
BUILD_PORT: 0
BUILD_SECURE_PORT: 0
- name: Build
run: mvn clean package --batch-mode --no-transfer-progress
env:
BUILD_PORT: 0
BUILD_SECURE_PORT: 0
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ dependency-reduced-pom.xml
*.versionsBackup
pom.xml.versionsBackup

jacoco.exec
jacoco.exec

out
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[![Become a Patreon](https://img.shields.io/badge/patreon-donate-orange.svg)](https://patreon.com/edgarespina)
[![Build Status](https://travis-ci.org/jknack/handlebars.java.svg?branch=master)](https://travis-ci.org/jknack/handlebars.java)
[![coveralls.io](https://img.shields.io/coveralls/jknack/handlebars.java.svg)](https://coveralls.io/r/jknack/handlebars.java?branch=master)
[![codecov](https://codecov.io/gh/jknack/handlebars.java/branch/master/graph/badge.svg)](https://codecov.io/gh/jknack/handlebars.java)
[![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)
[![javadoc](https://javadoc.io/badge/com.github.jknack/handlebars.svg)](https://javadoc.io/doc/com.github.jknack/handlebars)

Expand All @@ -22,16 +19,21 @@ Output:
Hello Handlebars.java!
```

Handlebars.java is a Java port of [handlebars](http://handlebarsjs.com/).
Handlebars.java is a Java port of [handlebars](https://handlebarsjs.com/).

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

[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.
[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.

# Requirements

- Handlebars 4.3+ requires Java 8 or higher.


# Getting Started
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).
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).

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).
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).

## Maven
#### 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)
Expand All @@ -45,10 +47,6 @@ Handlebars provides the power necessary to let you build semantic templates effe
</dependency>
```

#### Development version

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.

### Loading templates
Templates are loaded using the ```TemplateLoader``` class. Handlebars.java provides three implementations of a ```TemplateLoader```:
* ClassPathTemplateLoader (default)
Expand Down Expand Up @@ -150,7 +148,7 @@ Example:
or if you prefer YAML **myTemplates/home.yml**:

```yml
list:
items:
- name: Handlebars.java rocks!
```

Expand Down Expand Up @@ -197,7 +195,7 @@ Please note you don't have to specify the extension file.
* **conditional helpers**

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

### block and partial
Block and partial helpers work together to provide you [Template Inheritance](http://jknack.github.io/handlebars.java/reuse.html).
Expand Down
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Java 15/17 Migration

- Replace pegdown with something else
- Upgrade spring
90 changes: 90 additions & 0 deletions handlebars-caffeine/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars.java</artifactId>
<version>4.3.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars-caffeine</artifactId>

<name>Handlebars Caffeine Cache</name>

<dependencies>
<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.2</version>
</dependency>

<!-- Servlet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.9.2</version>
<exclusions>
<exclusion>
<groupId>org.abego.treelayout</groupId>
<artifactId>org.abego.treelayout.core</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Copyright (c) 2012-2015 Edgar Espina
*
* This file is part of Handlebars.java.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jknack.handlebars.cache;

import static java.util.Objects.requireNonNull;

import java.io.IOException;
import java.util.function.Function;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Parser;
import com.github.jknack.handlebars.Template;
import com.github.jknack.handlebars.io.TemplateSource;

/**
* Caffeine template cache for handlebars.
*
* @author edgar
* @since 4.3.0
*/
public class CaffeineTemplateCache implements TemplateCache {

/**
* Internal cache.
*/
private final Cache<TemplateSource, Template> cache;

/**
* Creates a new template cache.
*
* @param cache Cache.
*/
public CaffeineTemplateCache(final Cache<TemplateSource, Template> cache) {
this.cache = requireNonNull(cache, "The cache is required.");
}

@Override public void clear() {
cache.invalidateAll();
}

@Override public void evict(final TemplateSource source) {
cache.invalidate(source);
}

@Override public Template get(final TemplateSource source, final Parser parser) {
return cache.get(source, parseTemplate(parser));
}

/**
* This method does nothing on Caffeine. Better option is to use a loading cache with a
* eviction policy of your choice.
*
* Don't use this method.
*
* @param reload Ignored.
* @return This template cache.
*/
@Override public TemplateCache setReload(final boolean reload) {
// NOOP
return this;
}

private Function<? super TemplateSource, ? extends Template> parseTemplate(final Parser parser) {
return source -> {
try {
return parser.parse(source);
} catch (IOException ex) {
throw Handlebars.Utils.propagate(ex);
}
};
}
}
Loading

0 comments on commit ae4e84a

Please sign in to comment.