Module: Bureaucrat::Utils
- Extended by:
- Utils
- Included in:
- Fields::ErrorHash, Fields::ErrorList, Forms::BoundField, Forms::Form, Formsets::BaseFormSet, Utils, Widgets::RadioFieldRenderer, Widgets::RadioInput, Widgets::Widget
- Defined in:
- lib/bureaucrat/utils.rb
Defined Under Namespace
Modules: SafeData
Classes: OrderedHash, SafeString, StringAccessHash
Constant Summary
- ESCAPES =
{
'&' => '&',
'<' => '<',
'>' => '>',
'"' => '"',
"'" => '''
}
Instance Method Summary
(collapse)
Instance Method Details
- (Boolean) blank_value?(value)
81
82
83
|
# File 'lib/bureaucrat/utils.rb', line 81
def blank_value?(value)
!value || value == ''
end
|
- (Object) conditional_escape(html)
100
101
102
|
# File 'lib/bureaucrat/utils.rb', line 100
def conditional_escape(html)
html.is_a?(SafeData) ? html : escape(html)
end
|
- (Object) escape(html)
96
97
98
|
# File 'lib/bureaucrat/utils.rb', line 96
def escape(html)
mark_safe(html.gsub(/[&<>"']/) {|match| ESCAPES[match]})
end
|
- (Object) flatatt(attrs)
104
105
106
|
# File 'lib/bureaucrat/utils.rb', line 104
def flatatt(attrs)
attrs.map {|k, v| " #{k}=\"#{conditional_escape(v)}\""}.join('')
end
|
108
109
110
111
112
113
114
|
# File 'lib/bureaucrat/utils.rb', line 108
def format_string(string, values)
output = string.dup
values.each_pair do |variable, value|
output.gsub!(/%\(#{variable}\)s/, value.to_s)
end
output
end
|
- (Object) make_bool(value)
125
126
127
|
# File 'lib/bureaucrat/utils.rb', line 125
def make_bool(value)
!(value.respond_to?(:empty?) ? value.empty? : [0, nil, false].include?(value))
end
|
- (Object) make_float(value)
120
121
122
123
|
# File 'lib/bureaucrat/utils.rb', line 120
def make_float(value)
value += '0' if value.is_a?(String) && value != '.' && value[-1,1] == '.'
Float(value)
end
|
- (Object) mark_safe(s)
85
86
87
|
# File 'lib/bureaucrat/utils.rb', line 85
def mark_safe(s)
s.is_a?(SafeData) ? s : SafeString.new(s.to_s)
end
|
- (Object) pretty_name(name)
116
117
118
|
# File 'lib/bureaucrat/utils.rb', line 116
def pretty_name(name)
name.to_s.capitalize.gsub(/_/, ' ')
end
|