wecodepixels/premailer-bundle

Symfony bundle for Premailer

This package's canonical repository appears to be gone and the package has been frozen as a result.

Installs: 15 335

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 5

Forks: 0

Open Issues: 0

Type:symfony-bundle

v0.1.0 2014-05-11 01:37 UTC

This package is not auto-updated.

Last update: 2021-10-11 11:49:01 UTC


README

This is a Symfony2 bundle for the Premailer project that uses the Premailer CLI (command line interface).

Prerequisites

You will have to install the Premailer gem as per the official instructions. At the time of writing, the following snippet works properly on a Ubuntu 12.04 LTS installation:

sudo apt-get install ruby-dev
sudo gem install premailer nokogiri

Installation

Download the bundle

If you are using Composer as your package manager, you can simply use:

composer require wecodepixels/premailer-bundle:dev-master

Or if you prefer to manually edit your composer.json file:

{
    "require": {
	    "wecodepixels/premailer-bundle": "dev-master"
    }
}

and then run composer update wecodepixels/premailer-bundle.

Enable the bundle

Add the bundle inside your AppKernel.php file:

<?php
// app/AppKernel.php

registerBundles()
{
    $bundles = array(
        // ...
		new WeCodePixels\PremailerBundle\WeCodePixelsPremailerBundle(),
    );
}

Required configuration

You will have to specify the Premailer binary inside your config.yml file (or config_dev.yml, config_prod.yml, etc.). Again, here is an example that works properly on a Ubuntu 12.04 LTS installation:

we_code_pixels_premailer:
    bin: /usr/bin/premailer

As a tip, you can locate your premailer binary by executing where premailer inside your console.

Usage

Here is a simple example:

$html = '<h1>My HTML which contains one or more style tags</h1>';
$premailer = $this->container->get('we_code_pixels_premailer.premailer');
$premailer->setRemoveClasses(true);
$htmlWithInlinedCss = $premailer->execute($html);

There are a few more setters available that are directly linked to the Premailer CLI options:

  • setMode
  • setBaseUrl
  • setQueryString
  • setCss
  • setRemoveClasses
  • setRemoveScripts
  • setLineLength
  • setEntities
  • setIoExceptions