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:
<!---
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!