-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsubl2tm.xml
200 lines (162 loc) · 8.71 KB
/
subl2tm.xml
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!-- (C) 2012-2015 David "srbs" Forrest, ZLIB license -->
<!-- somerandombystander (at) gmail (dot) com -->
<!-- http://www.opensource.org/licenses/zlib-license.php -->
<project basedir="." name="Sublime to TextMate Transformer">
<!-- if you want to change the projectname, you need to change it on line 73 also -->
<macrodef name="subl2tm" description="This converts one (1) Sublime Text Package into one (1) TextMate Bundle.">
<attribute name="destdir" description="The root folder to put the TextMate Bundle files, usually ending in '*.tmbundle'." />
<attribute name="srcdir" description="The root folder for the Sublime Text files." />
<attribute name="snippet-transformer" default="subl2tm.xsl" description="The file that transforms the snippets. (default: subl2tm.xsl)" />
<attribute name="convert-to-tabs" default="false" description="Setting for changing the spaces to tabs in the resulting snippet xml. (default: false)" />
<!-- no package here, its a dir-folder -->
<sequential>
<local name="warningtext" />
<condition property="warningtext" value="${line.separator}Warning: Destination directory is not empty, may cause undesired effects." else="">
<and>
<available file="@{destdir}" type="dir" />
<resourcecount when="greater" count="0">
<fileset dir="@{destdir}" />
</resourcecount>
</and>
</condition>
<echo message="Converting Sublime Text package to a TextMate bundle. (@{srcdir} -> @{destdir})${warningtext}" />
<!-- mkdir -->
<mkdir dir="@{destdir}" />
<!-- copy non-snippets -->
<copy todir="@{destdir}/Preferences" flatten="true" includeEmptyDirs="false">
<fileset dir="@{srcdir}" includes="**/*.tmPreferences" />
</copy>
<copy todir="@{destdir}/Syntaxes" flatten="true" includeEmptyDirs="false">
<fileset dir="@{srcdir}" includes="**/*.tmLanguage" />
</copy>
<!-- create info.plist?? -->
<!-- transform & copy all snippets -->
<subl2tm-snippet destdir="@{destdir}/Snippets" transformer="@{snippet-transformer}" flatten="true" convert-to-tabs="@{convert-to-tabs}">
<fileset dir="@{srcdir}" includes="**/*.sublime-snippet" />
</subl2tm-snippet>
</sequential>
</macrodef>
<macrodef name="subl2tm-snippet" description="This converts Sublime Text snippets into TextMate snippets">
<attribute name="destdir" description="The destination directory the TextMate snippets go in." />
<attribute name="transformer" default="subl2tm.xsl" description="The XSLT file that transforms the snippet. (default: subl2tm.xsl)" />
<attribute name="convert-to-tabs" default="false" description="Setting for converting the spaces in the snippet xml to tabs. (default: false)" />
<attribute name="force" default="false" description="Recreate target files regardless on if they are newer than their source file. (default: false)" />
<attribute name="flatten" default="true" description="Flatten the hierarchy. (default: true)" />
<attribute name="scandirs" default="false" description="Transform all files in included directories. (default: false)" />
<!-- for nested fileset's -->
<element name="files" implicit="yes" description="A list of Sublime Text snippet files to convert." />
<sequential>
<!-- time stuff used to only apply the convert-to-tabs setting to newly created files -->
<local name="timepattern" />
<property name="timepattern" value="yyyy/MM/dd HH:mm:ss" />
<local name="time" />
<tstamp>
<format property="time" pattern="${timepattern}" offset="-1" unit="second" />
<!-- -1 second offset to guarantee that the generated files are included -->
</tstamp>
<!-- verify dir exists -->
<mkdir dir="@{destdir}" />
<!-- xslt transform settings -->
<local name="maptype" />
<!-- if user wanted flatten, use flatten below, other qise, do nothing (aka identity) -->
<condition property="maptype" value="flatten" else="identity">
<istrue value="@{flatten}" />
</condition>
<!-- verify xslt file exists, if not.. check for default, if that one doesn't exist,
keep the original file to show a proper error message
generally this will only work for the default value, but is done non-the-less -->
<local name="ant-file-dir" />
<dirname property="ant-file-dir" file="${ant.file.Sublime to TextMate Transformer}" />
<local name="xsl-default" />
<property name="xsl-default" value="${ant-file-dir}/@{transformer}" />
<local name="xsl-file" />
<condition property="xsl-file" value="${xsl-default}" else="@{transformer}">
<and>
<not>
<available file="@{transformer}" />
</not>
<available file="${xsl-default}" />
</and>
<!-- xsl-file = (!transformer.exists() && xsl-default.exists())? xsl-default: transformer -->
</condition>
<!-- copy & transform snippets -->
<xslt destdir="@{destdir}" style="${xsl-file}" force="@{force}"
useImplicitFileset="false" scanincludeddirectories="@{scandirs}">
<files />
<!-- flatten & change extension -->
<chainedmapper>
<mapper type="${maptype}" />
<globmapper from="*.sublime-snippet" to="*.tmSnippet" />
</chainedmapper>
</xslt>
<!-- below is the convert-to-tabs setting execution -->
<!-- Read the file & find out how many spaces are at the beginning of the lines. -->
<local name="quantity" />
<loadfile property="quantity" srcfile="${xsl-file}">
<!-- get the number of spaces the transformer(xsl-file) is set to create -->
<filterchain>
<!-- get only the line containing the indent-amount setting -->
<linecontainsregexp>
<regexp pattern="xalan:indent-amount="(\d+)"" />
</linecontainsregexp>
<!-- replace entire line (.* - .*) with just the digit (\d+) -->
<tokenfilter>
<replaceregex pattern=".*xalan:indent-amount="(\d+)".*" replace='\1' />
</tokenfilter>
<!-- guarantee that the only data left is the digits -->
<striplinebreaks />
</filterchain>
</loadfile>
<!-- Guarantee a value in quantity (0 is don't execute)-->
<property name="quantity" value="0" />
<!-- srbs style if hack starts here -->
<!-- Here we declare a property to be local so we can set it's value (and to not interfere anywhere else) -->
<local name="convert" />
<!-- Here we set the value of ${convert} to be '' when the user wants to replace the values -->
<!-- Otherwise (else) set it to 'fail' do not replace the values -->
<condition property="convert" value="" else="fail">
<and>
<!-- ONLY true/t values are accepted as true -->
<or>
<equals arg1="true" arg2="@{convert-to-tabs}" casesensitive="false" trim="true" forcestring="true" />
<equals arg1="t" arg2="@{convert-to-tabs}" casesensitive="false" trim="true" forcestring="true" />
</or>
<!-- Check to make sure there actually is a non-zero quantity in the file -->
<not>
<equals arg1="0" arg2="${quantity}" />
</not>
</and>
<!--convert = (convert-to-tabs==true && (quantity > 0))? "": "fail"-->
</condition>
<!-- The ${convert} variable is used in a following regular expression in a location that will guarantee failure
when/if text is inserted there -->
<!-- The only downfall of not using targets/depends or ant-contib if is that the
loadfile & replaceregexp tasks have to executed no matter what. -->
<!--<echo message="Check for existance for non-true & non-existance for true: -${convert}-" />-->
<!-- Replace the spaces with tabs. -->
<!-- <dict> are on column 1 -->
<replaceregexp match="${convert}^ {${quantity}}<" replace="<" byline="true">
<fileset dir="@{destdir}" includes="*.tmSnippet">
<!-- only the files we recently changed -->
<date datetime="${time}" when="after" pattern="${timepattern}" />
</fileset>
</replaceregexp>
<!-- <key> & <string> are on column 2 (1 tab) -->
<replaceregexp match="${convert}^ {${quantity}} {${quantity}}<" replace="	<" byline="true">
<fileset dir="@{destdir}" includes="*.tmSnippet">
<!-- only the files we recently changed -->
<date datetime="${time}" when="after" pattern="${timepattern}" />
</fileset>
</replaceregexp>
</sequential>
</macrodef>
<!-- future idea instead of what is in the xsl file?
<scriptdef name="generateuuid" language="javascript">
<attribute name="property" />
<![CDATA[
importClass(java.util.UUID);
project.setProperty(attributes.get("property"), UUID.randomUUID().toUpperCase());
]]>
</scriptdef>
-->
</project>