Skip to content

Commit

Permalink
Version 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jan 6, 2016
1 parent 2bc1b10 commit 683d1f6
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 17 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ The `craftplugin` generator can also be passed arguments via the command line, b

## Changelog

### 1.0.4 -- 2016.01.06

* Added support for named Services and Controllers
* Cleaned up the naming scheme for all plugin components; null values will be properly handled for all of the *Name's
* Updated README.md

### 1.0.3 -- 2016.01.05

* You can now access the generator via the web at [pluginfactory.io](http://pluginfactory.io)
Expand Down
53 changes: 52 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ const QUESTIONS = [

/* -- Questions dependent on pluginComponents choices */

{
when: function (answers) {
return (typeof answers.pluginComponents != 'object') ? false : (answers.pluginComponents.indexOf('controllers') != -1);
},
type: "input",
name: 'controllerName',
message: 'Name of your Controller:',
default: '',
store: false
},
{
when: function (answers) {
return (typeof answers.pluginComponents != 'object') ? false : (answers.pluginComponents.indexOf('elementtypes') != -1);
Expand Down Expand Up @@ -159,6 +169,16 @@ const QUESTIONS = [
default: '',
store: false
},
{
when: function (answers) {
return (typeof answers.pluginComponents != 'object') ? false : (answers.pluginComponents.indexOf('services') != -1);
},
type: "input",
name: 'serviceName',
message: 'Name of your Service:',
default: '',
store: false
},

];

Expand Down Expand Up @@ -211,6 +231,7 @@ const TEMPLATE_FILES = [
destDir: "controllers/",
dest: "Controller.php",
requires: "controllers",
subPrefix: "controllerName",
prefix: true
},
{
Expand Down Expand Up @@ -271,6 +292,7 @@ const TEMPLATE_FILES = [
destDir: "services/",
dest: "Service.php",
requires: "services",
subPrefix: "serviceName",
prefix: true
},
{
Expand Down Expand Up @@ -413,6 +435,27 @@ module.exports = yo.generators.Base.extend({
this.answers.pluginReleasesUrl = "https://raw.githubusercontent.com/" + this.answers.pluginAuthorGithub + "/" + this.answers.pluginDirName + "/master/releases.json";
this.answers.pluginCloneUrl = "https://github.com/" + this.answers.pluginAuthorGithub + "/" + this.answers.pluginDirName + ".git";
}

/* -- Clean up the various handle names */

if (typeof this.answers.controllerName != 'undefined')
this.answers.controllerName = this.answers.controllerName.prefixize();

if (typeof this.answers.elementName != 'undefined')
this.answers.elementName = this.answers.elementName.prefixize();

if (typeof this.answers.fieldName != 'undefined')
this.answers.fieldName = this.answers.fieldName.prefixize();

if (typeof this.answers.modelName != 'undefined')
this.answers.modelName = this.answers.modelName.prefixize();

if (typeof this.answers.recordName != 'undefined')
this.answers.recordName = this.answers.recordName.prefixize();

if (typeof this.answers.serviceName != 'undefined')
this.answers.serviceName = this.answers.serviceName.prefixize();

done();
}.bind(this));;
},
Expand Down Expand Up @@ -455,7 +498,7 @@ module.exports = yo.generators.Base.extend({
if (file.prefix) {
var subPrefix = "";
if (file.subPrefix) {
subPrefix = "_" + this.answers[file.subPrefix].camelize().capitalizeFirstLetter();
subPrefix = this.answers[file.subPrefix];
}
destFile = this.destDir + file.destDir + this.answers.pluginHandle + subPrefix + file.dest;
}
Expand Down Expand Up @@ -539,6 +582,14 @@ String.prototype.camelize = function() {
});
}

// Convert a string to have proceed with a _ and be camel-cased, with the first letter capitalized
String.prototype.prefixize = function() {
if (this == "")
return this;
else
return ("_" + this.camelize().capitalizeFirstLetter());
}

// Capitalize the first letter of a string
String.prototype.capitalizeFirstLetter = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
Expand Down
4 changes: 2 additions & 2 deletions app/templates/controllers/_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* <%= pluginName %> plugin for Craft CMS
*
* <%= pluginName %> Controller
* <%= pluginHandle %><%= controllerName %> Controller
*
* --snip--
* Generally speaking, controllers are the middlemen between the front end of the CP/website and your plugin’s
Expand All @@ -27,7 +27,7 @@

namespace Craft;

class <%= pluginHandle %>Controller extends BaseController
class <%= pluginHandle %><%= controllerName %>Controller extends BaseController
{

/**
Expand Down
6 changes: 3 additions & 3 deletions app/templates/elementtypes/_ElementType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* <%= pluginName %> plugin for Craft CMS
*
* <%= elementName %> ElementType
* <%= pluginHandle %><%= elementName %> ElementType
*
* --snip--
* Element Types are the classes used to identify each of these types of elements in Craft. There’s a
Expand All @@ -22,7 +22,7 @@

namespace Craft;

class <%= pluginHandle %>_<%= elementName %>ElementType extends BaseElementType
class <%= pluginHandle %><%= elementName %>ElementType extends BaseElementType
{
/**
* Returns this element type's name.
Expand All @@ -31,7 +31,7 @@ class <%= pluginHandle %>_<%= elementName %>ElementType extends BaseElementType
*/
public function getName()
{
return Craft::t('<%= pluginName %> <%= elementName %>');
return Craft::t('<%= pluginHandle %><%= elementName %>');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions app/templates/fieldtypes/_FieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* <%= pluginName %> plugin for Craft CMS
*
* <%= fieldName %> FieldType
* <%= pluginHandle %><%= fieldName %> FieldType
*
* --snip--
* Whenever someone creates a new field in Craft, they must specify what type of field it is. The system comes with
Expand All @@ -20,7 +20,7 @@

namespace Craft;

class <%= pluginHandle %>_<%= fieldName %>FieldType extends BaseFieldType
class <%= pluginHandle %><%= fieldName %>FieldType extends BaseFieldType
{
/**
* Returns the name of the fieldtype.
Expand All @@ -29,7 +29,7 @@ class <%= pluginHandle %>_<%= fieldName %>FieldType extends BaseFieldType
*/
public function getName()
{
return Craft::t('<%= pluginName %> <%= fieldName %>');
return Craft::t('<%= pluginHandle %><%= fieldName %>');
}

/**
Expand Down Expand Up @@ -81,7 +81,7 @@ public function getInputHtml($name, $value)
);

$jsonVars = json_encode($jsonVars);
craft()->templates->includeJs("$('#{$namespacedId}').<%= pluginHandle %>_<%= fieldName %>FieldType(" . $jsonVars . ");");
craft()->templates->includeJs("$('#{$namespacedId}').<%= pluginHandle %><%= pluginHandle %>FieldType(" . $jsonVars . ");");

/* -- Variables to pass down to our rendered template */

Expand Down
4 changes: 2 additions & 2 deletions app/templates/models/_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* <%= pluginName %> plugin for Craft CMS
*
* <%= modelName %> Model
* <%= pluginHandle %><%= modelName %> Model
*
* --snip--
* Models are containers for data. Just about every time information is passed between services, controllers, and
Expand All @@ -20,7 +20,7 @@

namespace Craft;

class <%= pluginHandle %>_<%= modelName %>Model extends BaseElementModel
class <%= pluginHandle %><%= modelName %>Model extends BaseElementModel
{
/**
* @access protected
Expand Down
6 changes: 3 additions & 3 deletions app/templates/records/_Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* <%= pluginName %> plugin for Craft CMS
*
* <%= recordName %> Record
* <%= pluginHandle %><%= recordName %> Record
*
* --snip--
* Active record models (or “records”) are like models, except with a database-facing layer built on top. On top of
Expand Down Expand Up @@ -31,7 +31,7 @@

namespace Craft;

class <%= pluginHandle %>_<%= recordName %>Record extends BaseRecord
class <%= pluginHandle %><%= recordName %>Record extends BaseRecord
{
/**
* Returns the name of the database table the model is associated with (sans table prefix). By convention,
Expand All @@ -41,7 +41,7 @@ class <%= pluginHandle %>_<%= recordName %>Record extends BaseRecord
*/
public function getTableName()
{
return '<%= pluginDirName %>_<%= recordName %>';
return '<%= pluginDirName %><%= recordName %>';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/templates/services/_Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* <%= pluginName %> plugin for Craft CMS
*
* <%= pluginName %> Service
* <%= pluginHandle %><%= serviceName %> Service
*
* --snip--
* All of your plugin’s business logic should go in services, including saving data, retrieving data, etc. They
Expand All @@ -20,7 +20,7 @@

namespace Craft;

class <%= pluginHandle %>Service extends BaseApplicationComponent
class <%= pluginHandle %><%= serviceName %>Service extends BaseApplicationComponent
{
/**
* This function can literally be anything you want, and you can have as many service functions as you want
Expand Down

0 comments on commit 683d1f6

Please sign in to comment.