Giter Site home page Giter Site logo

vijayeluri / moulder-j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jawher/moulder-j

0.0 1.0 0.0 246 KB

A jQuery-like HTML templating library written in Java

Home Page: http://github.com/jawher/moulder-j

License: MIT License

Java 100.00%

moulder-j's Introduction

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.

moulder-j's People

Contributors

itoshkov avatar jawher avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.