Comments (18)
I am not sure I understand this request. If you are thinking of non-CFML files there are plenty of formatters already out there (such as prettier). If you are thinking of .cfm
files that is a different sort of challenge than .cfc
files since they potentially combine HTML, JavaScript and CSS with CFML mixed throughout.
from commandbox-cfformat.
It was .cfm
s I was thinking of. I tested an old cfc that had a mixture of coldfusion tags and html and felt like it did a good job (maybe I need to look at it more closely) and it had me wishing I could do the same to some cfms that could really benefit from consistent formatting.
from commandbox-cfformat.
@jcberquist Outputting HTML, CSS, or JS isn't unique to CFMs. How would CFFormat handle this CFC?
<cfcomponent output="true">
<cffunction name="foo" output="true">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<style>
##body {
color: red;
}
</style>
<cfoutput>
<span id="body">This is a <b>test</b></span>
</cfoutput>
</cffunction>
</cfcomponent>
from commandbox-cfformat.
@mbandizzle: Thank you for the clarification. I am glad you were happy with the results for .cfc
files with HTML in them. I am aware that .cfc
files can have HTML et al. in them :), and I did spend a little bit of time trying to ensure that cfformat
could do something sane with embedded HTML. That said, I expect that the more complicated the HTML/CFML mix gets, the less true that will be. (For instance, I don't try to format CSS or JavaScript).
The reason I drew the distinction with .cfm
files is that many/most tag components are not going to have any HTML in them, and of those that do many would have uncomplicated structures. Whereas I would expect most .cfm
files to have a mix, and it can get very complicated 😀
cc: @bdw429s
from commandbox-cfformat.
It would be handy to have an optional flag to attempt to format .cfm files. Most "non-view" cfm files I use as includes and would benefit greatly from this fantastic plugin.
UPDATE: cfformat works nicely on .cfm files renamed with a .cfc extension. This feature would be very useful.
from commandbox-cfformat.
@chapmandu: based on what you said, I assume your .cfm
files were "pure" CFML? I can probably allow this to run on .cfm
files as well (though not by default), though results would definitely not be guarunteed 😄- it would be run at your own risk. I would expect it to do fine in files that only contained CFML.
from commandbox-cfformat.
I would be happy to run cfm files at my own risk, one can easily unstage if it goes terribly wrong.
I have a workaround script that renames cfm to cfc, applies cfformat then reverts names..
from commandbox-cfformat.
Just a polite bump.. I'd really like to be able to watch or format a directory containing cfm files..
You can see here how useful it would be:
https://github.com/cfwheels/cfwheels/tree/master/wheels/controller
from commandbox-cfformat.
@chapmandu I have added the ability to format cfm files in v0.14.0
- you can use the new --cfm
flag to get cfformat to watch and format directories of cfm files. I recommend caution :) and it is probably not something I will spend a lot of time on trying to support. That said, I hope it helps you out.
from commandbox-cfformat.
I appreciate the update. It's safe to say I won't be formatting any view files. 👍
from commandbox-cfformat.
It appears this update has some problems. Trying to format a .cfm file throws the exception below:
box cfformat run /code/file.cfm --overwrite --cfm
ERROR (5.0.1+00137) cannot cast [ELEMENTS] string to a number value
/modules/commandbox-cfformat/models/CFFormat.cfc: line 175
173: var bom = '';
174:
175: if (arrayLen(tokens.elements)) {
176: if (
177: isArray(tokens.elements[1]) &&
called from /modules/commandbox-cfformat/models/CFFormat.cfc: line 80
called from /modules/commandbox-cfformat/commands/cfformat/run.cfc: line 62
called from /modules/commandbox-cfformat/commands/cfformat/run.cfc: line 48
called from /system/services/CommandService.cfc: line 343
called from /system/services/CommandService.cfc: line 158
called from /system/Shell.cfc: line 768
called from /system/Bootstrap.cfm: line 119
from commandbox-cfformat.
Can you share the file you were trying to format?
from commandbox-cfformat.
Also, are you running this on Linux?
from commandbox-cfformat.
Yes, Linux Ubuntu 20.04
File contents below using command: box cfformat run /home/adam/code/helpers/json.cfm --overwrite --cfm
<cfscript>
public any function deserialiseIfJSON(required string string, any default = false) {
if (isJSON(arguments.string)) {
return deserializeJSON(arguments.string);
}
return arguments.default;
}
</cfscript>
from commandbox-cfformat.
Thanks! I will take a look. Can you format any files - or do they all break on this version?
from commandbox-cfformat.
cfcs are fine, but any cfm file seems to throw this same exception. I've tried several different cfm files.
from commandbox-cfformat.
@chapmandu it looks to me like I may have uploaded the incorrect linux binary with the v0.14.0
release. I have replaced the file. Perhaps I will need to make another release to fix this, but for now, could you try going to ~/.CommandBox/cfml/modules/commandbox-cfformat/bin/
folder when CommandBox is not running and delete the v0.14.0
folder there? When you next start CommandBox, it should download the correct binary.
from commandbox-cfformat.
That did the trick.. Thanks! Working nicely.
I also discovered that I don't need the --cfm
flag if I pass a cfm file path to the command.
from commandbox-cfformat.
Related Issues (20)
- Subsequent lines of a multiline statement should be indented. HOT 2
- cfformat check doesn't handle Unicode with BOM files HOT 1
- Forgebox installation is broken HOT 1
- DocBox commenting formatting HOT 6
- struct element alignment HOT 5
- Tag type comments converted to script comments erroneously HOT 2
- annotation with a `:` is adding a space HOT 2
- Latest version removing indendations on Comments HOT 1
- Latest version removing comments HOT 1
- CommandBox no longer reloads on module installation HOT 8
- preserve case in doc-block? HOT 2
- Indent content between cfscript tags HOT 3
- Ignoring blocks/tags via settings vs comment HOT 2
- Property alignment incorrect when the number of attributes differs
- annotation with a - is adding a space
- tag-check and single tags that are not self-closing HOT 3
- abstract component modifier injects spaces
- Lines are improperly outdented
- Method Multiline formatting/highlighting when inital element is not a method HOT 1
- CSS styles
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from commandbox-cfformat.