From cd569f074fd566f30d3eb760c3c9027203da3850 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 13 Dec 2016 14:43:53 -0600 Subject: [PATCH] correctly generate stub when using Markdown --- .../Foundation/Console/MailMakeCommand.php | 21 +++++- .../Console/NotificationMakeCommand.php | 66 ++++++++++++++++++- .../Foundation/Console/stubs/markdown.stub | 2 +- 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Console/MailMakeCommand.php b/src/Illuminate/Foundation/Console/MailMakeCommand.php index f2500e249202..3d6cb7a67bd6 100644 --- a/src/Illuminate/Foundation/Console/MailMakeCommand.php +++ b/src/Illuminate/Foundation/Console/MailMakeCommand.php @@ -60,6 +60,23 @@ 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. * @@ -67,7 +84,9 @@ protected function writeMarkdownTemplate() */ protected function getStub() { - return __DIR__.'/stubs/mail.stub'; + return $this->option('markdown') + ? __DIR__.'/stubs/markdown-mail.stub' + : __DIR__.'/stubs/mail.stub'; } /** diff --git a/src/Illuminate/Foundation/Console/NotificationMakeCommand.php b/src/Illuminate/Foundation/Console/NotificationMakeCommand.php index 59add2ad1114..f73a484fa321 100644 --- a/src/Illuminate/Foundation/Console/NotificationMakeCommand.php +++ b/src/Illuminate/Foundation/Console/NotificationMakeCommand.php @@ -3,6 +3,7 @@ namespace Illuminate\Foundation\Console; use Illuminate\Console\GeneratorCommand; +use Symfony\Component\Console\Input\InputOption; class NotificationMakeCommand extends GeneratorCommand { @@ -27,6 +28,55 @@ 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. * @@ -34,7 +84,9 @@ class NotificationMakeCommand extends GeneratorCommand */ protected function getStub() { - return __DIR__.'/stubs/notification.stub'; + return $this->option('markdown') + ? __DIR__.'/stubs/markdown-notification.stub' + : __DIR__.'/stubs/notification.stub'; } /** @@ -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.'], + ]; + } } diff --git a/src/Illuminate/Foundation/Console/stubs/markdown.stub b/src/Illuminate/Foundation/Console/stubs/markdown.stub index ed94081b152c..bc41428273d6 100644 --- a/src/Illuminate/Foundation/Console/stubs/markdown.stub +++ b/src/Illuminate/Foundation/Console/stubs/markdown.stub @@ -1,7 +1,7 @@ @component('mail::message') # Introduction -The body of your email. +The body of your message. @component('mail::button', ['url' => '']) Button Text