asciidoctor-dita-map 0.9.0 → 0.9.2
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/catalog.rb +5 -1
- data/lib/dita-map/cli.rb +83 -32
- 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: b3ca734004441a43e80c5537935c0bbbf2ff555b9ff00810a6f80f5f461003ad
|
|
4
|
+
data.tar.gz: f1f533b51dac4e4ebbcbf8632562c3caddb1a70bf5d1c7bbc1da73739ae97d07
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0bfff3d85f8c89f127af916d7d0c8c3c577e1cb2d53be274bc8c2d252af73f9dd157d231acc2385948bead240f19fb296fafe03eb6fadf2c670f18cfe9ba156f
|
|
7
|
+
data.tar.gz: 9058a374b8c72b5edf4397208ee3167a63154fc956b4206ef00b86739c91d52151e6223de1791e3e901289be59ac856eac12306dd8fe478018d3c36011127546
|
data/lib/dita-map/catalog.rb
CHANGED
|
@@ -30,11 +30,15 @@ class CatalogIncludeDirectives < Asciidoctor::Extensions::IncludeProcessor
|
|
|
30
30
|
|
|
31
31
|
def process doc, reader, target, attributes
|
|
32
32
|
offset = attributes['leveloffset'].to_i
|
|
33
|
+
chunk = attributes['chunk'] or nil
|
|
34
|
+
toc = attributes['toc'] or nil
|
|
33
35
|
|
|
34
36
|
doc.catalog[:include_files] = [] unless doc.catalog[:include_files]
|
|
35
37
|
doc.catalog[:include_files].append({
|
|
36
38
|
:target => target,
|
|
37
|
-
:offset => offset
|
|
39
|
+
:offset => offset,
|
|
40
|
+
:chunk => chunk,
|
|
41
|
+
:toc => toc
|
|
38
42
|
})
|
|
39
43
|
|
|
40
44
|
reader
|
data/lib/dita-map/cli.rb
CHANGED
|
@@ -33,11 +33,14 @@ module AsciidoctorDitaMap
|
|
|
33
33
|
def initialize name, argv
|
|
34
34
|
@attr = []
|
|
35
35
|
@opts = {
|
|
36
|
+
:chunk => true,
|
|
36
37
|
:id => true,
|
|
37
38
|
:navtitle => true,
|
|
38
39
|
:output => false,
|
|
39
40
|
:title => true,
|
|
41
|
+
:toc => true,
|
|
40
42
|
:type => true,
|
|
43
|
+
:self => false,
|
|
41
44
|
:verbose => false
|
|
42
45
|
}
|
|
43
46
|
@prep = []
|
|
@@ -67,6 +70,10 @@ module AsciidoctorDitaMap
|
|
|
67
70
|
@prep.append file
|
|
68
71
|
end
|
|
69
72
|
|
|
73
|
+
opt.on('-i', '--include-self', 'make the supplied file the toplevel topicref') do
|
|
74
|
+
@opts[:self] = true
|
|
75
|
+
end
|
|
76
|
+
|
|
70
77
|
opt.separator ''
|
|
71
78
|
|
|
72
79
|
opt.on('-I', '--no-id', 'do not generate the map id attribute') do
|
|
@@ -77,10 +84,18 @@ module AsciidoctorDitaMap
|
|
|
77
84
|
@opts[:title] = false
|
|
78
85
|
end
|
|
79
86
|
|
|
87
|
+
opt.on('-C', '--no-chunk', 'do not generate the chunk attribute') do
|
|
88
|
+
@opts[:chunk] = false
|
|
89
|
+
end
|
|
90
|
+
|
|
80
91
|
opt.on('-N', '--no-navtitle', 'do not generate the navtitle attribute') do
|
|
81
92
|
@opts[:navtitle] = false
|
|
82
93
|
end
|
|
83
94
|
|
|
95
|
+
opt.on('-O', '--no-toc', 'do not generate the toc attribute') do
|
|
96
|
+
@opts[:toc] = false
|
|
97
|
+
end
|
|
98
|
+
|
|
84
99
|
opt.on('-T', '--no-type', 'do not generate the type attribute') do
|
|
85
100
|
@opts[:type] = false
|
|
86
101
|
end
|
|
@@ -118,14 +133,31 @@ module AsciidoctorDitaMap
|
|
|
118
133
|
return args
|
|
119
134
|
end
|
|
120
135
|
|
|
121
|
-
def
|
|
122
|
-
|
|
123
|
-
|
|
136
|
+
def compose_mapref_attributes file_info, type
|
|
137
|
+
target_file = file_info[:target].sub(/\.adoc$/, '.ditamap')
|
|
138
|
+
attributes = { 'href' => target_file, 'format' => 'ditamap' }
|
|
139
|
+
attributes['type'] = type if @opts[:type]
|
|
140
|
+
attributes['chunk'] = file_info[:chunk] if @opts[:chunk] and file_info[:chunk]
|
|
141
|
+
attributes['toc'] = file_info[:toc] if @opts[:toc] and file_info[:toc]
|
|
124
142
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
143
|
+
return attributes
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def compose_topicref_attributes file_info, title, type
|
|
147
|
+
target_file = file_info[:target].sub(/\.adoc$/, '.dita')
|
|
148
|
+
attributes = { 'href' => target_file }
|
|
149
|
+
attributes['navtitle'] = title if @opts[:navtitle] and title
|
|
150
|
+
attributes['type'] = type if @opts[:type] and type and ['concept', 'reference', 'task'].include? type
|
|
151
|
+
attributes['chunk'] = file_info[:chunk] if @opts[:chunk] and file_info[:chunk]
|
|
152
|
+
attributes['toc'] = file_info[:toc] if @opts[:toc] and file_info[:toc]
|
|
153
|
+
|
|
154
|
+
return attributes
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def get_content_type attributes
|
|
158
|
+
document_type = attributes['_mod-docs-content-type'] ? attributes['_mod-docs-content-type'].downcase : nil
|
|
159
|
+
document_type = attributes['_content-type'] ? attributes['_content-type'].downcase : nil unless document_type
|
|
160
|
+
document_type = attributes['_module-type'] ? attributes['_module-type'].downcase : nil unless document_type
|
|
129
161
|
|
|
130
162
|
if document_type
|
|
131
163
|
document_type.sub!(/^assembly$/, 'concept')
|
|
@@ -133,9 +165,18 @@ module AsciidoctorDitaMap
|
|
|
133
165
|
end
|
|
134
166
|
|
|
135
167
|
unless ['concept', 'reference', 'task', 'map', 'attributes', 'snippet'].include? document_type
|
|
136
|
-
|
|
168
|
+
return nil
|
|
137
169
|
end
|
|
138
170
|
|
|
171
|
+
return document_type
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def parse_topic input
|
|
175
|
+
doc = Asciidoctor.load input, safe: :secure, attributes: @attr
|
|
176
|
+
|
|
177
|
+
document_title = doc.title ? doc.title.gsub(/<[^>]*>/, '') : nil
|
|
178
|
+
document_type = get_content_type doc.attributes
|
|
179
|
+
|
|
139
180
|
return document_title, document_type
|
|
140
181
|
end
|
|
141
182
|
|
|
@@ -147,38 +188,51 @@ module AsciidoctorDitaMap
|
|
|
147
188
|
doc = Asciidoctor.load input, safe: :safe, catalog_assets: true, attributes: @attr, base_dir: base_dir
|
|
148
189
|
|
|
149
190
|
include_files = doc.catalog[:include_files] ? doc.catalog[:include_files] : []
|
|
150
|
-
|
|
151
|
-
|
|
191
|
+
map_id = doc.id ? doc.id.gsub(/["']/, '') : nil
|
|
192
|
+
map_title = doc.title ? doc.title.gsub(/<[^>]*>/, '') : nil
|
|
193
|
+
map_type = get_content_type doc.attributes
|
|
194
|
+
|
|
195
|
+
info = {
|
|
196
|
+
:id => map_id,
|
|
197
|
+
:title => map_title,
|
|
198
|
+
:type => map_type
|
|
199
|
+
}
|
|
152
200
|
|
|
153
|
-
return include_files,
|
|
201
|
+
return include_files, info
|
|
154
202
|
end
|
|
155
203
|
|
|
156
|
-
def convert_map input, base_dir, prepended = ''
|
|
204
|
+
def convert_map input, base_dir, prepended = '', file = nil
|
|
157
205
|
result = ''
|
|
158
206
|
|
|
159
|
-
include_files,
|
|
207
|
+
include_files, map = parse_map prepended + input, base_dir
|
|
160
208
|
|
|
161
209
|
xml = REXML::Document.new
|
|
162
210
|
xml.context[:attribute_quote] = :quote
|
|
163
211
|
xml << REXML::XMLDecl.new('1.0', 'utf-8')
|
|
164
212
|
xml << REXML::DocType.new('map', 'PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd"')
|
|
165
213
|
|
|
166
|
-
if
|
|
167
|
-
xml_root = xml.add_element('map', { 'id' =>
|
|
214
|
+
if map[:id] and @opts[:id]
|
|
215
|
+
xml_root = xml.add_element('map', { 'id' => map[:id] })
|
|
168
216
|
else
|
|
169
217
|
xml_root = xml.add_element('map')
|
|
170
218
|
end
|
|
171
219
|
|
|
172
|
-
if
|
|
173
|
-
xml_title
|
|
174
|
-
xml_title.text =
|
|
220
|
+
if map[:title] and @opts[:title]
|
|
221
|
+
xml_title = xml_root.add_element('title')
|
|
222
|
+
xml_title.text = map[:title]
|
|
175
223
|
end
|
|
176
224
|
|
|
177
|
-
|
|
225
|
+
if @opts[:self] and file
|
|
226
|
+
attributes = compose_topicref_attributes({ :target => file }, map[:title], map[:type])
|
|
227
|
+
xml_self = xml_root.add_element('topicref', attributes)
|
|
228
|
+
stack = [{ :offset => 0, :element => xml_self }]
|
|
229
|
+
else
|
|
230
|
+
stack = [{ :offset => 0, :element => xml_root }]
|
|
231
|
+
end
|
|
178
232
|
|
|
179
|
-
include_files.each do |
|
|
180
|
-
target =
|
|
181
|
-
offset =
|
|
233
|
+
include_files.each do |file_info|
|
|
234
|
+
target = file_info[:target]
|
|
235
|
+
offset = file_info[:offset]
|
|
182
236
|
last_offset = stack.last[:offset]
|
|
183
237
|
full_path = base_dir + target
|
|
184
238
|
|
|
@@ -209,17 +263,10 @@ module AsciidoctorDitaMap
|
|
|
209
263
|
xml_parent = stack.last[:element]
|
|
210
264
|
|
|
211
265
|
if include_type == 'map'
|
|
212
|
-
|
|
213
|
-
attributes = { 'href' => file_name, 'format' => 'ditamap' }
|
|
214
|
-
attributes['type'] = include_type if @opts[:type]
|
|
215
|
-
|
|
266
|
+
attributes = compose_mapref_attributes file_info, include_type
|
|
216
267
|
xml_element = xml_parent.add_element('mapref', attributes)
|
|
217
268
|
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
|
-
|
|
269
|
+
attributes = compose_topicref_attributes file_info, include_title, include_type
|
|
223
270
|
xml_element = xml_parent.add_element('topicref', attributes)
|
|
224
271
|
end
|
|
225
272
|
|
|
@@ -254,7 +301,11 @@ module AsciidoctorDitaMap
|
|
|
254
301
|
output = @opts[:output] ? @opts[:output] : Pathname.new(file).sub_ext('.ditamap').to_s
|
|
255
302
|
end
|
|
256
303
|
|
|
257
|
-
|
|
304
|
+
if @opts[:self] and file != $stdin
|
|
305
|
+
result = convert_map input, base_dir, prepended, file
|
|
306
|
+
else
|
|
307
|
+
result = convert_map input, base_dir, prepended
|
|
308
|
+
end
|
|
258
309
|
|
|
259
310
|
if output == $stdout
|
|
260
311
|
$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.2
|
|
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: []
|