1313 * wheels generate controller user index,customaction
1414 * {code}
1515 **/
16- component aliases = ' wheels g controller' extends = " ../base" {
16+ component
17+ aliases = " wheels g controller"
18+ extends = " ../base"
19+ {
1720
18- /**
19- * @name.hint Name of the controller to create without the .cfc
20- * @actionList.hint optional list of actions, comma delimited
21- * @directory.hint if for some reason you don't have your controllers in /controllers/
22- **/
23- function run (
24- required string name ,
25- string actionList = " " ,
26- directory = ' controllers'
27- ) {
28- var obj = helpers .getNameVariants (arguments .name );
29- arguments .directory = fileSystemUtil .resolvePath ( arguments .directory );
21+ /**
22+ * @name.hint Name of the controller to create without the .cfc
23+ * @actionList.hint optional list of actions, comma delimited
24+ * @directory.hint if for some reason you don't have your controllers in /controllers/
25+ **/
26+ function run (
27+ required string name ,
28+ string actionList = ' ' ,
29+ directory = ' controllers'
30+ ) {
31+ var obj = helpers .getNameVariants ( arguments .name );
32+ arguments .directory = fileSystemUtil .resolvePath ( arguments .directory );
3033
31- print .line ( " Creating Controller..." ).toConsole ();
34+ print .line ( ' Creating Controller...' ).toConsole ();
3235
33- // Validate directory
34- if ( ! directoryExists ( arguments .directory ) ) {
35- error ( " [#arguments .directory #] can't be found. Are you running this from your site root?" );
36- }
36+ // Validate directory
37+ if ( ! directoryExists ( arguments .directory ) ) {
38+ error ( ' [#arguments .directory #] can'' t be found. Are you running this from your site root?' );
39+ }
3740
38- // If custom actions passed in as arguments, then use them, otherwise use CRUD
39- var actionContent = " " ;
41+ // If custom actions passed in as arguments, then use them, otherwise use CRUD
42+ var actionContent = ' ' ;
4043
41- if ( len ( arguments .actionList ) && arguments .actionList ! = " CRUD" ){
42- var allactions = " " ;
43- var controllerContent = fileRead ( helpers .getTemplate (' /ControllerContent.txt' ) );
44- // Loop Over actions to generate them
45- for ( var this Action in listToArray ( arguments .actionList ) ) {
46- if ( this Action == ' init' ) { continue ; }
47- allactions = allactions & $returnAction (this Action );
48- print .yellowLine ( " Generated Action: #this Action #" );
49- }
50- actionContent = allactions ;
51- } else {
52- // Do Crud: overrwrite whole controllerContent with CRUD template
53- controllerContent = fileRead ( helpers .getTemplate (' /CRUDContent.txt' ) );
54- print .yellowLine ( " Generating CRUD" );
55- }
44+ if ( len ( arguments .actionList ) && arguments .actionList ! = ' CRUD' ) {
45+ var allactions = ' ' ;
46+ var controllerContent = fileRead ( helpers .getTemplate ( ' /ControllerContent.txt' ) );
47+ // Loop Over actions to generate them
48+ for ( var this Action in listToArray ( arguments .actionList ) ) {
49+ if ( this Action == ' init' ) {
50+ continue ;
51+ }
52+ allactions = allactions & $returnAction ( this Action );
53+ print .yellowLine ( ' Generated Action: #this Action #' );
54+ }
55+ actionContent = allactions ;
56+ } else {
57+ // Do Crud: overrwrite whole controllerContent with CRUD template
58+ controllerContent = fileRead ( helpers .getTemplate ( ' /CRUDContent.txt' ) );
59+ print .yellowLine ( ' Generating CRUD' );
60+ }
5661
57- // Inject actions in controller content
58- controllerContent = replaceNoCase ( controllerContent , ' |actions|' , actionContent , ' all' );
59- // Replace Object tokens
60- controllerContent = $replaceDefaultObjectNames (controllerContent , obj );
62+ // Inject actions in controller content
63+ controllerContent = replaceNoCase (
64+ controllerContent ,
65+ ' |actions|' ,
66+ actionContent ,
67+ ' all'
68+ );
69+ // Replace Object tokens
70+ controllerContent = $replaceDefaultObjectNames ( controllerContent , obj );
6171
62- var controllerName = obj .objectNamePluralC & " .cfc" ;
63- var controllerPath = directory & " / " & controllerName ;
72+ var controllerName = obj .objectNamePluralC & ' .cfc' ;
73+ var controllerPath = directory & ' / ' & controllerName ;
6474
65- if ( fileExists (controllerPath )) {
66- if ( confirm ( ' #controllerName # already exists in target directory. Do you want to overwrite? [y/n]' ) ) {
67- print .greenLine ( ' Ok, going to overwrite...' ).toConsole ();
68- } else {
69- print .boldRedLine ( ' Ok, aborting!' );
70- return ;
71- }
72- }
73- file action = ' write' file = ' #controllerPath #' mode = ' 777' output = ' #trim ( controllerContent ) #' ;
74- print .line ( ' Created #controllerName #' );
75- }
75+ if ( fileExists ( controllerPath ) ) {
76+ if ( confirm ( ' #controllerName # already exists in target directory. Do you want to overwrite? [y/n]' ) ) {
77+ print .greenLine ( ' Ok, going to overwrite...' ).toConsole ();
78+ } else {
79+ print .boldRedLine ( ' Ok, aborting!' );
80+ return ;
81+ }
82+ }
83+ file action = " write" file = " #controllerPath #" mode = " 777" output = " #trim ( controllerContent ) #" ;
84+ print .line ( ' Created #controllerName #' );
85+ }
7686
77- }
87+ }
0 commit comments