Skip to content

Commit f73e907

Browse files
author
Tony Junkes
committed
Minor Improvements
Adjusted some code that was poorly organized. -- controller.cfc Broke out the controller scaffold code into it's own function. Added view creation back (removed it on accident).
1 parent 459f1f7 commit f73e907

File tree

4 files changed

+44
-48
lines changed

4 files changed

+44
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# fw1-commands (v0.4.0)
1+
# fw1-commands (v0.4.1)
22
A collection of commands to be used with CommandBox for working with FW/1
33

44
### Installation

box.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name" : "FW/1 Commands",
33
"slug" : "fw1-commands",
4-
"version" : "0.4.0",
4+
"version" : "0.4.1",
55
"author" : "Tony Junkes @cfchef",
66
"location" : "https://github.com/cfchef/fw1-commands/archive/master.zip",
77
"createPackageDirectory" : true,

fw1/create/bean.cfc

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@ component displayname="FW/1 Create Bean Command"
3737
extends="commandbox.system.BaseCommand"
3838
excludeFromHelp=false
3939
{
40-
public any function init() {
41-
// ascii codes
42-
variables.ascii = {
43-
br = Chr(10) & Chr(13), // line break
44-
br2 = Chr(10) & Chr(13) & Chr(10) & Chr(13), // line break 2x
45-
tb = Chr(9), // tab
46-
tb2 = Chr(9) & Chr(9), // tab 2x
47-
};
48-
49-
return this;
50-
}
51-
5240
/**
5341
* @name.hint Name of the bean to create. For packages, specify name as 'myPackage/MyBean'
5442
* @directory.hint The base directory to create your bean in. Defaults to 'beans'.
@@ -60,11 +48,12 @@ component displayname="FW/1 Create Bean Command"
6048
boolean initialCaps = true,
6149
boolean open = false
6250
) {
51+
// This will make each directory canonical and absolute
52+
arguments.directory = fileSystemUtil.resolvePath( arguments.directory );
53+
// Validate directory
54+
if ( !directoryExists( arguments.directory ) ) { directoryCreate( arguments.directory ); }
55+
// Generate beans
6356
for ( var bean in listToArray( arguments.name ) ) {
64-
// This will make each directory canonical and absolute
65-
arguments.directory = fileSystemUtil.resolvePath( arguments.directory );
66-
// Validate directory
67-
if ( !directoryExists( arguments.directory ) ) { directoryCreate( arguments.directory ); }
6857
// Allow dot-delimited paths
6958
bean = replace( bean, ".", "/", "all" );
7059
// Make bean name intital caps?
@@ -75,11 +64,11 @@ component displayname="FW/1 Create Bean Command"
7564
print.line();
7665
// Generate bean with init function
7766
savecontent variable="beanContent" {
78-
writeOutput( "component {" & ascii.br );
79-
writeOutput( ascii.tb & "public #beanName# function init() {" & ascii.br );
80-
writeOutput( ascii.tb2 & "return this;" & ascii.br );
81-
writeOutput( ascii.tb & "}" );
82-
writeOutput( ascii.br & "}" );
67+
writeOutput( "component {" & cr );
68+
writeOutput( chr(9) & "public #beanName# function init() {" & cr );
69+
writeOutput( chr(9) & chr(9) & "return this;" & cr );
70+
writeOutput( chr(9) & "}" );
71+
writeOutput( cr & "}" );
8372
}
8473
var beanPath = "#arguments.directory#/#beanName#.cfc";
8574
// Create dir if it doesn't exist

fw1/create/controller.cfc

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ component displayname="FW/1 Create Controller Command"
4343
extends="commandbox.system.BaseCommand"
4444
excludeFromHelp=false
4545
{
46-
public any function init() {
47-
// ascii codes
48-
variables.ascii = {
49-
br = Chr(10) & Chr(13), // line break
50-
br2 = Chr(10) & Chr(13) & Chr(10) & Chr(13), // line break 2x
51-
tb = Chr(9), // tab
52-
tb2 = Chr(9) & Chr(9), // tab 2x
53-
};
54-
55-
return this;
56-
}
57-
5846
/**
5947
* @name.hint Name of the controller to create.
6048
* @actions.hint A comma-delimited list of actions to generate
@@ -81,26 +69,45 @@ component displayname="FW/1 Create Controller Command"
8169
// This help readability so the success messages aren't up against the previous command line
8270
print.line();
8371
// Generate controller with actions passed
84-
savecontent variable="controllerContent" {
85-
var index = 0;
86-
var actionArray = listToArray( arguments.actions );
87-
writeOutput( "component {" & ascii.br );
88-
for ( var thisAction in actionArray ) {
89-
index++;
90-
writeOutput( ascii.tb & "public void function #thisAction#(struct rc = {}) {" & ascii.br );
91-
writeOutput( ascii.tb2 & ascii.br );
92-
writeOutput( ascii.tb & "}" );
93-
if ( index != arrayLen( actionArray ) ) { writeOutput( ascii.br2 ) }
94-
}
95-
writeOutput( ascii.br & "}" );
96-
}
72+
var controllerContent = scaffoldController( arguments.name, listToArray( arguments.actions ) );
9773
var controllerPath = "#arguments.directory#/#arguments.name#.cfc";
9874
// Create dir if it doesn't exist
9975
directoryCreate( getDirectoryFromPath( controllerPath ), true, true );
10076
// Create files
10177
file action="write" file="#controllerPath#" mode="777" output="#controllerContent#";
10278
print.greenLine( "Created #controllerPath#" );
79+
// Create views?
80+
if ( arguments.views ) {
81+
for ( var action in listToArray( arguments.actions ) ) {
82+
var viewPath = arguments.viewsDirectory & "/" & arguments.name & "/" & action & ".cfm";
83+
// Create dir if it doesn't exist
84+
directoryCreate( getDirectoryFromPath( viewPath ), true, true );
85+
// Create view
86+
fileWrite( viewPath, "<cfoutput>#cr##chr(9)#<h1>#arguments.name#.#action#</h1>#cr#</cfoutput>" );
87+
print.greenLine( "Created " & arguments.viewsDirectory & "/" & arguments.name & "/" & action & ".cfm" );
88+
}
89+
}
10390
// Open file
10491
if ( arguments.open ){ openPath( controllerPath ); }
10592
}
93+
94+
private string function scaffoldController(
95+
required string name,
96+
array actions = ["default"]
97+
) {
98+
savecontent variable="controller" {
99+
var index = 0;
100+
writeOutput( "component {" & cr );
101+
for ( var action in arguments.actions ) {
102+
index++;
103+
writeOutput( chr(9) & "public void function #action#(struct rc = {}) {" & cr );
104+
writeOutput( chr(9) & chr(9) & cr );
105+
writeOutput( chr(9) & "}" );
106+
if ( index != arrayLen( arguments.actions ) ) { writeOutput( cr & cr ) }
107+
}
108+
writeOutput( cr & "}" );
109+
}
110+
111+
return controller;
112+
}
106113
}

0 commit comments

Comments
 (0)