asciidoctor-dita-map 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dita-map/cli.rb +67 -29
- data/lib/dita-map/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4eb319b4d8423d61539d7ec4816ccfac5499656cc15b739542ddb68023d210a0
|
|
4
|
+
data.tar.gz: 768371877af9214c0d80db4e19f29db88ab85c00821a5965480bd7f5304c3f2a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d251c66f265772f85a48aee4e8da5c4f9902870e991074dfe10c12977fcbb5921c3a6b695108bfa0025becb1d97bd8cb19bd92fbbeee958b3a5958ed8cfead5f
|
|
7
|
+
data.tar.gz: 0ed486763aa0b355ef4ec931ce87181ab2a6ca9c024e55d9ec03b2782c9ceed05f321ef396378e9421ad10a1ef13200fb05c954e30081af25397ab6905fe0846
|
data/lib/dita-map/cli.rb
CHANGED
|
@@ -38,6 +38,7 @@ module AsciidoctorDitaMap
|
|
|
38
38
|
:output => false,
|
|
39
39
|
:title => true,
|
|
40
40
|
:type => true,
|
|
41
|
+
:self => false,
|
|
41
42
|
:verbose => false
|
|
42
43
|
}
|
|
43
44
|
@prep = []
|
|
@@ -67,6 +68,10 @@ module AsciidoctorDitaMap
|
|
|
67
68
|
@prep.append file
|
|
68
69
|
end
|
|
69
70
|
|
|
71
|
+
opt.on('-i', '--include-self', 'make the supplied file the toplevel topicref') do
|
|
72
|
+
@opts[:self] = true
|
|
73
|
+
end
|
|
74
|
+
|
|
70
75
|
opt.separator ''
|
|
71
76
|
|
|
72
77
|
opt.on('-I', '--no-id', 'do not generate the map id attribute') do
|
|
@@ -118,14 +123,28 @@ module AsciidoctorDitaMap
|
|
|
118
123
|
return args
|
|
119
124
|
end
|
|
120
125
|
|
|
121
|
-
def
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
def compose_mapref_attributes file_name, type
|
|
127
|
+
target_file = file_name.sub(/\.adoc$/, '.ditamap')
|
|
128
|
+
attributes = { 'href' => target_file, 'format' => 'ditamap' }
|
|
129
|
+
attributes['type'] = type if @opts[:type]
|
|
124
130
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
return attributes
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def compose_topicref_attributes file_name, title, type
|
|
135
|
+
target_file = file_name.sub(/\.adoc$/, '.dita')
|
|
136
|
+
|
|
137
|
+
attributes = { 'href' => target_file }
|
|
138
|
+
attributes['navtitle'] = title if @opts[:navtitle] and title
|
|
139
|
+
attributes['type'] = type if @opts[:type] and type and ['concept', 'reference', 'task'].include? type
|
|
140
|
+
|
|
141
|
+
return attributes
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def get_content_type attributes
|
|
145
|
+
document_type = attributes['_mod-docs-content-type'] ? attributes['_mod-docs-content-type'].downcase : nil
|
|
146
|
+
document_type = attributes['_content-type'] ? attributes['_content-type'].downcase : nil unless document_type
|
|
147
|
+
document_type = attributes['_module-type'] ? attributes['_module-type'].downcase : nil unless document_type
|
|
129
148
|
|
|
130
149
|
if document_type
|
|
131
150
|
document_type.sub!(/^assembly$/, 'concept')
|
|
@@ -133,9 +152,18 @@ module AsciidoctorDitaMap
|
|
|
133
152
|
end
|
|
134
153
|
|
|
135
154
|
unless ['concept', 'reference', 'task', 'map', 'attributes', 'snippet'].include? document_type
|
|
136
|
-
|
|
155
|
+
return nil
|
|
137
156
|
end
|
|
138
157
|
|
|
158
|
+
return document_type
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def parse_topic input
|
|
162
|
+
doc = Asciidoctor.load input, safe: :secure, attributes: @attr
|
|
163
|
+
|
|
164
|
+
document_title = doc.title ? doc.title.gsub(/<[^>]*>/, '') : nil
|
|
165
|
+
document_type = get_content_type doc.attributes
|
|
166
|
+
|
|
139
167
|
return document_title, document_type
|
|
140
168
|
end
|
|
141
169
|
|
|
@@ -147,34 +175,47 @@ module AsciidoctorDitaMap
|
|
|
147
175
|
doc = Asciidoctor.load input, safe: :safe, catalog_assets: true, attributes: @attr, base_dir: base_dir
|
|
148
176
|
|
|
149
177
|
include_files = doc.catalog[:include_files] ? doc.catalog[:include_files] : []
|
|
150
|
-
|
|
151
|
-
|
|
178
|
+
map_id = doc.id ? doc.id.gsub(/["']/, '') : nil
|
|
179
|
+
map_title = doc.title ? doc.title.gsub(/<[^>]*>/, '') : nil
|
|
180
|
+
map_type = get_content_type doc.attributes
|
|
181
|
+
|
|
182
|
+
info = {
|
|
183
|
+
:id => map_id,
|
|
184
|
+
:title => map_title,
|
|
185
|
+
:type => map_type
|
|
186
|
+
}
|
|
152
187
|
|
|
153
|
-
return include_files,
|
|
188
|
+
return include_files, info
|
|
154
189
|
end
|
|
155
190
|
|
|
156
|
-
def convert_map input, base_dir, prepended = ''
|
|
191
|
+
def convert_map input, base_dir, prepended = '', file = nil
|
|
157
192
|
result = ''
|
|
158
193
|
|
|
159
|
-
include_files,
|
|
194
|
+
include_files, map = parse_map prepended + input, base_dir
|
|
160
195
|
|
|
161
196
|
xml = REXML::Document.new
|
|
162
197
|
xml.context[:attribute_quote] = :quote
|
|
163
198
|
xml << REXML::XMLDecl.new('1.0', 'utf-8')
|
|
164
199
|
xml << REXML::DocType.new('map', 'PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd"')
|
|
165
200
|
|
|
166
|
-
if
|
|
167
|
-
xml_root = xml.add_element('map', { 'id' =>
|
|
201
|
+
if map[:id] and @opts[:id]
|
|
202
|
+
xml_root = xml.add_element('map', { 'id' => map[:id] })
|
|
168
203
|
else
|
|
169
204
|
xml_root = xml.add_element('map')
|
|
170
205
|
end
|
|
171
206
|
|
|
172
|
-
if
|
|
173
|
-
xml_title
|
|
174
|
-
xml_title.text =
|
|
207
|
+
if map[:title] and @opts[:title]
|
|
208
|
+
xml_title = xml_root.add_element('title')
|
|
209
|
+
xml_title.text = map[:title]
|
|
175
210
|
end
|
|
176
211
|
|
|
177
|
-
|
|
212
|
+
if @opts[:self] and file
|
|
213
|
+
attributes = compose_topicref_attributes file, map[:title], map[:type]
|
|
214
|
+
xml_self = xml_root.add_element('topicref', attributes)
|
|
215
|
+
stack = [{ :offset => 0, :element => xml_self }]
|
|
216
|
+
else
|
|
217
|
+
stack = [{ :offset => 0, :element => xml_root }]
|
|
218
|
+
end
|
|
178
219
|
|
|
179
220
|
include_files.each do |file|
|
|
180
221
|
target = file[:target]
|
|
@@ -209,17 +250,10 @@ module AsciidoctorDitaMap
|
|
|
209
250
|
xml_parent = stack.last[:element]
|
|
210
251
|
|
|
211
252
|
if include_type == 'map'
|
|
212
|
-
|
|
213
|
-
attributes = { 'href' => file_name, 'format' => 'ditamap' }
|
|
214
|
-
attributes['type'] = include_type if @opts[:type]
|
|
215
|
-
|
|
253
|
+
attributes = compose_mapref_attributes target, include_type
|
|
216
254
|
xml_element = xml_parent.add_element('mapref', attributes)
|
|
217
255
|
else
|
|
218
|
-
|
|
219
|
-
attributes = { 'href' => file_name }
|
|
220
|
-
attributes['navtitle'] = include_title if include_title and @opts[:navtitle]
|
|
221
|
-
attributes['type'] = include_type if include_type and @opts[:type]
|
|
222
|
-
|
|
256
|
+
attributes = compose_topicref_attributes target, include_title, include_type
|
|
223
257
|
xml_element = xml_parent.add_element('topicref', attributes)
|
|
224
258
|
end
|
|
225
259
|
|
|
@@ -254,7 +288,11 @@ module AsciidoctorDitaMap
|
|
|
254
288
|
output = @opts[:output] ? @opts[:output] : Pathname.new(file).sub_ext('.ditamap').to_s
|
|
255
289
|
end
|
|
256
290
|
|
|
257
|
-
|
|
291
|
+
if @opts[:self] and file != $stdin
|
|
292
|
+
result = convert_map input, base_dir, prepended, file
|
|
293
|
+
else
|
|
294
|
+
result = convert_map input, base_dir, prepended
|
|
295
|
+
end
|
|
258
296
|
|
|
259
297
|
if output == $stdout
|
|
260
298
|
$stdout.write result
|
data/lib/dita-map/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: asciidoctor-dita-map
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jaromir Hradilek
|
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
139
139
|
- !ruby/object:Gem::Version
|
|
140
140
|
version: '0'
|
|
141
141
|
requirements: []
|
|
142
|
-
rubygems_version:
|
|
142
|
+
rubygems_version: 4.0.6
|
|
143
143
|
specification_version: 4
|
|
144
144
|
summary: Convert an AsciiDoc file to a DITA map
|
|
145
145
|
test_files: []
|