class AdHocTemplate::DefaultTagFormatter

Constants

FUNCTION_TABLE

Public Class Methods

assign_format(format_label, &func) click to toggle source
# File lib/ad_hoc_template/default_tag_formatter.rb, line 10
def self.assign_format(format_label, &func)
  if format_label.kind_of?(Hash) && !func
    func_name, label = format_label.to_a.flatten
    FUNCTION_TABLE[label] = func_name
  else
    FUNCTION_TABLE[format_label] = func
  end
end

Public Instance Methods

default(var, record) click to toggle source
# File lib/ad_hoc_template/default_tag_formatter.rb, line 33
def default(var, record)
  record[var] || "[#{var}]"
end
find_function(format_label) click to toggle source
# File lib/ad_hoc_template/default_tag_formatter.rb, line 19
def find_function(format_label)
  FUNCTION_TABLE[format_label] || :default
end
format(format_label, var, record) click to toggle source
# File lib/ad_hoc_template/default_tag_formatter.rb, line 23
def format(format_label, var, record)
  func = find_function(format_label)
  case func
  when Symbol, String
    send(func, var, record)
  else
    func.call(var, record)
  end
end
html_encode(var, record) click to toggle source
# File lib/ad_hoc_template/default_tag_formatter.rb, line 37
def html_encode(var, record)
  HtmlElement.escape(record[var] || var)
end