├── tests
├── stubs
│ ├── test
│ ├── inline
│ ├── displaynone
│ ├── inlinestyle
│ └── doctype
├── ServiceProviderTest.php
├── AbstractTestCase.php
├── CompilerTest.php
└── CompilerEngineTest.php
├── .gitignore
├── .editorconfig
├── .travis.yml
├── phpunit.xml.dist
├── LICENCE
├── src
├── InkyServiceProvider.php
├── InkyCompiler.php
└── InkyCompilerEngine.php
├── composer.json
└── readme.md
/tests/stubs/test:
--------------------------------------------------------------------------------
1 | testy
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor
2 | composer.lock
--------------------------------------------------------------------------------
/tests/stubs/inline:
--------------------------------------------------------------------------------
1 |
2 |
testy
3 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*.php]
4 | indent_style = space
5 | indent_size = 4
--------------------------------------------------------------------------------
/tests/stubs/displaynone:
--------------------------------------------------------------------------------
1 |
6 | testy
7 |
--------------------------------------------------------------------------------
/tests/stubs/inlinestyle:
--------------------------------------------------------------------------------
1 |
6 | testy
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | notifications:
4 | email: false
5 |
6 | php:
7 | - 5.6
8 | - 7.0
9 | - 7.1
10 | - 7.2
11 |
12 | sudo: false
13 |
14 | cache:
15 | directories:
16 | - vendor
17 |
18 | install:
19 | - travis_retry composer install --no-interaction --prefer-source
20 |
21 | script:
22 | - vendor/bin/phpunit
--------------------------------------------------------------------------------
/tests/ServiceProviderTest.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | test
9 |
10 |
--------------------------------------------------------------------------------
/tests/AbstractTestCase.php:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 | ./tests
15 |
16 |
17 |
18 |
19 | ./src
20 |
21 |
22 |
--------------------------------------------------------------------------------
/LICENCE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Pete Cooper
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/InkyServiceProvider.php:
--------------------------------------------------------------------------------
1 | registerExtension();
17 | }
18 |
19 | /**
20 | * Register the application services.
21 | *
22 | * @return void
23 | */
24 | public function register()
25 | {
26 | $app = $this->app;
27 | $resolver = $app['view.engine.resolver'];
28 |
29 | $app->singleton('inky.compiler', function ($app) {
30 | $cache = $app['config']['view.compiled'];
31 |
32 | return new InkyCompiler($app['blade.compiler'], $app['files'], $cache);
33 | });
34 |
35 | $resolver->register('inky', function () use ($app) {
36 | return new InkyCompilerEngine($app['inky.compiler'], $app['files']);
37 | });
38 | }
39 |
40 | protected function registerExtension()
41 | {
42 | $this->app['view']->addExtension('inky.php', 'inky');
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "petecoop/laravel-inky",
3 | "description": "Foundation Inky email templates in Laravel",
4 | "keywords": ["foundation", "inky", "laravel"],
5 | "license": "MIT",
6 | "authors": [
7 | {
8 | "name": "petecoop",
9 | "email": "pete@petecoop.co.uk"
10 | }
11 | ],
12 | "require": {
13 | "hampe/inky": "^1.3.6.2",
14 | "illuminate/support": "~5.1",
15 | "illuminate/view": "~5.1",
16 | "symfony/css-selector": "^2.7|^3.0|^4.0",
17 | "symfony/dom-crawler": "^2.7|^3.0|^4.0",
18 | "tijsverkoyen/css-to-inline-styles": "^2.2"
19 | },
20 | "require-dev": {
21 | "graham-campbell/testbench": "^3.3",
22 | "phpunit/phpunit": "~5.4",
23 | "mockery/mockery": "^0.9.5"
24 | },
25 | "autoload": {
26 | "psr-4": {
27 | "Petecoop\\LaravelInky\\": "src"
28 | }
29 | },
30 | "autoload-dev": {
31 | "psr-4": {
32 | "Petecoop\\Tests\\LaravelInky\\": "tests"
33 | }
34 | },
35 | "extra": {
36 | "laravel": {
37 | "providers": [
38 | "Petecoop\\LaravelInky\\InkyServiceProvider"
39 | ]
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/InkyCompiler.php:
--------------------------------------------------------------------------------
1 | blade = $blade;
20 | $this->inky = new Inky();
21 | }
22 |
23 | public function compile($path = null)
24 | {
25 | if ($path) {
26 | $this->setPath($path);
27 | }
28 |
29 | if (!is_null($this->cachePath)) {
30 | $contents = $this->compileString($this->files->get($this->getPath()));
31 |
32 | $this->files->put($this->getCompiledPath($this->getPath()), $contents);
33 | }
34 | }
35 |
36 | public function getPath()
37 | {
38 | return $this->path;
39 | }
40 |
41 | public function setPath($path)
42 | {
43 | $this->path = $path;
44 | }
45 |
46 | public function compileString($value)
47 | {
48 | return $this->blade->compileString($this->inky->releaseTheKraken($value));
49 | }
50 |
51 | public function getFiles()
52 | {
53 | return $this->files;
54 | }
55 |
56 | public function getBlade()
57 | {
58 | return $this->blade;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/InkyCompilerEngine.php:
--------------------------------------------------------------------------------
1 | files = $files;
19 | }
20 |
21 | public function get($path, array $data = [])
22 | {
23 | $results = parent::get($path, $data);
24 |
25 | $crawler = new Crawler();
26 | $crawler->addHtmlContent($results);
27 |
28 | $stylesheets = $crawler->filter('link[rel=stylesheet]');
29 |
30 | // collect hrefs
31 | $stylesheetsHrefs = collect($stylesheets->extract('href'));
32 |
33 | // remove links
34 | $stylesheets->each(function (Crawler $crawler) {;
35 | foreach ($crawler as $node) {
36 | $node->parentNode->removeChild($node);
37 | }
38 | });
39 |
40 | $results = $crawler->html();
41 |
42 | // get the styles
43 | $files = $this->files;
44 | $styles = $stylesheetsHrefs->map(function ($stylesheet) use ($files) {
45 | $path = resource_path('assets/css/' . $stylesheet);
46 | return $files->get($path);
47 | })->implode("\n\n");
48 |
49 | $inliner = new CssToInlineStyles();
50 | return $inliner->convert($results, $styles);
51 | }
52 |
53 | public function getFiles()
54 | {
55 | return $this->files;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Not Maintained
2 | I'd recommend using the maintained fork: https://github.com/rsvpify/laravel-inky which supports the latest versions of Laravel.
3 |
4 | #
5 |
6 | Allows you to use Foundation's [Inky](http://foundation.zurb.com/emails/docs/inky.html) email templates nicely in Laravel 5.
7 |
8 | Any views with a `.inky.php` extension will be compiled with both Inky and Blade, allowing you to use both templating engines seamlessly together. CSS is automatically inlined so styles work in email clients that don't support external stylesheets.
9 |
10 | ## Installation
11 |
12 | Require with composer.
13 | ```
14 | composer require petecoop/laravel-inky
15 | ```
16 |
17 | Once installed, you'll need to register the service provider. Open `config/app.php` and add to the `providers` key:
18 |
19 | ```
20 | Petecoop\LaravelInky\InkyServiceProvider::class
21 | ```
22 |
23 | ## Usage
24 |
25 | Check the [Foundation for Emails docs](http://foundation.zurb.com/emails/docs/index.html) for full usage on how to use Inky and Foundation for Emails CSS.
26 |
27 | Create an Inky view e.g. `emails/welcome.inky.php`
28 |
29 | ```blade
30 |
31 |
32 | Welcome, {{ $name }}
33 |
34 |
35 | ```
36 |
37 | Use `Mail` as usual in Laravel
38 |
39 | ```php
40 | Mail::send('emails.welcome', ['name' => $user->name], function ($m) use ($user) {
41 | $m->from('hello@app.com', 'Your Application');
42 |
43 | $m->to($user->email, $user->name)->subject('Welcome!');
44 | });
45 | ```
46 |
47 | You can create a Blade layout to inherit from e.g. `emails/layout.inky.php`
48 |
49 | ```blade
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | @yield('content')
59 |
60 |
61 | ```
62 |
63 | then
64 |
65 | ```blade
66 | @extends('emails.layout')
67 |
68 | @section('content')
69 |
70 |
71 | Welcome, {{ $name }}
72 |
73 |
74 | @stop
75 | ```
76 |
77 | ### CSS Inlining
78 |
79 | `