Module: Dita
- Includes:
- Duxml
- Defined in:
- lib/ruby-dita.rb,
lib/ruby-dita/table.rb,
lib/ruby-dita/topic.rb
Constant Summary collapse
- GRAMMAR_PATH =
File.(File.dirname(__FILE__) + '/../xml/dita_grammar.xml')
Class Method Summary collapse
-
.grammar ⇒ GrammarClass
Returns Dita grammar as standalone object.
-
.row(ary) ⇒ Element
Correctly formatted row.
-
.table(column_info, rows = []) ⇒ Element
Valid Dita <table>.
-
.topic(title, content = nil) ⇒ Element
Valid Dita <topic>.
Instance Method Summary collapse
-
#load(path) ⇒ Doc
XML document.
Class Method Details
.grammar ⇒ GrammarClass
Returns Dita grammar as standalone object
17 18 19 |
# File 'lib/ruby-dita.rb', line 17 def self.grammar Ox.parse_obj File.read GRAMMAR_PATH end |
.row(ary) ⇒ Element
Returns correctly formatted row.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby-dita/table.rb', line 37 def self.row(ary) return ary if ary.all? do |a| a.respond_to?(:name) and a.name == 'row' end Element.new('row') << ary.collect do |entry| if entry.is_a?(Element) and entry.name == 'entry' entry else Element.new('entry') << entry end end end |
.table(column_info, rows = []) ⇒ Element
Returns valid Dita <table>.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby-dita/table.rb', line 8 def self.table(column_info, rows=[]) t = Element.new('table') headings = [] case column_info when Array headings = column_info if column_info.first.is_a?(String) t << column_info if column_info.first.is_a?(Element) when Hash headings = column_info.keys t << column_info.values else # TODO raise error? end tgroup = Element.new('tgroup') if headings.any? tgroup << Element.new('thead', [Element.new('row')]) headings.each do |h| tgroup.thead.row << Element.new('entry', [h]) end end tgroup[:cols] = column_info.size.to_s tgroup << Element.new('tbody') tgroup.tbody << rows.collect do |r| row r end t << tgroup end |
.topic(title, content = nil) ⇒ Element
Returns valid Dita <topic>.
9 10 11 12 13 14 |
# File 'lib/ruby-dita/topic.rb', line 9 def self.topic(title, content=nil) t = Element.new('topic') t[:id] = "topic#{t.object_id.to_s}" t << Element.new('title', [title]) t << Element.new('body', content) if content end |
Instance Method Details
#load(path) ⇒ Doc
Returns XML document.
12 13 14 |
# File 'lib/ruby-dita.rb', line 12 def load(path) super(path, GRAMMAR_PATH) end |