Skip to content

Commit

Permalink
correctly generate stub when using Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 13, 2016
1 parent b876759 commit cd569f0
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/Illuminate/Foundation/Console/MailMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,33 @@ protected function writeMarkdownTemplate()
$this->files->put($path, file_get_contents(__DIR__.'/stubs/markdown.stub'));
}

/**
* Build the class with the given name.
*
* @param string $name
* @return string
*/
protected function buildClass($name)
{
$class = parent::buildClass($name);

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

return $class;
}

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__.'/stubs/mail.stub';
return $this->option('markdown')
? __DIR__.'/stubs/markdown-mail.stub'
: __DIR__.'/stubs/mail.stub';
}

/**
Expand Down
66 changes: 65 additions & 1 deletion src/Illuminate/Foundation/Console/NotificationMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Foundation\Console;

use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

class NotificationMakeCommand extends GeneratorCommand
{
Expand All @@ -27,14 +28,65 @@ class NotificationMakeCommand extends GeneratorCommand
*/
protected $type = 'Notification';

/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
if (parent::fire() === false) {
return;
}

if ($this->option('markdown')) {
$this->writeMarkdownTemplate();
}
}

/**
* Write the Markdown template for the mailable.
*
* @return void
*/
protected function writeMarkdownTemplate()
{
$path = resource_path('views/'.str_replace('.', '/', $this->option('markdown'))).'.blade.php';

if (! $this->files->isDirectory(dirname($path))) {
$this->files->makeDirectory(dirname($path), 0755, true);
}

$this->files->put($path, file_get_contents(__DIR__.'/stubs/markdown.stub'));
}

/**
* Build the class with the given name.
*
* @param string $name
* @return string
*/
protected function buildClass($name)
{
$class = parent::buildClass($name);

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

return $class;
}

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__.'/stubs/notification.stub';
return $this->option('markdown')
? __DIR__.'/stubs/markdown-notification.stub'
: __DIR__.'/stubs/notification.stub';
}

/**
Expand All @@ -47,4 +99,16 @@ protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Notifications';
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['markdown', 'm', InputOption::VALUE_OPTIONAL, 'Create a new Markdown template for the notification.'],
];
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/stubs/markdown.stub
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@component('mail::message')
# Introduction

The body of your email.
The body of your message.

@component('mail::button', ['url' => ''])
Button Text
Expand Down

0 comments on commit cd569f0

Please sign in to comment.