Last active
April 12, 2024 11:39
-
-
Save crabmusket/1f595e679c8f18d45a138d97be23d3e3 to your computer and use it in GitHub Desktop.
Revisions
-
crabmusket revised this gist
Aug 19, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,14 +27,14 @@ protected function buildView() ]; } protected function mjmlToHtml($mjml) { $exe = config('mjml.path', base_path('node_modules/.bin/mjml')); $command = "$exe --stdin --stdout --config.minify=true"; $timeout = config('mjml.timeout', 60); $process = new Process($command); $process->setInput($mjml); $process->setTimeout($timeout); try { -
crabmusket revised this gist
Aug 6, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ <mj-section> <mj-column> <mj-text> Hello {{$name}}! </mj-text> </mj-column> </mj-section> -
crabmusket revised this gist
Aug 6, 2018 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,8 +7,6 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; use App\Mail\MJML; class MJMLTestEmail extends Mailable -
crabmusket created this gist
Aug 6, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ <?php namespace App\Mail; use Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Exception\RuntimeException; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Support\HtmlString; trait MJML { /** * Provided for semantic clarity, and so that your emails break if you forget * to use the trait. */ public function mjml($view, $data = []) { return $this->view($view, $data); } protected function buildView() { $mjml = app(ViewFactory::class)->make($this->view, $this->viewData)->render(); return [ 'html' => new HTMLString($this->mjmlToHtml($mjml)), ]; } protected function mjmlToHtml($html) { $exe = config('mjml.path', base_path('node_modules/.bin/mjml')); $command = "$exe --stdin --stdout --config.minify=true"; $timeout = config('mjml.timeout', 60); $process = new Process($command); $process->setInput($content); $process->setTimeout($timeout); try { $process->mustRun(); } catch (RuntimeException $e) { // Process took too long throw $e; } catch (ProcessFailedException $e) { // Process returned an error result throw $e; } catch (\Exception $e) { // Not sure what happened throw $e; } return $process->getOutput(); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ <?php namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; use App\User; use App\Teams\TeamStatistics; use App\Mail\MJML; class MJMLTestEmail extends Mailable { use Queueable, SerializesModels, MJML; public function build() { return $this ->from('you@example.com') ->subject('Example') ->mjml('emails.mjml-test', [ 'name' => 'Joe Public', ]); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ <!-- resources/views/emails/mjml-test.blade.php --> <mjml> <mj-body> <mj-section> <mj-column> <mj-text> Hello {{name}}! </mj-text> </mj-column> </mj-section> </mj-body> </mjml>