Skip to content

Fix indentation to cfset, add cfthread, cftimer, cftrace #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions ToScript.cfc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
component {
variables.indentLevel = 0;
variables.options = {indentChars=Chr(9)};
variables.options = {indentChars=Chr(9),cleanTypes=true};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why default this new option to true? Also, if you're introducing a new option, it should be added to the README.


public struct function toScript(filePath="", options={}, fileContent="") {
var codeFile = new cfmlparser.File(filePath=filePath,fileContent=fileContent);
Expand Down Expand Up @@ -146,17 +146,21 @@ component {
public function getTagConverter(tagName) {
var converter = "";
try {
converter = createObject("component", "converters." & trim(lCase(tagName))).init(options);
converter = createObject("component", "converters." & trim(lCase(tagName))).init(options,this);
} catch(any e) {
if (e.type == "Template") {
//due to compiler error of the CFC
rethrow;
}
converter = createObject("component", "converters.BaseConverter").init(options);
converter = createObject("component", "converters.BaseConverter").init(options,this);
}
return converter;
}

public function getIdentLevel() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is supposed to be getIndentLevel.

return variables.indentLevel;
}

private function lineBreak(sb) {
sb.append(Chr(13));
sb.append(Chr(10));
Expand Down Expand Up @@ -197,4 +201,4 @@ component {
outputBuffer.setLength(0);
}

}
}
7 changes: 4 additions & 3 deletions converters/BaseConverter.cfc
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
component {
variables.options = {};
public function init(options) {
public function init(options,toscript) {
variables.options = arguments.options;
variables.toscript = arguments.toscript;
return this;
}

public string function toScript(tag) {
if (listFindNoCase("cfcontent,cfcookie,cfheader,cfdbinfo,cfdirectory,cfexecute,cffeed,cffile,cffileupload,cfflush,cfftp,cfimage,cfldap,cflog,cfparam,cfpop,cfprint,cfquery,cfqueryparam,cfprocparam,cfhttp,cfhttpparam,cfoutput,cfinvokeargument,cfsetting,cfprocessingdirective,cfmailparam,cflogout,cfloginuser", tag.getName())) {
if (listFindNoCase("cfcontent,cfcookie,cfheader,cfdbinfo,cfdirectory,cfexecute,cffeed,cffile,cffileupload,cfflush,cfftp,cfimage,cfldap,cflog,cfparam,cfpop,cfprint,cfquery,cfqueryparam,cfprocparam,cfhttp,cfhttpparam,cfoutput,cfinvokeargument,cfsetting,cfprocessingdirective,cfmailparam,cflogout,cfloginuser,cftimer,cftrace,cfthread", tag.getName())) {
//do generic CF11+ conversion
return toScriptGeneric(tag);
}
Expand Down Expand Up @@ -81,4 +82,4 @@ component {
return Chr(13) & Chr(10);
}

}
}
10 changes: 7 additions & 3 deletions converters/cffunction.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ component extends="BaseConverter" {
s = s & "public ";
}
if (structKeyExists(attr, "returntype")) {
s = s & attr.returntype & " ";
if( !variables.options.cleanTypes || ( attr.returntype != "VOID" && attr.returntype != "any" ) ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since any is the default, it's fine to optionally exclude, but removing void changes the semantics. Also, it's unnecessary to nest another if here.

s = s & attr.returntype & " ";
}
}
s = s & "function " & attr.name & "(";

Expand All @@ -56,7 +58,9 @@ component extends="BaseConverter" {
s = s & "required ";
}
if (structKeyExists(childAttr, "type")) {
s = s & childAttr.type & " ";
if( !variables.options.cleanTypes || ( childAttr.type != "VOID" && childAttr.type != "any" ) ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issues as returntype

s = s & childAttr.type & " ";
}
}
s = s & childAttr.name;
if (structKeyExists(childAttr, "default")) {
Expand Down Expand Up @@ -85,4 +89,4 @@ component extends="BaseConverter" {
return "}";
}

}
}
5 changes: 4 additions & 1 deletion converters/cflock.cfc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
component extends="BaseConverter" {

public string function toScript(tag) {
if( !tag.hasInnerContent() ) {
throw(message="cflock tag have a start and end tag");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "tag has" or "tags have".

}
var s = "lock ";
var attr = tag.getAttributes();
s = s & trim(tag.getAttributeContent(stripTrailingSlash=true));
Expand All @@ -16,4 +19,4 @@ component extends="BaseConverter" {
public string function toScriptEndTag(tag) {
return "}";
}
}
}
14 changes: 13 additions & 1 deletion converters/cfloop.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ component extends="BaseConverter" {
s = s & "++";
}
s = s & " ) {";
} else if (structKeyExists(attr, "query")) {
s = "cfloop( query= " & attr.query;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you extend BaseBlockTagConverter for this component instead, I think you can just use super.toScript(tag) here.

if (structKeyExists(attr, "startrow")) {
s = s & " startRow= " & unPound(attr.startrow);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACF requires commas to separate script attributes, but I would recommend using something generic and already implemented as I suggested above.

}
if (structKeyExists(attr, "endrow")) {
s = s & " endRow= " & unPound(attr.endrow);
}
if (structKeyExists(attr, "maxrows")) {
s = s & " maxRows= " & unPound(attr.maxrows);
}
s = s & " ) {";
} else {
throw(message="Unimplemented cfloop condition: #tag.getAttributeContent()# ");
}
Expand All @@ -62,4 +74,4 @@ component extends="BaseConverter" {
return "}";
}

}
}
5 changes: 3 additions & 2 deletions converters/cfset.cfc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
component extends="BaseConverter" {

public string function toScript(tag) {
return trim(convertOperators(tag.getAttributeContent(stripTrailingSlash=true))) & ";";
var i = variables.toscript.getIdentLevel();
return reReplace( trim(convertOperators(tag.getAttributeContent(stripTrailingSlash=true))) & ";", "\n\t", chr(10) & repeatString( variables.options.indentChars, i ), "all" );
}
}
}
10 changes: 10 additions & 0 deletions converters/cftimer.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
component extends="BaseBlockTagConverter" {

public string function toScript(tag) {
if( !tag.hasInnerContent() ) {
throw(message="cftimer tag have a start and end tag");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "tag has" or "tags have".

}
return super.toScript(tag);
}

}