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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8112cf72fa44fe758766f114e0803b07e1a09b3e
4
- data.tar.gz: f7c6af95c20666ebb70cdebc5902393d8652760e
3
+ metadata.gz: 7f41ece3ad990f2f6fdf3b602d36ef3bac139cb1
4
+ data.tar.gz: 1c504ab70a19959676cab6fb51d87eca32abd123
5
5
  SHA512:
6
- metadata.gz: 6659ca96b56a8ff7c2ce81ec82ab55d2fd3d17d6aae35dec48ca72a8fa59eaf1ea1cf923940fcd860bff2f9c6ec8e814b0c9829e31fc732be60c655f57bf031d
7
- data.tar.gz: c3656c7632ec1731cd7cf229f84f117e6a735fc4d4f8a2eea629f0989caaab9fd05f3bbfe68731c1d7f42166559281ca4815d6ab2939e00cd781d4077629f132
6
+ metadata.gz: 6a0ff8cf76f4d57a3f27b5dcf2439a4bdbb04cbbe8f7f6ac619ef1dbd0ab9890ad9aa557a62b3461b0f96b4848996213c813f93e17edd64698ba9a8f67e58314
7
+ data.tar.gz: 70e259e5a7fbf820f6f6f215b2ff045ee66aa5925fa5d2ecd9b8cb443cf7418de908fedbb70222ec2a02122f28b1eb9ad1841d3c9562c87878bbe491bc2fb9b3
@@ -1,49 +1,48 @@
1
1
  require 'duxml'
2
2
 
3
3
  module Dita
4
- module Table
5
- include Duxml
6
- # @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
7
- # @param rows [Array] array of rows with which to populate table; can either be XML <row> elements or Strings representing values
8
- # @return [Element] valid Dita <table>
9
- def table(column_info, rows=[])
10
- t = Element.new('table')
11
- headings = []
12
- case column_info
13
- when Array
14
- headings = column_info if column_info.first.is_a?(String)
15
- t << column_info if column_info.first.is_a?(Element)
16
- when Hash
17
- headings = column_info.keys
18
- t << column_info.values
19
- else
20
- # TODO raise error?
21
- end
22
- tgroup = Element.new('tgroup')
23
- if headings.any?
24
- tgroup << Element.new('thead', [Element.new('row')])
25
- headings.each do |h|
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
- # @param ary [Array] array of row entries or entry values
37
- # @return [Element] correctly formatted row
38
- def row(ary)
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
45
- end
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
- end
48
- end # end of module Table
49
- end # end of module Dita
46
+ end
47
+ end
48
+ end # end of module Table
@@ -1,17 +1,15 @@
1
1
  require 'duxml'
2
2
 
3
3
  module Dita
4
- module Topic
4
+ include Duxml
5
5
 
6
- include Duxml
7
-
8
- # @param title [String, Element] string or XML rich-text
9
- # @param id [String] optional document-unique, XML-valid id string
10
- # @return [Element] valid Dita <topic>
11
- def topic(title, id=nil)
12
- t = Element.new('topic')
13
- t[:id] = id || "topic#{t.object_id.to_s}"
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
@@ -4,9 +4,6 @@ require_relative 'ruby-dita/topic'
4
4
  require_relative 'ruby-dita/table'
5
5
 
6
6
  module Dita
7
- include Topic
8
- include Table
9
-
10
7
  GRAMMAR_PATH = File.expand_path(File.dirname(__FILE__) + '/../xml/dita_grammar.xml')
11
8
  include Duxml
12
9
 
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.0
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-20 00:00:00.000000000 Z
11
+ date: 2016-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: duxml