Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added two new configs

Allow for scaffolds to automatically migrate, and allow users to modify
the generated view's extension.
  • Loading branch information...
commit d054e3cd631f3af51b9ffda8a3bc2f268017d2bb 1 parent 4edac9a
Loic Sharma authored
Showing with 92 additions and 25 deletions.
  1. +35 −1 config/scaffold.php
  2. +7 −9 readme.md
  3. +50 −15 tasks/make.php
36 config/scaffold.php
View
@@ -17,14 +17,48 @@
/*
|--------------------------------------------------------------------------
+ | Automatically Migrate
+ |--------------------------------------------------------------------------
+ |
+ | After a new scaffold is created, a migration file is created. By
+ | default, the new migration will not be migrated. However, you can
+ | change this to automatically run the new migration.
+ |
+ */
+
+ 'migrate' => false,
+
+ /*
+ |--------------------------------------------------------------------------
| View Parser
|--------------------------------------------------------------------------
|
| By default, generated views use the Blade parser. However, you may want
| to use the PHP parser, or any other custom parser, to match the other
- | views in your application.
+ | views in your application.
+ |
+ | Parsers: 'blade', 'php'.
|
*/
'parser' => 'blade',
+
+ /*
+ |--------------------------------------------------------------------------
+ | View Extensions
+ |--------------------------------------------------------------------------
+ |
+ | The generated view extension depends on the view parser. You can change
+ | the extension used by a parser, or add the extension of your own parser
+ | here. If a parser's extension is not set the default extension will be
+ | used.
+ |
+ */
+
+ 'extensions' => array(
+
+ 'blade' => BLADE_EXT,
+ 'default' => EXT,
+ ),
+
);
16 readme.md
View
@@ -36,14 +36,14 @@ Route::controller(Controller::detect());
Say you want to make a blog that contains posts that are posted by users. You could manually code all of that, or you
could just run:
- php artisan scaffold::make blog.comment content:text belongs_to:blog.post,user timestamps
- php artisan migrate
+ $ php artisan scaffold::make blog.comment content:text belongs_to:blog.post,user timestamps
+ $ php artisan migrate
- php artisan scaffold::make blog.post title:string content:text belongs_to:user has_many:blog.comment timestamps
- php artisan migrate
+ $ php artisan scaffold::make blog.post title:string content:text belongs_to:user has_many:blog.comment timestamps
+ $ php artisan migrate
- php artisan scaffold::make user username:string password:string has_many:blog.post,blog.comment
- php artisan migrate
+ $ php artisan scaffold::make user username:string password:string has_many:blog.post,blog.comment
+ $ php artisan migrate
Now isn't that a bit faster?
@@ -109,6 +109,4 @@ should be prefixed like so:
`timestamps`: If included, this will make the scaffold automatically timestamp
when rows are created or updated. If `timestamps` is omitted, the scaffold
-will not do this.
-
-**Note**: Don't forget to run your migrations after you create a new scaffold!
+will not do this.
65 tasks/make.php
View
@@ -5,11 +5,18 @@
class Scaffold_Make_Task {
/**
- * The table's data.
+ * Is the scaffold generator in testing mode?
*
- * @var array
+ * @var bool
*/
- public $data = array();
+ public $testing;
+
+ /**
+ * Wether or not to run migrations after a new scaffold is created.
+ *
+ * @var bool
+ */
+ public $migrate;
/**
* The type of parser the views will use.
@@ -19,6 +26,20 @@ class Scaffold_Make_Task {
public $parser;
/**
+ * View extensions.
+ *
+ * @var array
+ */
+ public $extensions;
+
+ /**
+ * The table's data.
+ *
+ * @var array
+ */
+ public $data = array();
+
+ /**
* The list of different relationships.
*
* @var array
@@ -32,13 +53,6 @@ class Scaffold_Make_Task {
);
/**
- * Is the scaffold generator in testing mode?
- *
- * @var bool
- */
- public $testing;
-
- /**
* Create a new scaffold.
*
* @param array $arguments
@@ -46,8 +60,10 @@ class Scaffold_Make_Task {
*/
public function run($arguments)
{
- $this->parser = Config::get('scaffold::scaffold.parser');
- $this->testing = Config::get('scaffold::scaffold.testing');
+ $this->testing = Config::get('scaffold::scaffold.testing');
+ $this->migrate = Config::get('scaffold::scaffold.migrate');
+ $this->parser = Config::get('scaffold::scaffold.parser');
+ $this->extensions = Config::get('scaffold::scaffold.extensions');
if($this->testing)
{
@@ -132,6 +148,11 @@ public function run($arguments)
$this->create_view('view');
$this->create_view('create');
$this->create_view('edit');
+
+ if($this->migrate)
+ {
+ $this->run_migrations();
+ }
}
}
@@ -437,14 +458,14 @@ public function create_view($view)
// Create the final directory it it doesn't already exist.
if ( ! is_dir($path)) mkdir($path);
- if($this->parser == 'blade')
+ if(isset($this->extensions[$this->parser]))
{
- $extension = BLADE_EXT;
+ $extension = $this->extensions[$this->parser];
}
else
{
- $extension = EXT;
+ $extension = $this->extensions['defaut'];
}
$file = $path.$view.$extension;
@@ -465,6 +486,20 @@ public function create_view($view)
}
/**
+ * Run the new migrations.
+ *
+ * @return void
+ */
+ public function run_migrations()
+ {
+ ob_start();
+
+ Laravel\CLI\Command::run(array('migrate'));
+
+ $this->log(ob_get_clean());
+ }
+
+ /**
* Show a message on the CLI.
*
* @param string $message
Please sign in to comment.
Something went wrong with that request. Please try again.