-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlayout.cfc
More file actions
91 lines (80 loc) · 2.96 KB
/
layout.cfc
File metadata and controls
91 lines (80 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Create a new layout in an existing ColdBox application. Run this command in the root
* of your app for it to find the correct folder. By default, your new layout will be created in /layouts but you can
* override that with the directory param.
* .
* {code:bash}
* coldbox create layout myLayout
* {code}
*
**/
component extends="coldbox-cli.models.BaseCommand" {
/**
* @arguments.name Name of the layout to create without the .cfm.
* @helper Generate a helper file for this layout
* @directory The base directory to create your layout in and creates the directory if it does not exist.
* @open Open the view in your default editor
* @force Force overwrite of existing files
* @content The content to put in the layout
**/
function run(
required name,
boolean helper = false,
directory = getAppPrefix( getCWD() ) & "layouts",
boolean open = false,
boolean force = false,
content = "<h1>#arguments.name# Layout</h1>#variables.utility.BREAK#",
boolean boxlang = isBoxLangProject( getCWD() )
){
// This will make each directory canonical and absolute
arguments.directory = resolvePath( arguments.directory );
// Validate directory
if ( !directoryExists( arguments.directory ) ) {
directoryCreate( arguments.directory );
}
// This help readability so the success messages aren't up against the previous command line
print.line();
if ( arguments.boxlang ) {
savecontent variable="local.layoutContent" {
writeOutput( "<bx:output>#variables.utility.BREAK#" )
writeOutput( arguments.content )
writeOutput( "<div>##view()##</div>#variables.utility.BREAK#" )
writeOutput( "</bx:output>" )
};
} else {
savecontent variable="local.layoutContent" {
writeOutput( "<cfoutput>#variables.utility.BREAK#" )
writeOutput( arguments.content )
writeOutput( "<div>##view()##</div>#variables.utility.BREAK#" )
writeOutput( "</cfoutput>" )
};
}
// Write out layout
var layoutPath = "#arguments.directory#/#arguments.name#.#arguments.boxlang ? "bxm" : "cfm"#";
// Confirm it
if (
fileExists( layoutPath ) && !arguments.force && !confirm(
"The file '#getFileFromPath( layoutPath )#' already exists, overwrite it (y/n)?"
)
) {
printWarn( "Exiting..." );
return;
}
file action="write" file="#layoutPath#" mode="777" output="#layoutContent#";
printInfo( "Created Layout [#layoutPath#]" );
// Open the view?
if ( arguments.open ) {
openPath( layoutPath );
}
if ( arguments.helper ) {
var layoutHelperContent= "<!--- #arguments.name# Layout Helper --->";
var layoutHelperPath = "#arguments.directory#/#arguments.name#Helper.#arguments.boxlang ? "bxm" : "cfm"#";
file action ="write" file="#layoutHelperPath#" mode="777" output="#layoutHelperContent#";
printInfo( "Created Layout Helper [#layoutHelperPath#]" );
// Open the view helper?
if ( arguments.open ) {
openPath( layoutHelperPath );
}
}
}
}