Skip to content

Commit 63e2ba6

Browse files
committed
Add docs and make Herb methods static
1 parent 8d8590e commit 63e2ba6

File tree

9 files changed

+455
-33
lines changed

9 files changed

+455
-33
lines changed

docs/.vitepress/config/theme.mts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ const defaultSidebar = [
9090
{ text: "Reference", link: "/bindings/javascript/reference" },
9191
],
9292
},
93+
{
94+
text: "Java",
95+
collapsed: false,
96+
items: [
97+
{ text: "Installation", link: "/bindings/java/" },
98+
{ text: "Reference", link: "/bindings/java/reference" },
99+
],
100+
},
93101
{ text: "WebAssembly", link: "/projects/webassembly" },
94102
],
95103
},

docs/docs/bindings/java/index.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# Herb Java Bindings
6+
7+
Herb provides official Java bindings through JNI (Java Native Interface) to the C library, allowing you to parse HTML+ERB in Java projects with native performance.
8+
9+
> [!TIP] More Language Bindings
10+
> Herb also has bindings for:
11+
> - [Ruby](/bindings/ruby/)
12+
> - [JavaScript/Node.js](/bindings/javascript/)
13+
14+
## Installation
15+
16+
### Prerequisites
17+
18+
Ensure you have Java installed:
19+
20+
:::code-group
21+
```shell
22+
java -version
23+
```
24+
:::
25+
26+
### Build from Source
27+
28+
Clone the repository and build the Java bindings:
29+
30+
:::code-group
31+
```shell
32+
git clone https://github.com/your-org/herb.git
33+
cd herb/java
34+
make templates
35+
make jni
36+
make java
37+
```
38+
:::
39+
40+
This creates the native library (`libherb_jni.dylib` on macOS, `.so` on Linux).
41+
42+
### Setting Up Your Project
43+
44+
Add the compiled classes to your classpath and ensure the native library is in your `java.library.path`.
45+
46+
## Getting Started
47+
48+
### Basic Example
49+
50+
Here's a simple example of parsing HTML+ERB:
51+
52+
:::code-group
53+
```java
54+
import org.herb.Herb;
55+
import org.herb.ParseResult;
56+
57+
public class Example {
58+
public static void main(String[] args) {
59+
String source = "<h1><%= user.name %></h1>";
60+
61+
ParseResult result = Herb.parse(source);
62+
63+
if (result.getValue() != null) {
64+
System.out.println(result.getValue().treeInspect());
65+
}
66+
}
67+
}
68+
```
69+
:::
70+
71+
### Lexing Example
72+
73+
You can also tokenize HTML+ERB source:
74+
75+
:::code-group
76+
```java
77+
import org.herb.Herb;
78+
import org.herb.LexResult;
79+
import org.herb.Token;
80+
81+
public class LexExample {
82+
public static void main(String[] args) {
83+
String source = "<h1><%= user.name %></h1>";
84+
85+
LexResult result = Herb.lex(source);
86+
87+
for (Token token : result.getTokens()) {
88+
System.out.println(token.inspect());
89+
}
90+
}
91+
}
92+
```
93+
:::

0 commit comments

Comments
 (0)