Skip to content

Commit 1eab3e5

Browse files
committed
Fence code blocks with language
1 parent 6b5cece commit 1eab3e5

1 file changed

Lines changed: 103 additions & 93 deletions

File tree

README.md

Lines changed: 103 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ Performance:
3737

3838
Maven dependency information:
3939

40-
<dependency>
41-
<groupId>com.github.spullara.mustache.java</groupId>
42-
<artifactId>compiler</artifactId>
43-
<version>0.8.2</version>
44-
</dependency>
40+
```xml
41+
<dependency>
42+
<groupId>com.github.spullara.mustache.java</groupId>
43+
<artifactId>compiler</artifactId>
44+
<version>0.8.2</version>
45+
</dependency>
46+
```
4547

4648
Example template file:
4749

@@ -55,31 +57,33 @@ Example template file:
5557

5658
Might be powered by some backing code:
5759

58-
public class Context {
59-
List<Item> items() {
60-
return Arrays.asList(
61-
new Item("Item 1", "$19.99", Arrays.asList(new Feature("New!"), new Feature("Awesome!"))),
62-
new Item("Item 2", "$29.99", Arrays.asList(new Feature("Old."), new Feature("Ugly.")))
63-
);
64-
}
65-
66-
static class Item {
67-
Item(String name, String price, List<Feature> features) {
68-
this.name = name;
69-
this.price = price;
70-
this.features = features;
71-
}
72-
String name, price;
73-
List<Feature> features;
74-
}
75-
76-
static class Feature {
77-
Feature(String description) {
78-
this.description = description;
79-
}
80-
String description;
81-
}
82-
}
60+
```java
61+
public class Context {
62+
List<Item> items() {
63+
return Arrays.asList(
64+
new Item("Item 1", "$19.99", Arrays.asList(new Feature("New!"), new Feature("Awesome!"))),
65+
new Item("Item 2", "$29.99", Arrays.asList(new Feature("Old."), new Feature("Ugly.")))
66+
);
67+
}
68+
69+
static class Item {
70+
Item(String name, String price, List<Feature> features) {
71+
this.name = name;
72+
this.price = price;
73+
this.features = features;
74+
}
75+
String name, price;
76+
List<Feature> features;
77+
}
78+
79+
static class Feature {
80+
Feature(String description) {
81+
this.description = description;
82+
}
83+
String description;
84+
}
85+
}
86+
```
8387

8488
And would result in:
8589

@@ -95,77 +99,83 @@ And would result in:
9599
Evaluation of the template proceeds serially. For instance, if you have blocking code within one of your callbacks
96100
you the system will pause while executing them:
97101

98-
static class Feature {
99-
Feature(String description) {
100-
this.description = description;
101-
}
102+
```java
103+
static class Feature {
104+
Feature(String description) {
105+
this.description = description;
106+
}
102107

103-
String description() throws InterruptedException {
104-
Thread.sleep(1000);
105-
return description;
106-
}
107-
}
108+
String description() throws InterruptedException {
109+
Thread.sleep(1000);
110+
return description;
111+
}
112+
}
113+
```
108114

109115
If you change description to return a `Callable` instead it will automatically be executed in a separate
110116
thread if you have provided an `ExecutorService` when you created your `MustacheFactory`.
111117

112-
Callable<String> description() throws InterruptedException {
113-
return new Callable<String>() {
114-
@Override
115-
public String call() throws Exception {
116-
Thread.sleep(1000);
117-
return description;
118-
}
119-
};
120-
}
118+
```java
119+
Callable<String> description() throws InterruptedException {
120+
return new Callable<String>() {
121+
122+
@Override
123+
public String call() throws Exception {
124+
Thread.sleep(1000);
125+
return description;
126+
}
127+
};
128+
}
129+
```
121130

122131
This enables scheduled tasks, streaming behavior and asynchronous i/o. Check out the `example` module in order
123132
to see a complete end-to-end example:
124133

125-
package mustachejava;
126-
127-
import com.github.mustachejava.DefaultMustacheFactory;
128-
import com.github.mustachejava.Mustache;
129-
import com.github.mustachejava.MustacheFactory;
130-
131-
import java.io.IOException;
132-
import java.io.PrintWriter;
133-
import java.io.Writer;
134-
import java.util.Arrays;
135-
import java.util.List;
136-
137-
public class Example {
138-
139-
List<Item> items() {
140-
return Arrays.asList(
141-
new Item("Item 1", "$19.99", Arrays.asList(new Feature("New!"), new Feature("Awesome!"))),
142-
new Item("Item 2", "$29.99", Arrays.asList(new Feature("Old."), new Feature("Ugly.")))
143-
);
144-
}
145-
146-
static class Item {
147-
Item(String name, String price, List<Feature> features) {
148-
this.name = name;
149-
this.price = price;
150-
this.features = features;
151-
}
152-
153-
String name, price;
154-
List<Feature> features;
155-
}
156-
157-
static class Feature {
158-
Feature(String description) {
159-
this.description = description;
160-
}
161-
162-
String description;
163-
}
164-
165-
public static void main(String[] args) throws IOException {
166-
MustacheFactory mf = new DefaultMustacheFactory();
167-
Mustache mustache = mf.compile("template.mustache");
168-
mustache.execute(new PrintWriter(System.out), new Example()).flush();
169-
}
134+
```java
135+
package mustachejava;
136+
137+
import com.github.mustachejava.DefaultMustacheFactory;
138+
import com.github.mustachejava.Mustache;
139+
import com.github.mustachejava.MustacheFactory;
140+
141+
import java.io.IOException;
142+
import java.io.PrintWriter;
143+
import java.io.Writer;
144+
import java.util.Arrays;
145+
import java.util.List;
146+
147+
public class Example {
148+
149+
List<Item> items() {
150+
return Arrays.asList(
151+
new Item("Item 1", "$19.99", Arrays.asList(new Feature("New!"), new Feature("Awesome!"))),
152+
new Item("Item 2", "$29.99", Arrays.asList(new Feature("Old."), new Feature("Ugly.")))
153+
);
154+
}
155+
156+
static class Item {
157+
Item(String name, String price, List<Feature> features) {
158+
this.name = name;
159+
this.price = price;
160+
this.features = features;
170161
}
171162

163+
String name, price;
164+
List<Feature> features;
165+
}
166+
167+
static class Feature {
168+
Feature(String description) {
169+
this.description = description;
170+
}
171+
172+
String description;
173+
}
174+
175+
public static void main(String[] args) throws IOException {
176+
MustacheFactory mf = new DefaultMustacheFactory();
177+
Mustache mustache = mf.compile("template.mustache");
178+
mustache.execute(new PrintWriter(System.out), new Example()).flush();
179+
}
180+
}
181+
```

0 commit comments

Comments
 (0)