Skip to content

Commit

Permalink
Merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
bkiers committed Oct 14, 2017
2 parents 6e92680 + 276a420 commit 83cdadd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Liqp   [![Build Status](https://travis-ci.org/bkiers/Liqp.png)](https://travis-ci.org/bkiers/Liqp)

A Java implementation of the [Liquid templating engine](http://wiki.shopify.com/Liquid) backed
up by an ANTLR grammar.
A Java implementation of the [Liquid templating engine](http://wiki.shopify.com/Liquid) backed
up by an ANTLR grammar.

## Installation

Expand All @@ -11,7 +11,7 @@ Add the dependency:

```groovy
dependencies {
compile 'nl.big-o:liqp:0.7.0'
compile 'nl.big-o:liqp:0.7.1'
}
```

Expand All @@ -23,7 +23,7 @@ Add the following dependency:
<dependency>
  <groupId>nl.big-o</groupId>
  <artifactId>liqp</artifactId>
  <version>0.7.0</version>
  <version>0.7.1</version>
</dependency>
```

Expand Down Expand Up @@ -58,9 +58,9 @@ Template template = Template.parse(input);
CommonTree root = template.getAST();
```

As you can see, the `getAST()` method returns an instance of a
[`CommonTree`](http://www.antlr.org/api/Java/org/antlr/runtime/tree/CommonTree.html) denoting the root
node of the input source. To see how the AST is built, you can use `Template#toStringAST()` to print
As you can see, the `getAST()` method returns an instance of a
[`CommonTree`](http://www.antlr.org/api/Java/org/antlr/runtime/tree/CommonTree.html) denoting the root
node of the input source. To see how the AST is built, you can use `Template#toStringAST()` to print
an ASCII representation of the tree:

```java
Expand Down Expand Up @@ -105,7 +105,7 @@ System.out.println(template.toStringAST());
'- PLAIN='</ul>'
*/
```
Checkout the [ANTLR grammar](https://github.com/bkiers/Liqp/blob/master/src/grammar/Liquid.g)
Checkout the [ANTLR grammar](https://github.com/bkiers/Liqp/blob/master/src/grammar/Liquid.g)
to see what the AST looks like for each of the parser rules.

## 2. Render Liquid
Expand All @@ -131,7 +131,7 @@ System.out.println(rendered);
```
The template variables provided as parameters to `render(...)` can be:

* a [varargs](http://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html) where
* a [varargs](http://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html) where
the 0<sup>th</sup>, 2<sup>nd</sup>, 4<sup>th</sup>, ... indexes must be `String` literals
denoting the keys. The values can be any `Object`.
* a `Map<String, Object>`
Expand Down Expand Up @@ -176,7 +176,7 @@ String rendered = template.render(); // no value for "name"

### 2.1 Custom filters

Let's say you want to create a custom filter, called `b`, that changes a string like
Let's say you want to create a custom filter, called `b`, that changes a string like
`*text*` to `<strong>text</strong>`.

You can do that as follows:
Expand Down Expand Up @@ -212,7 +212,7 @@ Filter.registerFilter(new Filter("repeat"){

// get the text of the value
String text = super.asString(value);

// check if an optional parameter is provided
int times = params.length == 0 ? 1 : super.asNumber(params[0]).intValue();

Expand Down Expand Up @@ -344,12 +344,12 @@ System.out.println(rendered);

### 2.3 Guards

If you're evaluating templates from untrusted sources, there are a couple of
If you're evaluating templates from untrusted sources, there are a couple of
ways you can guard against unwanted input.

For example, if you'd like the input template to be no larger than 125 characters,
the templating engine should not perform more than 15 iterations in total,
the generated string should not exceed 300 characters and the total rendering (and parsing!)
the generated string should not exceed 300 characters and the total rendering (and parsing!)
time should not exceed 100 milliseconds, you could do something like this:

```java
Expand All @@ -367,5 +367,5 @@ String rendered = Template.parse("{% for i in (1..10) %}{{ text }}{% endfor %}")
System.out.println(rendered);
```

Note that not providing a `ProtectionSettings`, is the same as not having any guards in
Note that not providing a `ProtectionSettings`, is the same as not having any guards in
place (or better, very large limits).
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<groupId>nl.big-o</groupId>
<artifactId>liqp</artifactId>
<packaging>jar</packaging>
<version>0.7.0</version>
<version>0.7.1</version>
<name>Liqp</name>
<description>A Java implementation of the Liquid templating engine backed up by an ANTLR grammar.</description>
<url>https://github.com/bkiers/Liqp</url>
Expand Down

0 comments on commit 83cdadd

Please sign in to comment.