Skip to content

Commit

Permalink
check for view existence first
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 17, 2020
1 parent 58dc491 commit 5f78c90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Illuminate/Mail/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ public function render($view, array $data = [], $inliner = null)
'mail', $this->htmlComponentPaths()
)->make($view, $data)->render();

$theme = Str::contains($this->theme, '::')
? $this->theme
: 'mail::themes.'.$this->theme;
if ($this->view->exists($this->theme)) {
$theme = $this->theme;
} else {
$theme = Str::contains($this->theme, '::')
? $this->theme
: 'mail::themes.'.$this->theme;
}

return new HtmlString(($inliner ?: new CssToInlineStyles)->convert(
$contents, $this->view->make($theme, $data)->render()
Expand Down
4 changes: 3 additions & 1 deletion tests/Mail/MailMarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function testRenderFunctionReturnsHtml()
$markdown = new Markdown($viewFactory);
$viewFactory->shouldReceive('flushFinderCache')->once();
$viewFactory->shouldReceive('replaceNamespace')->once()->with('mail', $markdown->htmlComponentPaths())->andReturnSelf();
$viewFactory->shouldReceive('exists')->with('default')->andReturn(false);
$viewFactory->shouldReceive('make')->with('view', [])->andReturnSelf();
$viewFactory->shouldReceive('make')->with('mail::themes.default', [])->andReturnSelf();
$viewFactory->shouldReceive('render')->twice()->andReturn('<html></html>', 'body {}');
Expand All @@ -36,8 +37,9 @@ public function testRenderFunctionReturnsHtmlWithCustomTheme()
$markdown->theme('yaz');
$viewFactory->shouldReceive('flushFinderCache')->once();
$viewFactory->shouldReceive('replaceNamespace')->once()->with('mail', $markdown->htmlComponentPaths())->andReturnSelf();
$viewFactory->shouldReceive('exists')->with('yaz')->andReturn(true);
$viewFactory->shouldReceive('make')->with('view', [])->andReturnSelf();
$viewFactory->shouldReceive('make')->with('mail::themes.yaz', [])->andReturnSelf();
$viewFactory->shouldReceive('make')->with('yaz', [])->andReturnSelf();
$viewFactory->shouldReceive('render')->twice()->andReturn('<html></html>', 'body {}');

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

1 comment on commit 5f78c90

@sheldonkotyk
Copy link

@sheldonkotyk sheldonkotyk commented on 5f78c90 Jan 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @taylorotwell,

I ran into an edge case where I had a default.antlers.html file in my resources/views folder already from a statamic theme that I created. It found that file and used it instead of the default.css, causing the css in the email not to be added.

I'm wondering if it should be looking only for a css file instead if you want to continue looking in the resources/views folder.

Please sign in to comment.