Thanks to Adam Crump, I finally got snippets working in CFEclipse. Turns out, it was something rather trivial, but I'll save that for another post. One of the things that's kept me from completely switching from HomeSite + to CFEclipse is snippets. I have hundreds of them, and the thought of living without them makes me cringe.
Once snippets were successfully working for me in CFEclipse, I decided I needed a tool to convert them from HomeSite + format to CFEclipse's XML format. HomeSite stores two files for each snippet you create. Each filename is the actual name of the snippet you see in Homesite. One file has a .hss extension, and contains the "start" text of the snippet. The other file gets a .hse extension, and contains the "end" text for the snippet. With this in mind, I outlined what I wanted my converter tool to do:
- Read snippets directory recursively
- Cead .hss and .hse files - these contain the snippet text
- Create folders in eclipse snippet directory
- Wrap the snippet text in xml (eclipse snippet format). Name of snippet is filename from homesite
- Write out xml files in eclipse snippets directory
Sounds pretty simple, right? ColdFusion MX 7 added a new recurse attribute to the cfdirectory tag which actually makes the whole process pretty simple. Here's the code I came up with. I have to admit, it's been a good while since I've written any code, so this took me a bit longer than I'd like to admit. I was able to use the code to convert and copy all of my snippets over, including all folders and subfolders, in just a few seconds. As always, YMMV:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<!---
1. read snippets directory recursively
2. read .hss and .hse files - these contain the snippet text
3. create folders in eclipse snippet directory
4. wrap the snippet text in xml (eclipse snippet format). Name of snippet is filename from homesite
5. write out xml files in eclipse snippets directory
--->
<!--- set homesite and eclipse snippet base directories --->
<cfset sourceDir = "C:\Program Files\Macromedia\HomeSite+\UserData\Snippets">
<cfset targetDir = "C:\_source\snippets">
<!--- read in the snippet files and directories from homesite recursively - need mx 7 --->
<cfdirectory
action="LIST"
directory="#sourceDir#"
name="dirList"
recurse="Yes"
sort="directory">
<!--- strip out .hse and other files so only .hss and directories are left --->
<cfquery name="theData" dbtype="query">
SELECT *
FROM dirList
WHERE type = 'dir'
OR name like '%.hss'
</cfquery>
<!--- loop over each directory, creating the same thing on the eclipse side --->
<cfoutput query="theData" group="directory" groupcasesensitive="yes">
<cfset myDir = replace(directory, sourceDir, "")>
<cfif directory is not sourceDir>
<cfdirectory action="CREATE" directory="#targetDir##myDir#">
</cfif>
<cfoutput>
<cfif listLast(name, ".") is "hss" and type is "file">
<!--- read in the .hss file (start of a snippet) --->
<cffile action="READ" file="#directory#\#name#" variable="snippetStart">
<!--- read in the .hse file (end of a snippet) --->
<cffile action="READ" file="#directory#\#ReplaceNoCase(name,".hss",".hse")#" variable="snippetEnd">
<!--- create the xml for each eclipse version of the snippet --->
<cfsavecontent variable="targetSnippet"><?xml version="1.0" encoding="utf-8"?>
<snippet filetemplate="false" extension="cfm">
<name>#ReplaceNoCase(name,".hss","")#</name>
<help>#ReplaceNoCase(name,".hss","")#</help>
<starttext><![CDATA[#snippetStart#]]></starttext>
<endtext><![CDATA[#snippetEnd#]]></endtext>
</snippet></cfsavecontent>
<!--- write out each file on the eclipse side --->
<cffile action="WRITE" file="#targetDir#\#myDir#\#ReplaceNoCase(name,".hss",".xml")#" output="#targetSnippet#">
</cfif>
</cfoutput>
</cfoutput>
All Finished!
1<!---
21. read snippets directory recursively
32. read .hss and .hse files - these contain the snippet text
43. create folders in eclipse snippet directory
54. wrap the snippet text in xml (eclipse snippet format). Name of snippet is filename from homesite
65. write out xml files in eclipse snippets directory
7--->
8<!--- set homesite and eclipse snippet base directories --->
9<cfset sourceDir = "C:\Program Files\Macromedia\HomeSite+\UserData\Snippets">
10<cfset targetDir = "C:\_source\snippets">
11
12<!--- read in the snippet files and directories from homesite recursively - need mx 7 --->
13<cfdirectory
14 action="LIST"
15 directory="#sourceDir#"
16 name="dirList"
17 recurse="Yes"
18 sort="directory">
19
20<!--- strip out .hse and other files so only .hss and directories are left --->
21<cfquery name="theData" dbtype="query">
22 SELECT *
23 FROM dirList
24 WHERE type = 'dir'
25 OR name like '%.hss'
26</cfquery>
27
28<!--- loop over each directory, creating the same thing on the eclipse side --->
29<cfoutput query="theData" group="directory" groupcasesensitive="yes">
30 <cfset myDir = replace(directory, sourceDir, "")>
31 <cfif directory is not sourceDir>
32 <cfdirectory action="CREATE" directory="#targetDir##myDir#">
33 </cfif>
34
35 <cfoutput>
36 <cfif listLast(name, ".") is "hss" and type is "file">
37 <!--- read in the .hss file (start of a snippet) --->
38 <cffile action="READ" file="#directory#\#name#" variable="snippetStart">
39 <!--- read in the .hse file (end of a snippet) --->
40 <cffile action="READ" file="#directory#\#ReplaceNoCase(name,".hss",".hse")#" variable="snippetEnd">
41
42<!--- create the xml for each eclipse version of the snippet --->
43<cfsavecontent variable="targetSnippet"><?xml version="1.0" encoding="utf-8"?>
44<snippet filetemplate="false" extension="cfm">
45<name>#ReplaceNoCase(name,".hss","")#</name>
46<help>#ReplaceNoCase(name,".hss","")#</help>
47<starttext><![CDATA[#snippetStart#]]></starttext>
48<endtext><![CDATA[#snippetEnd#]]></endtext>
49</snippet></cfsavecontent>
50
51 <!--- write out each file on the eclipse side --->
52 <cffile action="WRITE" file="#targetDir#\#myDir#\#ReplaceNoCase(name,".hss",".xml")#" output="#targetSnippet#">
53 </cfif>
54 </cfoutput>
55</cfoutput>
56
57All Finished!
12/5/06 10:37 PM
Really cool.
Thanks guys!!
12/8/06 2:33 AM
I'm slowly moving myself off of homesite +, but it is a hard habit to break!
12/13/06 3:00 AM
Ok, now for the big question: do you now exclusively use CFEclipse when you develop?? Be honest ...
Just let me say that now that I have re-joined Amkor under Adam Crump that I have really tried to adopt CFEclpse from Dreamweaver (I learned CF on Dreamweaver) and I've been pretty disciplined on exlusively using CFEclipse. I like being able to see all the modules in the CVS repository, that is pretty cool (not do-able in Dreamweaver or Tortoise CVS). But there are still cetain things that I would love to be able to do in CFEclipse that I could do in Dreamweaver (mostly little things). But I like that fact that there is a large CFEclipse comminuty and there will probably be more cool features available.
Cheers,
Jim Bambrough
12/13/06 7:27 PM
I'm like 75% there. I still can't stop using Homesite + as a simple text editor. I know, I know... I'm working on it!
12/27/07 5:40 AM
HomeSite CodeTemplates->CFEclipse Snippets.
No idea if someone already put a script up for this...
All of my "Snippets" in homesite were actually in the form of Code Templates (codetemp.dat).
Heres a very raw and dirty script I used to convert them for CFEclipse (I stress the word raw and very - kinda a 2 minute project ;) )
<cfsetting enablecfoutputonly="Yes">
<cfparam name="hold" default=""> <cfparam name="holdList" default=""> <cfparam name="newFileCon" default="">
<!--- Your CodeTemp.dat file ---> <cfset myfile = FileOpen("C:\Program Files\Macromedia\HomeSite+\UserData\CodeTemp.dat", "read")> <cfloop condition="NOT #FileisEOF(myfile)#">
<cfset x = FileReadLine(myfile)> <cfif left(x,1) EQ "["> <cfif len(hold) EQ 0> <cfset newFileCon = '<?xml version="1.0" encoding="utf-8"?> <snippet filetemplate="false" extension="cfm"> <name>#trim(left(listRest(Right(x,len(x)-1),"|"),len(listRest(Right(x,len(x)-1),"|"))-1))#</name> <help></help>'> <cfelse> <cfset newFileCon = newFileCon&' <starttext><![CDATA[#listFirst(hold,"|")#]]></starttext> <endtext><![CDATA[#listRest(hold,"|")#]]></endtext> </snippet> '> <cfset hold=""> <!--- Destination folder ---> <cfscript>FileWrite("c:\temp\#trim(listFirst(Right(x,len(x)-1),"|"))#.xml", "#newFileCon#");holdList=listAppend(holdList,"#trim(listFirst(Right(x,len(x)-1),"|"))#=/#trim(listFirst(Right(x,len(x)-1),"|"))#.xml",chr(13));</cfscript> <cfset newFileCon = '<?xml version="1.0" encoding="utf-8"?> <snippet filetemplate="false" extension="cfm"> <name>#trim(left(listRest(Right(x,len(x)-1),"|"),len(listRest(Right(x,len(x)-1),"|"))-1))#</name> <help></help>'> </cfif> <cfelse> <cfset hold = hold&x&chr(13)> </cfif>
</cfloop> <cfset FileClose(myfile)>
<cfsavecontent variable="keyComprop"> <cfoutput>##These key combos are used by the cfeclipse plugin. ##Thu #dateFormat(now(),"mmm dd")# #timeFormat(now(),"hh:mm:ss")# EST #year(now())# #holdList#</cfoutput> </cfsavecontent> <!--- Destination folder ---> <cfscript>FileWrite("c:\temp\keyCombos.properties", "#keyComprop#");</cfscript>
12/28/07 11:30 PM
Thanks Charlie. I'll bet there are still a lot of HS+ users out there still holding out on converting!
1/17/08 2:18 PM
Thank you a ton! I've switched over to CFEclipse (well, really FusionDebug) months ago, but left behind probably a hundred HS+ snippets. Now I've got them back. Ecellent. Thanks again.
1/21/08 2:25 PM
Hi Alan,
I'm glad you found the script helpful. Snippets were definitely one of my favorite features in Homesite.
3/31/08 10:56 AM
Thanks Rob. I finally switched to CFEclipse last summer and spent many hours deciding which snippets to covert by hand. There are others where I work that could use this. Also, moving to CFEclipse has allowed me to move to a Mac. Woo Woo.
7/14/10 2:36 PM
Thanks Rob!
I was looking for something like this for a couple weeks now. Moved from Homesite+ to CF Builder. So far I'm loving it. The learning curve is a bit frustrating, especially when you jump into a new IDE and are working on existing projects. I find myself stopping and messing around with CF Builder features.
By the way, I still have your CFMX 6 book on my shelf. I think that was the most well-written CF book I've ever read.
Andy
5/17/11 1:13 PM
Just used your code to convert my HomeSite+ snippets to
ColdFusion Builder 2. Worked like a charm and CFB2 liked
the conversion. Only had to add these lines when a ".hse" file
did not exist:
<!--- read in the .hse file (end of a snippet) --->
<cfset tempEndfile = "#directory#\#ReplaceNoCase(name,".hss",".hse")#">
<cfif fileexists("#tempEndfile#") is "yes">
<cffile action="READ" file="#tempEndfile#" variable="snippetEnd">
<cfelse>
<cfset snippetEnd = "">
</cfif>
Thank you!