Class: MarkdownTable
- Defined in:
- lib/almirah/doc_items/markdown_table.rb
Instance Attribute Summary collapse
-
#column_names ⇒ Object
Returns the value of attribute column_names.
-
#rows ⇒ Object
Returns the value of attribute rows.
Attributes inherited from DocItem
Instance Method Summary collapse
- #addRow(row) ⇒ Object
-
#initialize(heading_row) ⇒ MarkdownTable
constructor
A new instance of MarkdownTable.
- #to_html ⇒ Object
Methods inherited from TextLine
add_lazy_doc_id, #bold, #bold_and_italic, #change_state, #format_string, #italic, #link
Constructor Details
#initialize(heading_row) ⇒ MarkdownTable
Returns a new instance of MarkdownTable.
8 9 10 11 |
# File 'lib/almirah/doc_items/markdown_table.rb', line 8 def initialize(heading_row) @column_names = heading_row.split('|') @rows = Array.new end |
Instance Attribute Details
#column_names ⇒ Object
Returns the value of attribute column_names.
5 6 7 |
# File 'lib/almirah/doc_items/markdown_table.rb', line 5 def column_names @column_names end |
#rows ⇒ Object
Returns the value of attribute rows.
6 7 8 |
# File 'lib/almirah/doc_items/markdown_table.rb', line 6 def rows @rows end |
Instance Method Details
#addRow(row) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/almirah/doc_items/markdown_table.rb', line 13 def addRow(row) #check if row contains a link if tmp = /(.*)\s+>\[(\S*)\]/.match(row) return false # this is not a regular Markdown table. # so the table type shall be changed and this row shall be passed one more time end columns = row.split('|') @rows.append(columns.map!{ |x| x.strip }) return true end |
#to_html ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/almirah/doc_items/markdown_table.rb', line 25 def to_html s = '' if @@htmlTableRenderInProgress s += "</table>\n" @@htmlTableRenderInProgress = false end s += "<table class=\"markdown_table\">\n" s += "\t<thead>" @column_names.each do |h| s += " <th>#{h}</th>" end s += " </thead>\n" @rows.each do |row| s += "\t<tr>\n" row.each do |col| if col.to_i > 0 && col.to_i.to_s == col # autoalign cells with numbers s += "\t\t<td style=\"text-align: center;\">#{col}</td>\n" else f_text = format_string(col) s += "\t\t<td>#{f_text}</td>\n" end end s += "\t</tr>\n" end s += "</table>\n" return s end |