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:

  1. Read snippets directory recursively
  2. Cead .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

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!

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Dipak Parikh's Gravatar Really cool.

Thanks guys!!
# Posted By Dipak Parikh | 12/5/06 10:37 PM
Rob Brooks-Bilson's Gravatar I'm slowly moving myself off of homesite +, but it is a hard habit to break!
# Posted By Rob Brooks-Bilson | 12/8/06 2:33 AM
Jim Bambrough's Gravatar 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
# Posted By Jim Bambrough | 12/13/06 3:00 AM
Rob Brooks-Bilson's Gravatar 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!
# Posted By Rob Brooks-Bilson | 12/13/06 7:27 PM
Charlie Stell's Gravatar 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>
# Posted By Charlie Stell | 12/27/07 5:40 AM
Rob Brooks-Bilson's Gravatar Thanks Charlie. I'll bet there are still a lot of HS+ users out there still holding out on converting!
# Posted By Rob Brooks-Bilson | 12/28/07 11:30 PM
Alan McCollough's Gravatar 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.
# Posted By Alan McCollough | 1/17/08 2:18 PM
Rob Brooks-Bilson's Gravatar Hi Alan,

I'm glad you found the script helpful. Snippets were definitely one of my favorite features in Homesite.
# Posted By Rob Brooks-Bilson | 1/21/08 2:25 PM
Wil Genovese's Gravatar 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.
# Posted By Wil Genovese | 3/31/08 10:56 AM



Copyright 1995-2009 Rob Brooks-Bilson. All rights reserved.
Aura skin for Raymond Camden's BlogCFC inspired by Joe Rinehart & Steven Erat. This blog is running version 5.9.004.