ruby-dita 0.3.0 → 0.3.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/ruby-dita/table.rb +41 -42
- data/lib/ruby-dita/topic.rb +9 -11
- data/lib/ruby-dita.rb +0 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f41ece3ad990f2f6fdf3b602d36ef3bac139cb1
|
4
|
+
data.tar.gz: 1c504ab70a19959676cab6fb51d87eca32abd123
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a0ff8cf76f4d57a3f27b5dcf2439a4bdbb04cbbe8f7f6ac619ef1dbd0ab9890ad9aa557a62b3461b0f96b4848996213c813f93e17edd64698ba9a8f67e58314
|
7
|
+
data.tar.gz: 70e259e5a7fbf820f6f6f215b2ff045ee66aa5925fa5d2ecd9b8cb443cf7418de908fedbb70222ec2a02122f28b1eb9ad1841d3c9562c87878bbe491bc2fb9b3
|
data/lib/ruby-dita/table.rb
CHANGED
@@ -1,49 +1,48 @@
|
|
1
1
|
require 'duxml'
|
2
2
|
|
3
3
|
module Dita
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
tgroup.thead.row << Element.new('entry', [h])
|
27
|
-
end
|
4
|
+
include Duxml
|
5
|
+
# @param column_info [Array, Hash] if Array of Strings, column headings; if Array of Elements, colspecs; if Hash, keys are strings for column headings; values are <colspec> elements
|
6
|
+
# @param rows [Array] array of rows with which to populate table; can either be XML <row> elements or Strings representing values
|
7
|
+
# @return [Element] valid Dita <table>
|
8
|
+
def self.table(column_info, rows=[])
|
9
|
+
t = Element.new('table')
|
10
|
+
headings = []
|
11
|
+
case column_info
|
12
|
+
when Array
|
13
|
+
headings = column_info if column_info.first.is_a?(String)
|
14
|
+
t << column_info if column_info.first.is_a?(Element)
|
15
|
+
when Hash
|
16
|
+
headings = column_info.keys
|
17
|
+
t << column_info.values
|
18
|
+
else
|
19
|
+
# TODO raise error?
|
20
|
+
end
|
21
|
+
tgroup = Element.new('tgroup')
|
22
|
+
if headings.any?
|
23
|
+
tgroup << Element.new('thead', [Element.new('row')])
|
24
|
+
headings.each do |h|
|
25
|
+
tgroup.thead.row << Element.new('entry', [h])
|
28
26
|
end
|
29
|
-
|
30
|
-
tgroup[:cols] = column_info.size.to_s
|
31
|
-
tgroup << Element.new('tbody')
|
32
|
-
tgroup.tbody << rows.collect do |r| row r end
|
33
|
-
t << tgroup
|
34
27
|
end
|
35
28
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
29
|
+
tgroup[:cols] = column_info.size.to_s
|
30
|
+
tgroup << Element.new('tbody')
|
31
|
+
tgroup.tbody << rows.collect do |r| row r end
|
32
|
+
t << tgroup
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param ary [Array] array of row entries or entry values
|
36
|
+
# @return [Element] correctly formatted row
|
37
|
+
def self.row(ary)
|
38
|
+
return ary if ary.all? do |a| a.respond_to?(:name) and a.name == 'row' end
|
39
|
+
Element.new('row') <<
|
40
|
+
ary.collect do |entry|
|
41
|
+
if entry.is_a?(Element) and entry.name == 'entry'
|
42
|
+
entry
|
43
|
+
else
|
44
|
+
Element.new('entry') << entry
|
46
45
|
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end # end of module
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end # end of module Table
|
data/lib/ruby-dita/topic.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
require 'duxml'
|
2
2
|
|
3
3
|
module Dita
|
4
|
-
|
4
|
+
include Duxml
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
t << Element.new('title', [title])
|
15
|
-
end
|
6
|
+
# @param title [String, Element] string or XML rich-text
|
7
|
+
# @param content [Array] optional topic body content in array form
|
8
|
+
# @return [Element] valid Dita <topic>
|
9
|
+
def self.topic(title, content=nil)
|
10
|
+
t = Element.new('topic')
|
11
|
+
t[:id] = "topic#{t.object_id.to_s}"
|
12
|
+
t << Element.new('title', [title])
|
13
|
+
t << Element.new('body', content) if content
|
16
14
|
end
|
17
15
|
end
|
data/lib/ruby-dita.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-dita
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Kong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: duxml
|