Class: FormatSimpleTable

Inherits:
ClWiki::CustomFormatter show all
Defined in:
lib/cl_wiki/format/format.simpletable.rb

Class Method Summary collapse

Class Method Details

.format_content(content, page = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cl_wiki/format/format.simpletable.rb', line 6

def FormatSimpleTable.format_content(content, page=nil)
  table_attr = content.scan(/<simpletable(.*?)>/m).to_s.strip
  table_attr = 'border="1"' if table_attr.empty?
  content.gsub!(/<simpletable.*?>/m, '')
  content.gsub!(/<\/simpletable>/m, '')
  content.strip!
  lines = content.split("\n")
  lines.collect! do |ln|
    ln.gsub!(/\t/, '  ')
    '<tr><td>' + ln.gsub(/  +/, '</td><td>') + '</td></tr>'
  end
  lines.collect! do |ln| ln.gsub(/<td>\s*?<\/td>/, '<td>&nbsp;</td>') end

  # if you do a .join("\n"), then the \n will be converted to <br>
  # ... so don't do that    
  "<table #{table_attr}>\n" + lines.join("") + "</table>"
end

.match_reObject



2
3
4
# File 'lib/cl_wiki/format/format.simpletable.rb', line 2

def FormatSimpleTable.match_re
  /<simpletable.*?>.*?<\/simpletable>/m
end