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.



222
223
224
225
226
227
228
# File 'lib/table_setter/table.rb', line 222

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



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

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

+ (Object) joinbr(*args)



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

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

+ (Object) joincomma(*args)



263
264
265
# File 'lib/table_setter/table.rb', line 263

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

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



235
236
237
238
239
240
241
242
# File 'lib/table_setter/table.rb', line 235

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



230
231
232
# File 'lib/table_setter/table.rb', line 230

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

+ (Object) small(cell)

make it small



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

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

+ (Object) strong(cell)

make it strong



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

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