File tree 12 files changed +228
-136
lines changed
12 files changed +228
-136
lines changed Original file line number Diff line number Diff line change 4
4
root = true
5
5
6
6
[* ]
7
- indent_style = tab
7
+ indent_style = space
8
8
indent_size = 4
9
9
charset = " utf-8"
10
10
end_of_line = lf
Original file line number Diff line number Diff line change 1
1
language : php
2
2
3
3
php :
4
- - 5.3
5
4
- 5.4
6
5
- 5.5
7
6
- 5.6
8
7
9
8
env :
10
- global :
11
- - PLUGIN_NAME=InlineCss
12
- - REQUIRE=""
13
- - DB=mysql CAKE_VERSION=2.4
14
-
15
9
matrix :
16
- - DB=mysql CAKE_VERSION=2.4
17
- - DB=mysql CAKE_VERSION=2.5
18
- - DB=mysql CAKE_VERSION=2.6
10
+ - 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=''
11
+ global :
12
+ - DEFAULT=1
19
13
20
14
matrix :
15
+ fast_finish : true
16
+
21
17
include :
22
18
- php : 5.4
23
- env :
24
- - PHPCS=1
19
+ env : PHPCS=1 DEFAULT=0
20
+
21
+ - php : 5.5
22
+ env : COVERALLS=1 DEFAULT=0
23
+
25
24
allow_failures :
26
25
- php : 5.4
27
- env :
28
- - PHPCS=1
26
+ env : PHPCS=1 DEFAULT=0
29
27
30
28
before_script :
31
- - git clone https://github.com/FriendsOfCake/travis.git --depth 1 ../travis
32
- - ../travis/before_script.sh
33
- - echo "require APP . 'vendor' . DS . 'autoload.php';" >> ../cakephp/app/Config/bootstrap.php
29
+ - composer self-update
30
+ - composer install --prefer-source --no-interaction --dev
34
31
35
- script :
36
- - ../travis/script.sh
32
+ - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi"
33
+
34
+ - sh -c "if [ '$PHPCS' = '1' ]; then composer require --dev cakephp/cakephp-codesniffer=2.*; fi"
35
+
36
+ - sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi"
37
+ - sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi"
37
38
38
- after_success :
39
- - ../travis/after_success.sh
39
+ - phpenv rehash
40
+ - set +H
41
+ - cp phpunit.xml.dist phpunit.xml
42
+
43
+ script :
44
+ - sh -c "if [ '$COVERALLS' = '1' ]; then phpunit --coverage-clover build/logs/clover.xml; fi"
45
+ - sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi"
46
+ - sh -c "if [ '$DEFAULT' = '1' ]; then phpunit; fi"
47
+ - sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP --ignore=tests src/ ; fi"
40
48
41
49
notifications :
42
50
email : false
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 12
12
}
13
13
],
14
14
"require" : {
15
+ "cakephp/cakephp" : " ~3.0" ,
15
16
"tijsverkoyen/css-to-inline-styles" : " ^1.5"
16
17
},
17
- "extra" : {
18
- "installer-name" : " InlineCss"
18
+ "autoload" : {
19
+ "psr-4" : {
20
+ "InlineCss\\ " : " src"
21
+ }
22
+ },
23
+ "autoload-dev" : {
24
+ "psr-4" : {
25
+ "Cake\\ Test\\ " : " ./vendor/cakephp/cakephp/tests" ,
26
+ "InlineCss\\ Test\\ " : " tests"
27
+ }
19
28
}
20
29
}
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <phpunit
3
+ colors =" true"
4
+ processIsolation =" false"
5
+ stopOnFailure =" false"
6
+ syntaxCheck =" false"
7
+ bootstrap =" ./tests/bootstrap.php"
8
+ >
9
+ <php >
10
+ <ini name =" memory_limit" value =" -1" />
11
+ <ini name =" apc.enable_cli" value =" 1" />
12
+ </php >
13
+
14
+ <!-- Add any additional test suites you want to run here -->
15
+ <testsuites >
16
+ <testsuite name =" App Test Suite" >
17
+ <directory >./tests/TestCase</directory >
18
+ </testsuite >
19
+ <!-- Add plugin test suites here. -->
20
+ </testsuites >
21
+
22
+ <!-- Setup a listener for fixtures -->
23
+ <listeners >
24
+ <listener
25
+ class =" \Cake\TestSuite\Fixture\FixtureInjector"
26
+ file =" ./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php" >
27
+ <arguments >
28
+ <object class =" \Cake\TestSuite\Fixture\FixtureManager" />
29
+ </arguments >
30
+ </listener >
31
+ </listeners >
32
+
33
+ <filter >
34
+ <blacklist >
35
+ <directory suffix =" .php" >./vendor/</directory >
36
+ <directory suffix =" .ctp" >./vendor/</directory >
37
+
38
+ <directory suffix =" .php" >./tests/</directory >
39
+ <directory suffix =" .ctp" >./tests/</directory >
40
+ </blacklist >
41
+ </filter >
42
+
43
+ </phpunit >
Original file line number Diff line number Diff line change @@ -6,31 +6,31 @@ This plugin provides a CakePHP helper that uses [CssToInlineStyles](https://gith
6
6
7
7
## Requirements
8
8
9
- * CakePHP 2 .x
9
+ * CakePHP 3 .x
10
10
11
11
## Installation
12
12
13
13
This plugin should be installed using Composer:-
14
14
15
15
```
16
- composer require drmonkeyninja/cakephp-inline-css:2 .0.*
16
+ composer require drmonkeyninja/cakephp-inline-css:3 .0.*
17
17
```
18
18
19
19
Then add the following line to your bootstrap.php to load the plugin.
20
20
21
21
``` php
22
- CakePlugin ::load('InlineCss. InlineCss');
22
+ Plugin ::load('InlineCss');
23
23
```
24
24
25
25
## Usage
26
26
27
27
To use this plugin you want to load the ` InlineCss ` helper to use with your email's HTML template:-
28
28
29
29
``` php
30
- $Email = new CakeEmail ();
31
- $Email ->template('welcome', 'fancy')
30
+ $email = new Email ();
31
+ $email ->template('welcome', 'fancy')
32
32
->emailFormat('html')
33
- ->helpers(array( 'InlineCss.InlineCss') )
33
+ ->helpers([ 'InlineCss.InlineCss'] )
34
34
->to('bob@example.com')
35
35
->from('app@domain.com')
36
36
->send();
@@ -53,4 +53,4 @@ It will be rendered as:-
53
53
54
54
This makes generating HTML emails a lot simpler as you can write your CSS in a more DRY approach.
55
55
56
- 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.
56
+ 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.
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace InlineCss \View \Helper ;
3
+
4
+ use Cake \View \Helper ;
5
+ use TijsVerkoyen \CssToInlineStyles \CssToInlineStyles ;
6
+
7
+ class InlineCssHelper extends Helper
8
+ {
9
+
10
+ /**
11
+ * After layout logic.
12
+ *
13
+ * @param \Cake\Event\Event $event Event
14
+ * @param string $layoutFile Layout filename
15
+ */
16
+ public function afterLayout (\Cake \Event \Event $ event , $ layoutFile )
17
+ {
18
+ $ content = $ this ->_View ->Blocks ->get ('content ' );
19
+
20
+ if (!isset ($ this ->InlineCss )) {
21
+ $ this ->InlineCss = new CssToInlineStyles ();
22
+ }
23
+
24
+ // Convert inline style blocks to inline CSS on the HTML content.
25
+ $ this ->InlineCss ->setHTML ($ content );
26
+ $ this ->InlineCss ->setUseInlineStylesBlock (true );
27
+ $ content = $ this ->InlineCss ->convert ();
28
+
29
+ $ this ->_View ->Blocks ->set ('content ' , $ content );
30
+
31
+ return ;
32
+ }
33
+
34
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace InlineCss \TestCase \View \Helper ;
3
+
4
+ use Cake \Network \Request ;
5
+ use Cake \TestSuite \TestCase ;
6
+ use Cake \View \View ;
7
+ use InlineCss \View \Helper \InlineCssHelper ;
8
+
9
+ class InlineCssHelperTest extends TestCase
10
+ {
11
+
12
+ public $ InlineCss = null ;
13
+
14
+ public function setUp ()
15
+ {
16
+ parent ::setUp ();
17
+
18
+ $ this ->View = new View (new Request ());
19
+ $ this ->InlineCss = new InlineCssHelper ($ this ->View );
20
+ }
21
+
22
+ public function testAfterLayout ()
23
+ {
24
+ $ this ->View ->Blocks ->set ('content ' , '<style type="text/css">a{color:red}</style><p><a href="#">Test</a></p> ' );
25
+
26
+ $ this ->InlineCss ->afterLayout (new \Cake \Event \Event ('' ), null );
27
+
28
+ $ expected = '<p><a href="#" style="color: red;">Test</a></p> ' ;
29
+ $ this ->assertContains ($ expected , $ this ->View ->Blocks ->get ('content ' ));
30
+ }
31
+
32
+ }
You can’t perform that action at this time.
0 commit comments