moulder

A jQuery-like HTML templating library written in Java

License

License

GroupId

GroupId

com.plecting
ArtifactId

ArtifactId

moulder
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

moulder
A jQuery-like HTML templating library written in Java
Project URL

Project URL

http://github.com/jawher/moulder-j
Source Code Management

Source Code Management

https://github.com/jawher/moulder-j.git

Download moulder

How to add to project

<!-- https://jarcasting.com/artifacts/com.plecting/moulder/ -->
<dependency>
    <groupId>com.plecting</groupId>
    <artifactId>moulder</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.plecting/moulder/
implementation 'com.plecting:moulder:1.0.0'
// https://jarcasting.com/artifacts/com.plecting/moulder/
implementation ("com.plecting:moulder:1.0.0")
'com.plecting:moulder:jar:1.0.0'
<dependency org="com.plecting" name="moulder" rev="1.0.0">
  <artifact name="moulder" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.plecting', module='moulder', version='1.0.0')
)
libraryDependencies += "com.plecting" % "moulder" % "1.0.0"
[com.plecting/moulder "1.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.jsoup : jsoup jar 1.6.3

test (3)

Group / Artifact Type Version
junit : junit jar 4.8.2
org.mockito : mockito-all jar 1.8.5
xmlunit : xmlunit jar 1.3

Project Modules

There are no modules declared in this project.

Moulder-j

Build Status

A (relatively) tiny jQuery-like HTML templating library written in Java. In a nutshell, here's how to use moulder:

  1. parse a document
  2. select one or more elements (using jQuery's selectors syntax)
  3. apply one or more modifiers on the previous selection (add/remove/modify attribute, set text, repeat, ...)
  4. go back to 2 to alter as many other elements as needed
  5. profit !

Using this library

To use this library in your projects, just add the following to the dependencies section of your pom.xml (moulder is deployed in central):

<dependency>
  <groupId>com.plecting</groupId>
  <artifactId>moulder</artifactId>
  <version>1.0.0</version>
</dependency>

I've compiled some simple and elementary use cases in this gist, and some more complex and advanced use cases in this gist.

Here's a quick sample of how moulder can be used to manipulate html:

Given this markup:

<html>
    <body>
        <h1>dummy text to be replaced</h1>
    </body>
</html>

This moulder based snippet:

Document doc = Jsoup.parse(HTML);
MoulderShop m = new MoulderShop();

List<String> items = Arrays.asList("summer", "autumn", "winter", "spring");

m.register("h1",
        repeat(items.size()),
        text(seq(items)),
        attr("class", seq("even", "odd").cycle()),
        append("<p>content</p>")
);

m.process(doc);

Will generate the following:

<html>
    <head>
    </head>
    <body>
        <h1 class="even">Spring</h1>
        <p>content</p>
        <h1 class="odd">Summer</h1>
        <p>content</p>
        <h1 class="even">Autumn</h1>
        <p>content</p>
        <h1 class="odd">Winter</h1>
        <p>content</p>
    </body>
</html>

Or in plain english:

  • repeat the h1 element as many times as there are items in the list
  • For each generated h1 element, set it's class to even or odd
  • Also set it's text content to the corresponding season
  • And finally, append a paragraph after it

Building

You need a Java 5 (or newer) environment and Maven 3 installed:

$ mvn --version
Apache Maven 3.0-beta-1 (r935667; 2010-04-19 19:00:39+0200)
Java version: 1.6.0_20
Java home: /usr/lib/jvm/java-6-sun-1.6.0.20/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-22-generic" arch: "amd64" Family: "unix"

You should now be able to do a full build of ojaas:

$ git clone git://github.com/jawher/moulder-j.git
$ cd moulder-j
$ mvn clean install

Troubleshooting

Please consider using Github issues tracker to submit bug reports or feature requests.

License

See LICENSE for details.

Versions

Version
1.0.0