-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathiedoc2ruby.xml
331 lines (295 loc) · 10.9 KB
/
iedoc2ruby.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xslt [
<!--Used to control code intenting -->
<!ENTITY nl "
">
<!ENTITY tab " ">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:strip-space elements="*"/>
<xsl:param name="mode" />
<xsl:template match="/">
<xsl:apply-templates select="//top" />
<xsl:apply-templates select="//function" />
<xsl:text disable-output-escaping="yes">
end # GeneratedDriver
end # Client
end # Selenium
</xsl:text>
</xsl:template>
<!--********************
TOP
***************-->
<xsl:template match="top">
<xsl:text disable-output-escaping="yes">
# Copyright 2006 ThoughtWorks, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -----------------
# Original code by Aslak Hellesoy and Darren Hobbs
# This file has been automatically generated via XSL
# -----------------
# </xsl:text>
<xsl:apply-templates>
<xsl:with-param name="replace-string">&nl;# </xsl:with-param>
</xsl:apply-templates>
<xsl:text disable-output-escaping="yes"><![CDATA[
module Selenium
module Client
module GeneratedDriver
]]>
</xsl:text>
</xsl:template>
<xsl:template match="comment">
<xsl:text>&nl;&tab;&tab;# </xsl:text>
<xsl:apply-templates>
<xsl:with-param name="replace-string">&nl;&tab;&tab;# </xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="node()|@*" >
<xsl:param name="replace-string" />
<xsl:copy>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="text()">
<xsl:param name="replace-string" />
<xsl:call-template name="search-and-replace">
<xsl:with-param name="input"><xsl:value-of select='.' /></xsl:with-param>
<xsl:with-param name="search-string"><xsl:text>&nl;</xsl:text></xsl:with-param>
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="b|strong">
<xsl:param name="replace-string" />
<xsl:element name="b">
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="code|tt">
<xsl:param name="replace-string" />
<xsl:element name="tt">
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="em|i">
<xsl:param name="replace-string" />
<xsl:element name="em">
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="h3">
<xsl:param name="replace-string" />
<xsl:text>===</xsl:text>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="li">
<xsl:param name="replace-string" />
<xsl:choose>
<xsl:when test="local-name(..) = 'ul'">
<xsl:text>*&tab;</xsl:text>
</xsl:when>
<xsl:when test="local-name(..) = 'ol'">
<xsl:value-of select="position()"/><xsl:text>. </xsl:text>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
<xsl:value-of select="$replace-string" />
</xsl:template>
<xsl:template match="ul|ol|dl">
<xsl:param name="replace-string" />
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /><!--<xsl:text>&tab;</xsl:text>--></xsl:with-param>
</xsl:apply-templates>
<xsl:value-of select="$replace-string" />
</xsl:template>
<xsl:template match="p">
<xsl:param name="replace-string" />
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
<xsl:value-of select="$replace-string" />
</xsl:template>
<xsl:template match="a|blockquote">
<xsl:param name="replace-string" />
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="dt">
<xsl:param name="replace-string" />
<xsl:text>*&tab;</xsl:text>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
<xsl:text>::</xsl:text>
</xsl:template>
<xsl:template match="dd">
<xsl:param name="replace-string" />
<xsl:value-of select="$replace-string" />
<xsl:text>&tab;</xsl:text>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /><xsl:text>&tab;</xsl:text></xsl:with-param>
</xsl:apply-templates>
<xsl:value-of select="$replace-string" />
</xsl:template>
<!--****************
FUNCTION
******************-->
<xsl:template match="function">
<!-- Doc -->
<xsl:apply-templates select="comment" />
<xsl:text>&nl;&tab;&tab;#</xsl:text>
<xsl:apply-templates select="param" mode="comment" />
<xsl:text>&nl;&tab;&tab;def </xsl:text>
<xsl:call-template name="underscorify">
<xsl:with-param name="input"><xsl:value-of select="@name" /></xsl:with-param>
</xsl:call-template>
<!-- Params -->
<xsl:text>(</xsl:text>
<xsl:apply-templates select="param" mode="declaration" />
<xsl:text>)&nl;&tab;&tab;&tab;</xsl:text>
<xsl:if test="count(./return) = 0">
<xsl:text>remote_control_command</xsl:text>
</xsl:if>
<xsl:apply-templates select="return" mode="implementation" />
<xsl:text>("</xsl:text>
<xsl:value-of select="@name" />
<xsl:text>", [</xsl:text>
<xsl:apply-templates select="param" mode="implementation" />
<xsl:text>])&nl;&tab;&tab;end&nl;&nl;</xsl:text>
</xsl:template>
<!--*****************
RETURN
*******************-->
<xsl:template name="procMethod">
<xsl:param name="type" />
<xsl:choose>
<xsl:when test="$type='string'">
<xsl:text>string_command</xsl:text>
</xsl:when>
<xsl:when test="$type='number'">
<xsl:text>number_command</xsl:text>
</xsl:when>
<xsl:when test="$type='boolean'">
<xsl:text>boolean_command</xsl:text>
</xsl:when>
<xsl:when test="$type='string[]'">
<xsl:text>string_array_command</xsl:text>
</xsl:when>
<xsl:when test="$type='number[]'">
<xsl:text>number_array_command</xsl:text>
</xsl:when>
<xsl:when test="$type='boolean[]'">
<xsl:text>boolean_array_command</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">returntype is invalid: <xsl:value-of select="$type"/></xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- In the function implementation, add "return" keyword, casting to correct type -->
<xsl:template match="return" mode="implementation">
<xsl:text>return </xsl:text>
<xsl:call-template name="procMethod">
<xsl:with-param name="type"><xsl:value-of select="@type" /></xsl:with-param>
</xsl:call-template>
</xsl:template>
<!-- In the RDoc, add the <returns> tag -->
<xsl:template match="return" mode="comment">
<xsl:text>&nl;&tab;&tab;/// <returns></xsl:text>
<xsl:call-template name="search-and-replace">
<xsl:with-param name="input"><xsl:value-of select="."/></xsl:with-param>
<xsl:with-param name="search-string"><xsl:text>&nl;</xsl:text></xsl:with-param>
<xsl:with-param name="replace-string">&nl;&tab;&tab;/// </xsl:with-param>
</xsl:call-template>
<xsl:text></returns></xsl:text>
</xsl:template>
<!-- In the RDoc, add the <param> tag -->
<xsl:template match="param" mode="comment">
<xsl:text>&nl;&tab;&tab;# '</xsl:text>
<xsl:value-of select="@name" />
<xsl:text>' is </xsl:text>
<xsl:apply-templates />
</xsl:template>
<!-- In the function declaration, specify all String parameters -->
<xsl:template match="param" mode="declaration">
<xsl:value-of select="@name" />
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:template>
<!-- In the function implementation, add String parameters to array -->
<xsl:template match="param" mode="implementation">
<xsl:value-of select="@name" />
<xsl:text>,</xsl:text>
</xsl:template>
<xsl:template name="search-and-replace">
<xsl:param name="input"/>
<xsl:param name="search-string"/>
<xsl:param name="replace-string"/>
<xsl:choose>
<!-- See if the input contains the search string -->
<xsl:when test="$search-string and
contains($input,$search-string)">
<!-- If so, then concatenate the substring before the search
string to the replacement string and to the result of
recursively applying this template to the remaining substring.
-->
<xsl:value-of
select="substring-before($input,$search-string)"/>
<xsl:value-of select="$replace-string"/>
<xsl:call-template name="search-and-replace">
<xsl:with-param name="input"
select="substring-after($input,$search-string)"/>
<xsl:with-param name="search-string"
select="$search-string"/>
<xsl:with-param name="replace-string"
select="$replace-string"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- There are no more occurrences of the search string so
just return the current input string -->
<xsl:value-of select="$input"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="underscorify">
<xsl:param name="input" />
<xsl:if test="$input">
<xsl:variable name="first-char" select="substring($input, 1, 1)"/>
<xsl:variable name="lower-first-char" select="translate($first-char, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
<xsl:if test="$first-char != $lower-first-char">
<xsl:text>_</xsl:text>
</xsl:if>
<xsl:value-of select="$lower-first-char"/>
<xsl:call-template name="underscorify">
<xsl:with-param name="input" select="substring($input, 2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>