Class: TableFu::Formatting

Inherits:
Object
  • Object
show all
Defined in:
lib/table_setter/table.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) bar(percent)

In order to show a sideways bar chart, we’re extending the builtin TableFu formatters.



218
219
220
221
222
223
224
# File 'lib/table_setter/table.rb', line 218

def bar(percent)
  percent = percent.to_f
  if percent < 1
    percent = percent * 100
  end
  "<div class=\"bar\" style=\"width:#{percent}%\">#{percent}%</div>"
end

+ (Object) join(*args)

join multiple columns, with optional delimiter



251
252
253
# File 'lib/table_setter/table.rb', line 251

def join(*args)
  args.join(" ")
end

+ (Object) joinbr(*args)



255
256
257
# File 'lib/table_setter/table.rb', line 255

def joinbr(*args)
  args.join("<br>")
end

+ (Object) joincomma(*args)



259
260
261
# File 'lib/table_setter/table.rb', line 259

def joincomma(*args)
  args.join(", ")
end

format as a link, if the href is empty don’t make the link active



231
232
233
234
235
236
237
238
# File 'lib/table_setter/table.rb', line 231

def link(linkname, href)
  title = linkname.to_s.gsub(/(["])/, "'")
  if !href.value.nil? && !href.value.to_s().empty?
    "<a href=\"#{href}\" title=\"#{title}\">#{linkname}</a>"
  else
    "<a title=\"#{title}\">#{linkname}</a>"
  end
end

+ (Object) markdown(cell)

markdown formatting in tablefu cells



226
227
228
# File 'lib/table_setter/table.rb', line 226

def markdown(cell)
  RDiscount.new(cell).to_html
end

+ (Object) small(cell)

make it small



246
247
248
# File 'lib/table_setter/table.rb', line 246

def small(cell)
  "<small>#{cell}</small>"
end

+ (Object) strong(cell)

make it strong



241
242
243
# File 'lib/table_setter/table.rb', line 241

def strong(cell)
  "<strong>#{cell}</strong>"
end