Skip to content

Commit

Permalink
Add ability to stub a Markdown template from make:mail.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 13, 2016
1 parent e5b0325 commit b876759
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Illuminate/Foundation/Console/MailMakeCommand.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 MailMakeCommand extends GeneratorCommand
{
Expand All @@ -27,6 +28,38 @@ class MailMakeCommand extends GeneratorCommand
*/
protected $type = 'Mail';

/**
* 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'));
}

/**
* Get the stub file for the generator.
*
Expand All @@ -47,4 +80,16 @@ protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Mail';
}

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

The body of your email.

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

Thanks,<br>
{{ config('app.name') }}
@endcomponent

0 comments on commit b876759

Please sign in to comment.