Class: Presenting::Attribute
- Inherits:
-
Object
- Object
- Presenting::Attribute
- Includes:
- Configurable
- Defined in:
- lib/presenting/attribute.rb
Overview
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
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#sanitize ⇒ Object
writeonly
whether html should be sanitize.
-
#value ⇒ Object
Where a field’s value comes from.
Instance Method Summary collapse
- #id ⇒ Object
-
#id=(val) ⇒ Object
The short programmatic name for this field.
- #sanitize? ⇒ Boolean
-
#value_from(obj) ⇒ Object
:nodoc:.
Methods included from Configurable
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/presenting/attribute.rb', line 16 def name @name end |
#sanitize=(value) ⇒ Object (writeonly)
whether html should be sanitize. right now this actually means html escaping. consider: by default, do not sanitize if value is a String?
46 47 48 |
# File 'lib/presenting/attribute.rb', line 46 def sanitize=(value) @sanitize = value end |
#value ⇒ Object
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
31 32 33 |
# File 'lib/presenting/attribute.rb', line 31 def value @value end |
Instance Method Details
#id ⇒ Object
23 24 25 |
# File 'lib/presenting/attribute.rb', line 23 def id @id ||= name.to_s.underscore.gsub(/[^a-z0-9]/i, '_').gsub(/__+/, '_').sub(/_$/, '') end |
#id=(val) ⇒ Object
The short programmatic name for this field. Can be used as a CSS class, sorting name, etc.
19 20 21 |
# File 'lib/presenting/attribute.rb', line 19 def id=(val) @id = val.to_s end |
#sanitize? ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/presenting/attribute.rb', line 47 def sanitize? unless defined? @sanitize @sanitize = Presenting::Defaults.sanitize_fields end @sanitize end |
#value_from(obj) ⇒ Object
:nodoc:
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/presenting/attribute.rb', line 33 def value_from(obj) #:nodoc: case value when Symbol obj.is_a?(Hash) ? obj[value] : obj.send(value) when String value when Proc value.call(obj) end end |