class Presenting::Attribute

represents an attribute meant to be read from a record used for things like Grid and Details. not intended for things like Form or FieldSearch

Attributes

name[R]
sanitize[W]

whether html should be sanitize. right now this actually means html escaping. consider: by default, do not sanitize if value is a String?

value[RW]

Where a field’s value comes from. Depends heavily on the data type you provide.

  • String: fixed value (as provided)

  • Symbol: a method on the record (no arguments)

  • Proc: a custom block that accepts the record as an argument

Public Instance Methods

id() click to toggle source
# File lib/presenting/attribute.rb, line 23
def id
  @id ||= name.to_s.underscore.gsub(/[^a-z0-9]/i, '_').gsub(/__+/, '_').sub(/_$/, '')
end
id=(val) click to toggle source

The short programmatic name for this field. Can be used as a CSS class, sorting name, etc.

# File lib/presenting/attribute.rb, line 19
def id=(val)
  @id = val.to_s
end
name=(val) click to toggle source
# File lib/presenting/attribute.rb, line 8
def name=(val)
  self.value ||= val # don't lazy define :value, because we're about to typecast here
  if val.is_a? Symbol
    @name = val.to_s.titleize
  else
    @name = val.to_s
  end
end
sanitize?() click to toggle source
# File lib/presenting/attribute.rb, line 47
def sanitize?
  unless defined? @sanitize
    @sanitize = Presenting::Defaults.sanitize_fields
  end
  @sanitize
end