Skip to content

Commit 263b83f

Browse files
committed
Placehlder replacers.
1 parent 0b88b07 commit 263b83f

21 files changed

+571
-1
lines changed

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:37:"PHPUnit\Runner\DefaultTestResultCache":693:{a:2:{s:7:"defects";a:2:{s:94:"Binarcode\LaravelMailator\Tests\Feature\Models\MailTemplateTest::test_can_create_mail_template";i:4;s:87:"Binarcode\LaravelMailator\Tests\Feature\Models\MailTemplateTest::test_can_send_template";i:4;}s:5:"times";a:4:{s:94:"Binarcode\LaravelMailator\Tests\Feature\Models\MailTemplateTest::test_can_create_mail_template";d:0.15;s:87:"Binarcode\LaravelMailator\Tests\Feature\Models\MailTemplateTest::test_can_send_template";d:0.111;s:102:"Binarcode\LaravelMailator\Tests\Feature\Models\MailatorScheduleTest::test_can_create_mailator_schedule";d:0.039;s:97:"Binarcode\LaravelMailator\Tests\Feature\Models\MailatorScheduleTest::test_sending_email_only_once";d:0.109;}}}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
"php": "^7.4",
2121
"illuminate/support": "^7.0",
2222
"opis/closure": "^3.5",
23-
"spatie/test-time": "^1.2"
23+
"tijsverkoyen/css-to-inline-styles": "^2.2"
2424
},
2525
"require-dev": {
2626
"friendsofphp/php-cs-fixer": "^2.16",
2727
"orchestra/testbench": "^5.0",
2828
"phpunit/phpunit": "^9.0",
29+
"spatie/test-time": "^1.2",
2930
"psalm/plugin-laravel": "^1.2",
3031
"vimeo/psalm": "^3.11"
3132
},

config/mailator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,18 @@
2929
],
3030

3131
'log_model' => Binarcode\LaravelMailator\Models\MailatorLog::class,
32+
33+
'templates' => [
34+
/**
35+
> The email layout, used to wrap the template.
36+
*/
37+
'laravel-mailator::mails.template_layout' => 'laravel-mailator::mails.template_layout',
38+
39+
/**
40+
> The default list with replacers for the template.
41+
*/
42+
'replacers' => [
43+
Binarcode\LaravelMailator\Replacers\SampleReplacer::class,
44+
],
45+
],
3246
];

database/migrations/create_mailator_tables.php.stub

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,34 @@ class CreateMailatorTables extends Migration
5656
->references('id')
5757
->on(config('mailator.schedulers_table_name', 'mailator_schedulers'));
5858
});
59+
60+
Schema::create('mail_templates', function (Blueprint $table) {
61+
$table->id();
62+
$table->uuid('uuid');
63+
64+
$table->string('name')->nullable();
65+
$table->string('from_email')->nullable();
66+
$table->string('from_name')->nullable();
67+
$table->string('subject')->nullable();
68+
69+
$table->longText('html')->nullable();
70+
$table->longText('email_html')->nullable();
71+
$table->longText('webview_html')->nullable();
72+
73+
$table->string('mailable_class')->nullable();
74+
$table->timestamps();
75+
});
76+
77+
Schema::create('mail_template_placeholders', function (Blueprint $table) {
78+
$table->id();
79+
$table->foreignId('mail_template_id')->constrained('mail_templates')->cascadeOnDelete();
80+
$table->string('name');
81+
$table->string('description');
82+
$table->json('meta')->nullable();
83+
$table->timestamps();
84+
85+
/** * Indexes */
86+
$table->index('mail_template_id');
87+
});
5988
}
6089
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ $template->getContent() ?? '' }}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6+
</head>
7+
<body>
8+
<style>
9+
@media only screen and (max-width: 600px) {
10+
.inner-body {
11+
width: 100% !important;
12+
}
13+
14+
.footer {
15+
width: 100% !important;
16+
}
17+
}
18+
19+
@media only screen and (max-width: 500px) {
20+
.button {
21+
width: 100% !important;
22+
}
23+
}
24+
</style>
25+
26+
<table class="wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation">
27+
<tr>
28+
<td align="center">
29+
<table class="content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
30+
{{ $header ?? '' }}
31+
32+
<!-- Email Body -->
33+
<tr>
34+
<td class="body" width="100%" cellpadding="0" cellspacing="0">
35+
<table class="inner-body" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation">
36+
<!-- Body content -->
37+
<tr>
38+
<td class="content-cell">
39+
40+
{{ $template->getContent() ?? '' }}
41+
42+
{{ $subcopy ?? '' }}
43+
</td>
44+
</tr>
45+
</table>
46+
</td>
47+
</tr>
48+
49+
{{ $footer ?? '' }}
50+
</table>
51+
</td>
52+
</tr>
53+
</table>
54+
</body>
55+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo iusto laudantium molestias quae ratione vitae? Architecto dignissimos inventore laudantium omnis? Beatae blanditiis ex neque obcaecati quos voluptate voluptatem. Ducimus, quo.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Binarcode\LaravelMailator\Actions;
4+
5+
use Binarcode\LaravelMailator\Models\MailTemplateable;
6+
use Binarcode\LaravelMailator\Replacers\Replacer;
7+
8+
class PersonalizeMailAction
9+
{
10+
public function execute($html, MailTemplateable $template, array $replacers): string
11+
{
12+
return collect($replacers)
13+
->filter(fn (object $class) => $class instanceof Replacer)
14+
->reduce(fn (string $html, Replacer $replacer) => $replacer->replace($html, $template), $html);
15+
}
16+
}
17+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Binarcode\LaravelMailator\Exceptions;
4+
5+
use Binarcode\LaravelMailator\Models\MailTemplateable;
6+
use Exception;
7+
8+
class InvalidTemplateException extends Exception
9+
{
10+
public static function throw(string $actual)
11+
{
12+
return new static('Expected instance of ' . MailTemplateable::class . ", given [$actual].");
13+
}
14+
}

src/Models/Concerns/WithUuid.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Binarcode\LaravelMailator\Models\Concerns;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Support\Str;
8+
9+
trait WithUuid
10+
{
11+
public static function bootWithUuid()
12+
{
13+
static::creating(function (Model $model) {
14+
if (! $model->uuid) {
15+
$model->setAttribute('uuid', Str::orderedUuid());
16+
}
17+
});
18+
}
19+
20+
public static function whereUuid(string $uuid): Builder
21+
{
22+
return static::query()->where('uuid', $uuid);
23+
}
24+
25+
public static function firstWhereUuid(string $uuid): Model
26+
{
27+
return static::where('uuid', $uuid)->firstOrFail();
28+
}
29+
}

0 commit comments

Comments
 (0)