Skip to content

Commit

Permalink
Merge branch '3.x'
Browse files Browse the repository at this point in the history
* 3.x:
  Updated the readme
  Fixed unit test and helper callback
  Added missing `use` statement.
  Bug fix.
  Required CakePHP.
  Updated Travis setup.
  Configured autoload for Composer.
  New Cake 3.x tests.
  Updated the helper.
  Remove Cake 2.x tests.
  Updated .editorconfig for Cake 3.x.

# Conflicts:
#	Test/Case/View/Helper/InlineCssHelperTest.php
#	View/Helper/InlineCssHelper.php
  • Loading branch information
drmonkeyninja committed Nov 30, 2016
2 parents 8405ace + c322ad6 commit 78859cf
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
root = true

[*]
indent_style = tab
indent_style = space
indent_size = 4
charset = "utf-8"
end_of_line = lf
Expand Down
48 changes: 28 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6

env:
global:
- PLUGIN_NAME=InlineCss
- REQUIRE=""
- DB=mysql CAKE_VERSION=2.4

matrix:
- DB=mysql CAKE_VERSION=2.4
- DB=mysql CAKE_VERSION=2.5
- DB=mysql CAKE_VERSION=2.6
- DB=mysql db_class='Cake\Database\Driver\Mysql' db_dsn='mysql:host=0.0.0.0;dbname=cakephp_test' db_database='cakephp_test' db_username='travis' db_password=''
global:
- DEFAULT=1

matrix:
fast_finish: true

include:
- php: 5.4
env:
- PHPCS=1
env: PHPCS=1 DEFAULT=0

- php: 5.5
env: COVERALLS=1 DEFAULT=0

allow_failures:
- php: 5.4
env:
- PHPCS=1
env: PHPCS=1 DEFAULT=0

before_script:
- git clone https://github.com/FriendsOfCake/travis.git --depth 1 ../travis
- ../travis/before_script.sh
- echo "require APP . 'vendor' . DS . 'autoload.php';" >> ../cakephp/app/Config/bootstrap.php
- composer self-update
- composer install --prefer-source --no-interaction --dev

script:
- ../travis/script.sh
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi"

- sh -c "if [ '$PHPCS' = '1' ]; then composer require --dev cakephp/cakephp-codesniffer=2.*; fi"

- sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi"
- sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi"

after_success:
- ../travis/after_success.sh
- phpenv rehash
- set +H
- cp phpunit.xml.dist phpunit.xml

script:
- sh -c "if [ '$COVERALLS' = '1' ]; then phpunit --coverage-clover build/logs/clover.xml; fi"
- sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi"
- sh -c "if [ '$DEFAULT' = '1' ]; then phpunit; fi"
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP --ignore=tests src/ ; fi"

notifications:
email: false
21 changes: 0 additions & 21 deletions Test/Case/AllInlineCssTest.php

This file was deleted.

37 changes: 0 additions & 37 deletions Test/Case/View/Helper/InlineCssHelperTest.php

This file was deleted.

48 changes: 0 additions & 48 deletions View/Helper/InlineCssHelper.php

This file was deleted.

13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@
}
],
"require": {
"cakephp/cakephp": "~3.0",
"tijsverkoyen/css-to-inline-styles": "^1.5"
},
"extra": {
"installer-name": "InlineCss"
"autoload": {
"psr-4": {
"InlineCss\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests",
"InlineCss\\Test\\": "tests"
}
}
}
43 changes: 43 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="App Test Suite">
<directory>./tests/TestCase</directory>
</testsuite>
<!-- Add plugin test suites here. -->
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>

<filter>
<blacklist>
<directory suffix=".php">./vendor/</directory>
<directory suffix=".ctp">./vendor/</directory>

<directory suffix=".php">./tests/</directory>
<directory suffix=".ctp">./tests/</directory>
</blacklist>
</filter>

</phpunit>
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ This plugin provides a CakePHP helper that uses [CssToInlineStyles](https://gith

## Requirements

* CakePHP 2.x
* CakePHP 3.x

## Installation

This plugin should be installed using Composer:-

```
composer require drmonkeyninja/cakephp-inline-css:2.0.*
composer require drmonkeyninja/cakephp-inline-css:3.0.*
```

Then add the following line to your bootstrap.php to load the plugin.

```php
CakePlugin::load('InlineCss.InlineCss');
Plugin::load('InlineCss');
```

## Usage

To use this plugin you want to load the `InlineCss` helper to use with your email's HTML template:-

```php
$Email = new CakeEmail();
$Email->template('welcome', 'fancy')
$email = new Email();
$email->template('welcome', 'fancy')
->emailFormat('html')
->helpers(array('InlineCss.InlineCss'))
->helpers(['InlineCss.InlineCss'])
->to('bob@example.com')
->from('app@domain.com')
->send();
Expand All @@ -53,4 +53,4 @@ It will be rendered as:-

This makes generating HTML emails a lot simpler as you can write your CSS in a more DRY approach.

I recommend you look consider deferring the sending of emails using something like the excellent [Queue plugin](https://github.com/dereuromark/cakephp-queue/tree/2.x) to improve your app's response time for users when using this plugin.
I recommend you look consider deferring the sending of emails using something like the excellent [Queue plugin](https://github.com/dereuromark/cakephp-queue) to improve your app's response time for users when using this plugin.
34 changes: 34 additions & 0 deletions src/View/Helper/InlineCssHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
namespace InlineCss\View\Helper;

use Cake\View\Helper;
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;

class InlineCssHelper extends Helper
{

/**
* After layout logic.
*
* @param \Cake\Event\Event $event Event
* @param string $layoutFile Layout filename
*/
public function afterLayout(\Cake\Event\Event $event, $layoutFile)
{
$content = $this->_View->Blocks->get('content');

if (!isset($this->InlineCss)) {
$this->InlineCss = new CssToInlineStyles();
}

// Convert inline style blocks to inline CSS on the HTML content.
$this->InlineCss->setHTML($content);
$this->InlineCss->setUseInlineStylesBlock(true);
$content = $this->InlineCss->convert();

$this->_View->Blocks->set('content', $content);

return;
}

}
32 changes: 32 additions & 0 deletions tests/TestCase/View/Helper/InlineCssHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace InlineCss\TestCase\View\Helper;

use Cake\Network\Request;
use Cake\TestSuite\TestCase;
use Cake\View\View;
use InlineCss\View\Helper\InlineCssHelper;

class InlineCssHelperTest extends TestCase
{

public $InlineCss = null;

public function setUp()
{
parent::setUp();

$this->View = new View(new Request());
$this->InlineCss = new InlineCssHelper($this->View);
}

public function testAfterLayout()
{
$this->View->Blocks->set('content', '<style type="text/css">a{color:red}</style><p><a href="#">Test</a></p>');

$this->InlineCss->afterLayout(new \Cake\Event\Event(''), null);

$expected = '<p><a href="#" style="color: red;">Test</a></p>';
$this->assertContains($expected, $this->View->Blocks->get('content'));
}

}
Loading

0 comments on commit 78859cf

Please sign in to comment.