Skip to content

Commit

Permalink
Allow for per-mailable theme configuration.
Browse files Browse the repository at this point in the history
A “theme” property on the mailable will be used to determine the theme
on a per-mailable level if necessary.
  • Loading branch information
taylorotwell committed Mar 15, 2017
1 parent 02d9147 commit b2c35ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ protected function buildMarkdownView()
{
$markdown = Container::getInstance()->make(Markdown::class);

if (isset($this->theme)) {
$markdown->theme($this->theme);
}

$data = $this->buildViewData();

return [
Expand Down
13 changes: 13 additions & 0 deletions src/Illuminate/Mail/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,17 @@ public function loadComponentsFrom(array $paths = [])
{
$this->componentPaths = $paths;
}

/**
* Set the default theme to be used.
*
* @param string $theme
* @return $this
*/
public function theme($theme)
{
$this->theme = $theme;

return $this;
}
}
16 changes: 16 additions & 0 deletions tests/Mail/MailMarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ public function testRenderFunctionReturnsHtml()
$this->assertTrue(strpos($result, '<html></html>') !== false);
}

public function testRenderFunctionReturnsHtmlWithCustomTheme()
{
$viewFactory = \Mockery::mock('Illuminate\View\Factory');
$markdown = new \Illuminate\Mail\Markdown($viewFactory);
$markdown->theme('yaz');
$viewFactory->shouldReceive('flushFinderCache')->once();
$viewFactory->shouldReceive('replaceNamespace')->once()->with('mail', $markdown->htmlComponentPaths())->andReturnSelf();
$viewFactory->shouldReceive('make')->with('view', [])->andReturnSelf();
$viewFactory->shouldReceive('make')->with('mail::themes.yaz')->andReturnSelf();
$viewFactory->shouldReceive('render')->twice()->andReturn('<html></html>', 'body {}');

$result = $markdown->render('view', []);

$this->assertTrue(strpos($result, '<html></html>') !== false);
}

public function testRenderTextReturnsText()
{
$viewFactory = \Mockery::mock('Illuminate\View\Factory');
Expand Down

0 comments on commit b2c35ca

Please sign in to comment.