Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cli/src/commands/wheels/generate/controller.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ component aliases="wheels g controller" extends="../base" {

if (hasCustomActions) {
// HIGHEST PRIORITY: Custom actions specified
actionList = listToArray(arguments.actions);
actionList = listToArray(trim(arguments.actions));
// Remove empty elements and trim each action
actionList = actionList.map(function(action) {
return trim(action);
}).filter(function(action) {
return len(action) > 0;
});
} else if (arguments.crud) {
if (arguments.api) {
// API: No form actions (new, edit)
Expand Down Expand Up @@ -144,4 +150,4 @@ component aliases="wheels g controller" extends="../base" {
setExitCode(1);
}
}
}
}
8 changes: 4 additions & 4 deletions cli/src/commands/wheels/generate/helper.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,17 @@ result = #functionList[1]#("some input");

private string function generateHighlightFunction() {
var content = chr(9) & chr(9) & "// Highlight search terms in text" & chr(10);
content &= chr(9) & chr(9) & "local.searchTerm = arguments.options.term ?: """";" & chr(10);
content &= chr(9) & chr(9) & "local.term = arguments.options.term ?: """";" & chr(10);
content &= chr(9) & chr(9) & "local.highlightClass = arguments.options.class ?: ""highlight"";" & chr(10);
content &= chr(10);
content &= chr(9) & chr(9) & "if (!len(local.searchTerm)) {" & chr(10);
content &= chr(9) & chr(9) & "if (!len(local.term)) {" & chr(10);
content &= chr(9) & chr(9) & chr(9) & "return arguments.value;" & chr(10);
content &= chr(9) & chr(9) & "}" & chr(10);
content &= chr(10);
content &= chr(9) & chr(9) & "return reReplaceNoCase(" & chr(10);
content &= chr(9) & chr(9) & chr(9) & "arguments.value," & chr(10);
content &= chr(9) & chr(9) & chr(9) & """(#local.searchTerm#)""," & chr(10);
content &= chr(9) & chr(9) & chr(9) & """<span class=\""#local.highlightClass#\"">\\1</span>""," & chr(10);
content &= chr(9) & chr(9) & chr(9) & """('' & local.term & '')""," & chr(10);
content &= chr(9) & chr(9) & chr(9) & """<span class=''' & local.highlightClass & '''>\\1</span>""," & chr(10);
content &= chr(9) & chr(9) & chr(9) & """all""" & chr(10);
content &= chr(9) & chr(9) & ");" & chr(10);
return content;
Expand Down
13 changes: 10 additions & 3 deletions cli/src/commands/wheels/generate/model.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ component aliases='wheels g model' extends="../base" {
name = arguments.name,
properties = parsedProperties,
baseDirectory = getCWD(),
tableName = arguments.tableName
tableName = arguments.tableName,
primaryKey = arguments.primaryKey
);
} else {
var actualTableName = len(arguments.tableName) ? arguments.tableName : helpers.pluralize(lCase(arguments.name));
Expand Down Expand Up @@ -176,7 +177,13 @@ component aliases='wheels g model' extends="../base" {
var properties = [];

if (len(arguments.propertiesString)) {
var propList = listToArray(arguments.propertiesString);
var propList = listToArray(trim(arguments.propertiesString));
// Remove empty elements and trim each property
propList = propList.map(function(prop) {
return trim(prop);
}).filter(function(prop) {
return len(prop) > 0;
});

for (var prop in propList) {
var parts = listToArray(prop, ":");
Expand Down Expand Up @@ -264,4 +271,4 @@ component aliases='wheels g model' extends="../base" {

return arguments.properties;
}
}
}
11 changes: 7 additions & 4 deletions cli/src/models/ScaffoldService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ component {
required string name,
required array properties,
string baseDirectory = "",
string tableName = ""
string tableName = "",
string primaryKey = "id"
) {
var timestamp = dateFormat(now(), "yyyymmdd") & timeFormat(now(), "HHmmss");
var actualTableName = len(arguments.tableName) ? arguments.tableName : variables.helpers.pluralize(lCase(arguments.name));
Expand All @@ -231,7 +232,8 @@ component {
var content = generateMigrationContentWithProperties(
className = className,
tableName = actualTableName,
properties = arguments.properties
properties = arguments.properties,
primaryKey = arguments.primaryKey
);

// Write migration file
Expand All @@ -246,7 +248,8 @@ component {
private function generateMigrationContentWithProperties(
required string className,
required string tableName,
required array properties
required array properties,
string primaryKey = "id"
) {
var content = '/*' & chr(10);
content &= ' |----------------------------------------------------------------------------------------------|' & chr(10);
Expand All @@ -270,7 +273,7 @@ component {
content &= ' function up() {' & chr(10);
content &= ' transaction {' & chr(10);
content &= ' try {' & chr(10);
content &= ' t = createTable(name = ''#arguments.tableName#'', force=''false'', id=''true'', primaryKey=''id'');' & chr(10);
content &= ' t = createTable(name = ''#arguments.tableName#'', force=''false'', id=''true'', primaryKey=''#arguments.primaryKey#'');' & chr(10);

// Add properties (skip association properties that don't have database columns)
for (var prop in arguments.properties) {
Expand Down
Loading