Class: View::Array Abstract

Inherits:
Formatter show all
Defined in:
lib/view/formatters/array.rb

Overview

This class is abstract.

Subclass this for html safe lists with formatted each support.

Direct Known Subclasses

Sentence

Instance Attribute Summary

Attributes inherited from Formatter

#block, #template, #value

Instance Method Summary (collapse)

Methods inherited from Formatter

#all_options, as, #format, #format!, inherited, #options, skip_blank_formatter, type

Instance Method Details

- (Boolean) all_safe?

Returns:



17
18
19
20
21
# File 'lib/view/formatters/array.rb', line 17

def all_safe?
  formatted_values.all? do |element|
    element.respond_to?(:html_safe?) && element.html_safe?
  end
end

- (Object) each_options



29
30
31
# File 'lib/view/formatters/array.rb', line 29

def each_options
  all_options[:each] || { :as => View.configuration.default_formatter }
end

- (Object) formatted_values



23
24
25
26
27
# File 'lib/view/formatters/array.rb', line 23

def formatted_values
  @formatted_values ||= value.map do |element|
    View.format(element, each_options, template, &block)
  end
end

- (Object) to_s

The formatted value will be html safe if all the elements in the array are safe too.



8
9
10
11
12
13
14
15
# File 'lib/view/formatters/array.rb', line 8

def to_s
  result = super
  if result.respond_to?(:html_safe) && all_safe?
    result.html_safe
  else
    result
  end
end