robrohan / farcry-tmbundle

Textmate bundle for the FarCry framework. Has tag and function snippets as well as templates and other goodies

This URL has Read+Write access

farcry-tmbundle / dictToBundle.xsl
100644 163 lines (140 sloc) 5.681 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?xml version="1.0" encoding="UTF-8" ?>
<!--
dictToBundle
Created by Rob Rohan on 2008-11-22.
Copyright (c) 2008-2009 Rob Rohan. All rights reserved.
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dic="http://www.cfeclipse.org/version1/dictionary"
xmlns:util="java:java.util.UUID"
version="2.0"
exclude-result-prefixes="xsl dic util">
 
<xsl:output method="xml"/>
<xsl:output method="xml" indent="yes" name="plistxml"
exclude-result-prefixes="xsl dic util" />
 
<xsl:variable name="NL">
<xsl:text>
</xsl:text>
</xsl:variable>
 
<xsl:template match="/">
<xsl:value-of select="$NL" />
<xsl:comment>TAGS</xsl:comment>
<xsl:value-of select="$NL" />
<xsl:comment><xsl:value-of select="'============================='" /></xsl:comment>
<xsl:value-of select="$NL" />
<xsl:apply-templates select="/dic:dictionary/dic:tags/dic:tag" />
<xsl:comment><xsl:value-of select="'============================='" /></xsl:comment>
<xsl:value-of select="$NL" />
 
 
<xsl:value-of select="$NL" />
<xsl:comment>FUNCTIONS</xsl:comment>
<xsl:value-of select="$NL" />
<xsl:comment><xsl:value-of select="'============================='" /></xsl:comment>
<xsl:value-of select="$NL" />
<xsl:apply-templates select="/dic:dictionary/dic:functions/dic:function" />
<xsl:comment><xsl:value-of select="'============================='" /></xsl:comment>
<xsl:value-of select="$NL" />
</xsl:template>
 
<!-- Formats the functions. Writes the plist too. -->
<xsl:template match="dic:function">
<xsl:variable name="filename" select="translate(@name,':','-')" />
 
<xsl:variable name="uid" select="util:randomUUID()"/>
<string><xsl:value-of select="util:toString($uid)"/></string>
<xsl:value-of select="$NL" />
 
<xsl:result-document href="bundle/Snippets/{$filename}.tmSnippet" format="plistxml">
<!-- <xsl:text><!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"></xsl:text> -->
<plist version="1.0">
<dict>
<key>content</key>
<string><xsl:value-of select="@name" />
<xsl:text>(${1:</xsl:text>
<xsl:for-each select="./dic:parameter">
<xsl:call-template name="param-with-placement">
<xsl:with-param name="placement" select="position()+position()" />
<xsl:with-param name="separator" select="', '" />
<xsl:with-param name="total-param-count" select="count(../dic:parameter)" />
</xsl:call-template>
</xsl:for-each>
<xsl:text>})</xsl:text></string>
 
<key>name</key>
<string><xsl:value-of select="@name"/></string>
 
<key>scope</key>
<string>text.html.cfm</string>
 
<key>tabTrigger</key>
<string><xsl:value-of select="@name"/></string>
 
<key>uuid</key>
<string><xsl:value-of select="util:toString($uid)"/></string>
</dict>
</plist>
</xsl:result-document>
</xsl:template>
 
<!-- Formats the tags. Writes out the plist file too -->
<xsl:template match="dic:tag">
<xsl:variable name="filename" select="translate(@name,':','-')" />
<!-- <xsl:value-of select="$filename" /> -->
 
<xsl:variable name="uid" select="util:randomUUID()"/>
<string><xsl:value-of select="util:toString($uid)"/></string>
<xsl:value-of select="$NL" />
 
<xsl:result-document href="bundle/Snippets/{$filename}.tmSnippet" format="plistxml">
<!-- <xsl:text><!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"></xsl:text> -->
<plist version="1.0">
<dict>
<key>content</key>
<string><xsl:text>&lt;</xsl:text>
<xsl:value-of select="@name" />
<xsl:text> ${1:</xsl:text>
<xsl:for-each select="./dic:parameter">
<xsl:call-template name="param-with-placement">
<xsl:with-param name="placement" select="position()+position()" />
<xsl:with-param name="separator" select="' '" />
<xsl:with-param name="total-param-count" select="count(../dic:parameter)" />
<!-- <xsl:with-param name="element" select="." /> -->
</xsl:call-template>
</xsl:for-each>
<xsl:text>}</xsl:text>
 
<xsl:choose>
<xsl:when test="@single = 'true'">
<xsl:text>/&gt;$0</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>&gt;$0&lt;</xsl:text>
<xsl:value-of select="@name" />
<xsl:text>&gt;</xsl:text>
</xsl:otherwise>
</xsl:choose></string>
 
<key>name</key>
<string><xsl:value-of select="@name"/></string>
 
<key>scope</key>
<string>text.html.cfm</string>
 
<key>tabTrigger</key>
<string><xsl:value-of select="substring-before(@name,':')"/></string>
 
<key>uuid</key>
<string><xsl:value-of select="util:toString($uid)"/></string>
</dict>
</plist>
</xsl:result-document>
</xsl:template>
 
<!-- handles doing the tag and function params. Takes 3 params.
placement = where to start the textmate $N variables from
separator = what to tack on to the end of each paramenter
total-param-count = total number of params, so we don't add the
separator to the last item.
-->
<xsl:template name="param-with-placement">
<xsl:param name="placement" />
<xsl:param name="separator" />
<xsl:param name="total-param-count" />
 
<xsl:text>$</xsl:text>
<xsl:text>{</xsl:text>
<xsl:value-of select="$placement" />
<xsl:text>:</xsl:text>
<xsl:value-of select="@name" /><xsl:text>="$</xsl:text>
<xsl:value-of select="$placement+1" />
<xsl:text>"</xsl:text>
<xsl:if test="position() != $total-param-count">
<xsl:value-of select="$separator" />
</xsl:if>
<xsl:text>}</xsl:text>
</xsl:template>
 
<xsl:template match="text()" />
</xsl:stylesheet>