ruby-dita 0.2.0 → 0.3.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
  SHA1:
3
- metadata.gz: 0cd6cf168af1a771c35bbc6349842743ff843c64
4
- data.tar.gz: 3ce9cd5a7ac57cb85343145cf30a57839c4804fb
3
+ metadata.gz: 8112cf72fa44fe758766f114e0803b07e1a09b3e
4
+ data.tar.gz: f7c6af95c20666ebb70cdebc5902393d8652760e
5
5
  SHA512:
6
- metadata.gz: 71eea0d79a3920a8d90d0458941c6e436fdf772384d36c4357f7eafa451d4d8afb04063d638ff6077383cbe6f57a60e953120e48fafaba2e143fb1ea32a078a9
7
- data.tar.gz: 1fd993202a3c91db1fab8bf22e9c74d9f113e9fb2deb601dc86105f1a768a88c788269fb3c19f8e25b8a10d169557de6ff289329fc8648225964f18e2476d881
6
+ metadata.gz: 6659ca96b56a8ff7c2ce81ec82ab55d2fd3d17d6aae35dec48ca72a8fa59eaf1ea1cf923940fcd860bff2f9c6ec8e814b0c9829e31fc732be60c655f57bf031d
7
+ data.tar.gz: c3656c7632ec1731cd7cf229f84f117e6a735fc4d4f8a2eea629f0989caaab9fd05f3bbfe68731c1d7f42166559281ca4815d6ab2939e00cd781d4077629f132
@@ -0,0 +1,49 @@
1
+ require 'duxml'
2
+
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
28
+ 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
+ end
35
+
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
46
+ end
47
+ end
48
+ end # end of module Table
49
+ end # end of module Dita
@@ -0,0 +1,17 @@
1
+ require 'duxml'
2
+
3
+ module Dita
4
+ module Topic
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
16
+ end
17
+ end
data/lib/ruby-dita.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  # Copyright (c) 2016 Freescale Semiconductor Inc.
2
2
 
3
- require 'duxml'
4
-
3
+ require_relative 'ruby-dita/topic'
4
+ require_relative 'ruby-dita/table'
5
5
 
6
6
  module Dita
7
+ include Topic
8
+ include Table
9
+
7
10
  GRAMMAR_PATH = File.expand_path(File.dirname(__FILE__) + '/../xml/dita_grammar.xml')
8
11
  include Duxml
9
12
 
@@ -12,4 +15,9 @@ module Dita
12
15
  def load(path)
13
16
  super(path, GRAMMAR_PATH)
14
17
  end
18
+
19
+ # @return [GrammarClass] returns Dita grammar as standalone object
20
+ def self.grammar
21
+ Ox.parse_obj File.read GRAMMAR_PATH
22
+ end
15
23
  end
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.2.0
4
+ version: 0.3.0
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-17 00:00:00.000000000 Z
11
+ date: 2016-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: duxml
@@ -31,9 +31,11 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - lib/ruby-dita/table.rb
35
+ - lib/ruby-dita/topic.rb
34
36
  - lib/ruby-dita.rb
35
37
  - xml/dita_grammar.xml
36
- homepage: https://github.com/ruby-dita/ruby-dita
38
+ homepage: https://github.com/ludocracy/ruby-dita
37
39
  licenses:
38
40
  - MIT
39
41
  metadata: {}