Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mdedetrich/java-premailer-wrapper

Java wrapper for Premailer
https://github.com/mdedetrich/java-premailer-wrapper

Last synced: 9 days ago
JSON representation

Java wrapper for Premailer

Awesome Lists containing this project

README

        

# Java Premailer Wrapper

[![Maven Central](https://img.shields.io/maven-central/v/org.mdedetrich/java-premailer-wrapper?label=java-premailer-wrapper%40maven-central)](https://maven-badges.herokuapp.com/maven-central/org.mdedetrich/java-premailer-wrapper)

## What is this?

This java wrapper around [Premailer](https://github.com/premailer/premailer). It is roughly based on the
wrapper from [here](https://github.com/r-shah/java-premailer-wrapper), with a few important differences

- It works
- Premailer is brought in as a dependency rather than being directly included in the source. This allows you
to easily bump Premailer as a dependency
- Added a method that allows you to terminate a Premailer instance (`PremailerInterface.destroyInstance`)
- A fix for JDK 1.8 in regards to conflicts for `.merge ` method (see [here](https://github.com/jruby/jruby/issues/1249))
- The `Premailer` class no longer acts like a pseudo singleton. Its up to the user to manage the instance (typically you
would store this in a Singleton to reuse the `PremailerInstance`)
- Uses a versioning scheme to identify between Premailer releases, i.e. 1.0_1.8.7 means version 1 using Premailer 1.8.7

## Dependency Info

Currently hosted on maven central, with the following details

```xml

org.mdedetrich
java-premailer-wrapper
1.3_1.8.7

```

If you haven't already done so, you need to add the `Rubygems` maven repository, i.e.

```xml

rubygems-releases
http://rubygems-proxy.torquebox.org/releases

```

## Building

You can build a jar by doing

```
mvn compile
mvn package
```

## Usage

To use, do something like this

```java
String testHtml = "

test

";

// Create a Premailer
Premailer premailer = new Premailer()

// Get the instance
PremailerInterface premailerInterface = premailer.getPremailerInstance();

// Pass your options in form of HashMap
Map options = new HashMap( );

// Pass at least this option for html string
options.put( "with_html_string", true );

System.out.print( premailerInterface.plain_text(testHtml, options) );
System.out.print( premailerInterface.inline_css(testHtml, options) );

// Shut it down
premailer.destroyInstance();
```