Skip to content

Commit

Permalink
[8.x] Fix auto-generated Markdown views (#39565)
Browse files Browse the repository at this point in the history
* Fix auto-generated Markdown views

* formatting

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
jbrooksuk and taylorotwell authored Nov 10, 2021
1 parent 34e7d50 commit ff56967
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/Illuminate/Foundation/Console/MailMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function handle()
return;
}

if ($this->hasOption('markdown')) {
if ($this->option('markdown') !== false) {
$this->writeMarkdownTemplate();
}
}
Expand All @@ -55,14 +55,8 @@ public function handle()
*/
protected function writeMarkdownTemplate()
{
$view = $this->option('markdown');

if (! $view) {
$view = 'mail.'.Str::kebab(class_basename($this->argument('name')));
}

$path = $this->viewPath(
str_replace('.', '/', $view).'.blade.php'
str_replace('.', '/', $this->getView()).'.blade.php'
);

if (! $this->files->isDirectory(dirname($path))) {
Expand All @@ -82,13 +76,29 @@ protected function buildClass($name)
{
$class = parent::buildClass($name);

if ($this->option('markdown')) {
$class = str_replace('DummyView', $this->option('markdown'), $class);
if ($this->option('markdown') !== false) {
$class = str_replace('DummyView', $this->getView(), $class);
}

return $class;
}

/**
* Get the view name.
*
* @return string
*/
protected function getView()
{
$view = $this->option('markdown');

if (! $view) {
$view = 'mail.'.Str::kebab(class_basename($this->argument('name')));
}

return $view;
}

/**
* Get the stub file for the generator.
*
Expand All @@ -97,7 +107,7 @@ protected function buildClass($name)
protected function getStub()
{
return $this->resolveStubPath(
$this->option('markdown')
$this->option('markdown') !== false
? '/stubs/markdown-mail.stub'
: '/stubs/mail.stub');
}
Expand Down Expand Up @@ -136,7 +146,7 @@ protected function getOptions()
return [
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the mailable already exists'],

['markdown', 'm', InputOption::VALUE_OPTIONAL, 'Create a new Markdown template for the mailable'],
['markdown', 'm', InputOption::VALUE_OPTIONAL, 'Create a new Markdown template for the mailable', false],
];
}
}

0 comments on commit ff56967

Please sign in to comment.