Module: Campo::Plugins::Aria::InstanceMethods::Convenience
- Defined in:
- lib/campo/plugins/aria.rb
Instance Method Summary collapse
-
#describe(message, opts = {}) ⇒ Object
Adds aria-describedby along with a span.
Instance Method Details
#text(message, opts) ⇒ String #text(message-tuples, opts) ⇒ String #text(messages, opts) ⇒ String
Adds aria-describedby along with a span.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/campo/plugins/aria.rb', line 39 def describe( , opts={} ) label, field = if self.kind_of? Campo::Label [self,self.fields.first] elsif (parent = self.parent).kind_of? Campo::Label [parent, self] end span_id = "#{label.attributes[:for]}_description" if .respond_to? :map # array span = Campo::Span.new( span_id, "%ul", opts ) .each do |(x,o)| o ||= {} li = Campo.literal("%li",o) << Campo.literal(x) span.fields.first << li end else span = Campo::Span.new( span_id, , opts ) end label.fields.unshift span field.attributes[:"aria-describedby"] = span_id self end |