-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.rb
149 lines (130 loc) · 4.1 KB
/
default.rb
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
#!/usr/bin/env ruby
require 'nokogiri'
require 'date'
order = %w[intro_composite.xml
analysis_composite.xml
s2r_composite.xml
satc_composite.xml]
n = 'NoPrint'
stylesheet = %(<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:debrief="http://www.debrief.info/"
exclude-result-prefixes="xs debrief"
version="1.0">
<xsl:template match="/compositeCheatsheet">
<xsl:apply-templates select="taskGroup"/>
</xsl:template>
<xsl:template match="taskGroup">
<task id="{generate-id(.)}">
<title>
<xsl:apply-templates select="@name"/>
</title>
<shortdesc>
<xsl:apply-templates select="intro"/>
</shortdesc>
<xsl:choose>
<xsl:when test="taskGroup">
<xsl:apply-templates select="taskGroup"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="task">
<xsl:variable name="path" select="param[@name='path']/@value"/>
<task id="{generate-id(.)}">
<title>
<xsl:apply-templates
select="document($path)//cheatsheet/@title"/>
</title>
<shortdesc>
<xsl:apply-templates
select="document($path)//cheatsheet/intro/description"/>
</shortdesc>
<taskbody>
<steps>
<xsl:apply-templates select="document($path)//cheatsheet"/>
</steps>
<result>
<xsl:apply-templates select="onCompletion"/>
</result>
</taskbody>
</task>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</task>
</xsl:template>
<xsl:template match="cheatsheet">
<xsl:for-each select="item">
<step id="{generate-id(.)}">
<cmd>
<xsl:apply-templates select="@title"/>
</cmd>
<info>
<xsl:apply-templates select="description"/>
</info>
<stepxmp>
<xsl:choose>
<xsl:when test="@skip = 'true'">optional</xsl:when>
</xsl:choose>
</stepxmp>
</step>
</xsl:for-each>
</xsl:template>
<xsl:template match="b">
<b><xsl:apply-templates/></b>
</xsl:template>
<xsl:template match="text()">
<xsl:copy/>
</xsl:template>
<xsl:template match="i[.='#{n}']"/>
<xsl:template
match="text()[preceding-sibling::i[.='#{n}'][1]][following-sibling::i[.='#{n}'][1]]|
*[preceding-sibling::i[.='#{n}'][1]][following-sibling::i[.='#{n}'][1]]"/>
<xsl:template match="br">
<ph />
</xsl:template>
<xsl:template match="i">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>)
ditamap = %(<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map>
<title>Debrief Topic Map</title>
<topicmeta>
<searchtitle>Debrief Eclipse cheat sheets</searchtitle>
<shortdesc>Overview of Debrief inside Eclipse</shortdesc>
<author>Debrief</author>
<author>John Bampton</author>
<source>http://debrief.info/</source>
<publisher>Github John Bampton and #{11_461_173_985_121
.to_s
.split(/[356]/)
.map(&:to_i)
.map(&:chr)
.join
.capitalize}</publisher>
<critdates>
<created date="#{Date.today}"/>
</critdates>
<audience type="marine expert"
job="analysis" experiencelevel="intermediate"/>
<category>Maritime</category>
<category>Software</category>
<othermeta name="type" content="Naval"/>
</topicmeta>)
Dir.glob('cheatsheets-xml-test-data/**/*_composite.xml')
.sort_by { |x| order.index(File.basename(x)) }
.each do |filename|
document = Nokogiri::XML(File.new(filename))
template = Nokogiri::XSLT(stylesheet)
ditamap += %(
<topicref href="dita/#{File.basename(filename, '.*')}.dita" type="task"/>)
transformed_document = template.transform(document)
File.open("output/dita/#{File.basename(filename, '.*')}.dita", 'w')
.write(transformed_document)
end
ditamap += '
</map>'
File.open('output/map.ditamap', 'w') { |f| f.write(ditamap) }
puts ditamap