asciidoctor-dita-map 0.1.0 → 0.9.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 785383f1b9ac91dfff356c6ccfce6568a16af5c805715d24d294f8539d019d89
4
- data.tar.gz: 0be9258a03b8cff762cd30aae0657b6d105636b1a92334ed456ae68f57eabf1b
3
+ metadata.gz: 11f4d701aaa5c98c2ed6d3f78393c695e60cf981b2332e65f7b6c86288cfa5aa
4
+ data.tar.gz: 2db0005558356a8578d9f0bf89c08140bd74becc1372eed2aa85fc78ae406438
5
5
  SHA512:
6
- metadata.gz: d9dcb68378da10bd98c006524283da2741f32028988dcd2236ecaef3e5933e44a333f8502d8656e94c29dffff1373b542ed2efc75b48e6130d35cd5722395ac9
7
- data.tar.gz: c550422cc1932cc96c952c26a978d48d7788a8b5c9700ad3c51c1f544f29407d780fc5c13a25b06b11e78ae4b7b0751ab26caecf01020c449d94397b10b4d6db
6
+ metadata.gz: f5684c9fe2027bf5b99b080feb850a0840598a55f0f8fd0dcef5281a18cbf8a895aaab00a906e94eeecdb0befa7fd600ab68f867b7edf2906128ced51078e6df
7
+ data.tar.gz: 38d6f1d08c260b6438535a47dc81d48e151a2997e46fc4b79b93a799a8d600b9dcb45550e702c1bf2f38cc5b2670ec8b39a2ba7a1b3fecf3f1bca5c53de25241
data/README.md CHANGED
@@ -1,6 +1,100 @@
1
1
  # dita-map
2
2
 
3
- **dita-map** is a command line utility that converts a single AsciiDoc file to a DITA map.
3
+ **dita-map** is a command line utility that converts a single AsciiDoc file to a DITA map. It recognizes the [document title](https://docs.asciidoctor.org/asciidoc/latest/sections/titles-and-levels/#section-level-syntax) as the map title and uses the [include directives](https://docs.asciidoctor.org/asciidoc/latest/directives/include/) and their respective [leveloffset](https://docs.asciidoctor.org/asciidoc/latest/directives/include-with-leveloffset/#manipulate-heading-levels-with-leveloffset) values to compose the tree of `<mapref>` and `<topicref>` elements.
4
+
5
+ ## Installation
6
+
7
+ Install the `asciidoctor-dita-map` Ruby gem:
8
+
9
+ ```console
10
+ gem install asciidoctor-dita-map
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ To convert a single AsciiDoc file to a DITA map, supply it as an argument to the `dita-map` command:
16
+
17
+ ```console
18
+ $ dita-map your_file.adoc
19
+ ```
20
+
21
+ By default, `dita-map` creates a new file, `your_file.ditamap`, in the same directory as the source file. You can supply multiple files at the same time or use wildcards:
22
+
23
+ ```console
24
+ $ dita-map *.adoc
25
+ ```
26
+
27
+ When you do not supply any file names or specify `-` as the first argument, `dita-map` reads from standard input and prints the result to standard output. For example:
28
+
29
+ ```console
30
+ $ echo 'include::task.adoc[leveloffset=+1]' | dita-map
31
+ <?xml version='1.0' encoding='UTF-8'?>
32
+ <!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
33
+ <map>
34
+ <topicref href="task.dita" navtitle="A topic title" type="task" />
35
+ </map>
36
+ ```
37
+
38
+ ### Changing the output file name
39
+
40
+ To change the output file name or location, use the `-o` or `--out-file` command-line option:
41
+
42
+ ```console
43
+ $ dita-map input_file.adoc -o output_file.ditamap
44
+ ```
45
+
46
+ To print the result to standard output, use `-` as the output file name. For example:
47
+
48
+ ```console
49
+ $ dita-map input_file.adoc -o -
50
+ <?xml version='1.0' encoding='UTF-8'?>
51
+ <!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
52
+ <map>
53
+ <title>A map title</title>
54
+ <mapref href="another_map.ditamap" format="ditamap" type="map" />
55
+ <topicref href="concept.dita" navtitle="A concept title" type="concept">
56
+ <topicref href="task.dita" navtitle="A task title" type="task" />
57
+ </topicref>
58
+ </map>
59
+ ```
60
+
61
+ ### Supplying individual attribute definitions
62
+
63
+ If your AsciiDoc files use custom attributes that are defined externally, you can supply the attribute definitions with the `-a` or `--attribute` command-line option:
64
+
65
+ ```console
66
+ $ dita-map -a attribute_name=attribute_value your_file.adoc
67
+ ```
68
+
69
+ You can supply multiple `-a`/`--attribute` options at the same time.
70
+
71
+ ### Supplying attribute definition files
72
+
73
+ If listing individual attribute definitions is impractical, you can supply AsciiDoc files that contain the attribute definitions with the `-p` or `--prepend-file` command-line option:
74
+
75
+ ```console
76
+ $ dita-map -p definition_file.adoc your_file.adoc
77
+ ```
78
+
79
+ The supplied file is prepended to each AsciiDoc file during conversion. You can supply multiple `-p`/`--prepend-file` options at the same time or combine them with the `-a`/`--attribute` options to construct your attribute definitions. If you define the same attribute twice this way, the value defined by the `-a`/`--attribute` option takes precedence.
80
+
81
+ ## Recognized content types
82
+
83
+ To correctly recognize when to use the `<topicref>` and `<mapref>` elements and what values to assign to their `type` attributes, `dita-map` recognizes the following `:_mod-docs-content-type:` attribute definition values in included AsciiDoc files:
84
+
85
+ | AsciiDoc attribute | Output element | Output type value |
86
+ | --- | --- | --- |
87
+ | `ASSEMBLY` | `<topicref>` | `concept` |
88
+ | `CONCEPT` | `<topicref>` | `concept` |
89
+ | `PROCEDURE` | `<topicref>` | `task` |
90
+ | `REFERENCE` | `<topicref>` | `reference` |
91
+ | `MAP` | `<mapref>` | `map` |
92
+
93
+ For example, to ensure an included AsciiDoc file is recognized as a DITA map, add the following line at the top of the file:
94
+
95
+ ```asciidoc
96
+ :_mod-docs-content-type: MAP
97
+ ```
4
98
 
5
99
  ## Copyright
6
100
 
data/lib/dita-map/cli.rb CHANGED
@@ -37,7 +37,8 @@ module AsciidoctorDitaMap
37
37
  :navtitle => true,
38
38
  :output => false,
39
39
  :title => true,
40
- :type => true
40
+ :type => true,
41
+ :verbose => false
41
42
  }
42
43
  @prep = []
43
44
  @name = name
@@ -86,12 +87,18 @@ module AsciidoctorDitaMap
86
87
 
87
88
  opt.separator ''
88
89
 
90
+ opt.on('-v', '--verbose', 'report additional problems in the supplied files') do
91
+ @opts[:verbose] = true
92
+ end
93
+
94
+ opt.separator ''
95
+
89
96
  opt.on('-h', '--help', 'display this help and exit') do
90
97
  puts opt
91
98
  exit
92
99
  end
93
100
 
94
- opt.on('-v', '--version', 'display version information and exit') do
101
+ opt.on('-V', '--version', 'display version information and exit') do
95
102
  puts "#{@name} #{VERSION}"
96
103
  exit
97
104
  end
@@ -125,14 +132,13 @@ module AsciidoctorDitaMap
125
132
  document_type.sub!(/^procedure$/, 'task')
126
133
  end
127
134
 
128
- unless ['concept', 'reference', 'task', 'map'].include? document_type
135
+ unless ['concept', 'reference', 'task', 'map', 'attributes', 'snippet'].include? document_type
129
136
  document_type = nil
130
137
  end
131
138
 
132
139
  return document_title, document_type
133
140
  end
134
141
 
135
-
136
142
  def parse_map input, base_dir
137
143
  Asciidoctor::Extensions.register do
138
144
  include_processor CatalogIncludeDirectives
@@ -174,30 +180,33 @@ module AsciidoctorDitaMap
174
180
  target = file[:target]
175
181
  offset = file[:offset]
176
182
  last_offset = stack.last[:offset]
183
+ full_path = base_dir + target
184
+
185
+ if not File.exist? full_path and @opts[:verbose]
186
+ warn "#{@name}: warning: file not found: #{target}"
187
+ end
188
+
189
+ begin
190
+ include_title, include_type = parse_topic prepended + File.read(full_path)
191
+ next if ['attributes', 'snippet'].include? include_type
192
+ rescue
193
+ warn "#{@name}: warning: unable to read included file: #{target}"
194
+ include_title, include_type = nil, nil
195
+ end
177
196
 
178
197
  if offset == 0
179
- warn "#{@name}: warning: Invalid leveloffset - expected 1, got 0: #{target}"
198
+ warn "#{@name}: warning: invalid leveloffset - expected 1, got 0: #{target}"
180
199
  offset = 1
181
200
  elsif offset > last_offset and offset - last_offset > 1
182
201
  expected_offset = last_offset + 1
183
- warn "#{@name}: warning: Invalid leveloffset - expected #{expected_offset}, got #{offset}: #{target}"
184
- offset = expected_offset
202
+ warn "#{@name}: warning: invalid leveloffset - expected #{expected_offset}, got #{offset}: #{target}"
185
203
  end
186
204
 
187
205
  while stack.last[:offset] >= offset
188
206
  stack.pop
189
207
  end
190
208
 
191
- xml_parent = stack.last[:element]
192
-
193
- if @opts[:navtitle] or @opts[:type]
194
- begin
195
- include_title, include_type = parse_topic prepended + File.read(base_dir + target)
196
- rescue
197
- warn "#{@name}: warning: Unable to read included file: #{base_dir + target}"
198
- include_title, include_type = nil, nil
199
- end
200
- end
209
+ xml_parent = stack.last[:element]
201
210
 
202
211
  if include_type == 'map'
203
212
  file_name = target.sub(/\.adoc$/, '.ditamap')
@@ -24,5 +24,5 @@
24
24
  # frozen_string_literal: true
25
25
 
26
26
  module AsciidoctorDitaMap
27
- VERSION = '0.1.0'
27
+ VERSION = '0.9.0'
28
28
  end
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.1.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaromir Hradilek