# Methods added to this helper will be available to all templates in the application. module ApplicationHelper # Evaluate a block, but if the block raises an exception, nil is returned # This is useful for evaluating an expression that may have one of # it's component equal to nil. def n begin return yield rescue Exception nil end end def datetime(time) return nil unless time time.strftime '%A %B %d, %Y %I:%M %p' end def chop_url!(url) url = url.sub /^http:\/\//, '' url = url.sub /\/$/, '' url end def uger_version '0.6.1' end def normalize_phone(phone) t = ' ' digits = Array.new index = 0 while index < phone.size t[0] = phone[index] if t =~ /\d/ digits << t.clone end index += 1 end if digits.size != 10 # We don't know how to deal with extension or international prefix yet. return phone end "(#{digits[0]}#{digits[1]}#{digits[2]}) #{digits[3]}#{digits[4]}#{digits[5]}-#{digits[6]}#{digits[7]}#{digits[8]}#{digits[9]}" end end module InputSanitization include ActionView::Helpers::TextHelper def write_attribute(name, *args) if args.first.is_a?(String) && !(@input_sanitization_exceptions || []).include?(name) super name, sanitize(args.first) else super end end end