Class: Bureaucrat::Widgets::Widget

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/bureaucrat/widgets.rb

Overview

Base class for widgets

Direct Known Subclasses

CheckboxInput, Input, Select, Textarea

Constant Summary

Constant Summary

Constants included from Utils

Utils::ESCAPES

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Utils

#blank_value?, #conditional_escape, #escape, #flatatt, #format_string, #make_bool, #make_float, #mark_safe, #pretty_name

Constructor Details

- (Widget) initialize(attrs = nil)



12
13
14
# File 'lib/bureaucrat/widgets.rb', line 12

def initialize(attrs = nil)
  @attrs = attrs.nil? ? {} : attrs.dup
end

Instance Attribute Details

- (Object) attrs (readonly)

Returns the value of attribute attrs



10
11
12
# File 'lib/bureaucrat/widgets.rb', line 10

def attrs
  @attrs
end

- (Object) is_required

Returns the value of attribute is_required



9
10
11
# File 'lib/bureaucrat/widgets.rb', line 9

def is_required
  @is_required
end

Class Method Details

+ (Object) id_for_label(id_)



35
36
37
# File 'lib/bureaucrat/widgets.rb', line 35

def self.id_for_label(id_)
  id_
end

Instance Method Details

- (Object) build_attrs(extra_attrs = nil, options = {})



25
26
27
28
29
# File 'lib/bureaucrat/widgets.rb', line 25

def build_attrs(extra_attrs = nil, options = {})
  attrs = @attrs.merge(options)
  attrs.update(extra_attrs) if extra_attrs
  attrs
end

- (Boolean) has_changed?(initial, data)



39
40
41
42
43
# File 'lib/bureaucrat/widgets.rb', line 39

def has_changed?(initial, data)
  data_value = data || ''
  initial_value = initial || ''
  initial_value != data_value
end

- (Boolean) hidden?



49
50
51
# File 'lib/bureaucrat/widgets.rb', line 49

def hidden?
  false
end

- (Object) initialize_copy(original)



16
17
18
19
# File 'lib/bureaucrat/widgets.rb', line 16

def initialize_copy(original)
  super(original)
  @attrs = original.attrs.dup
end

- (Boolean) needs_multipart?



45
46
47
# File 'lib/bureaucrat/widgets.rb', line 45

def needs_multipart?
  false
end

- (Object) render(name, value, attrs = nil)

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/bureaucrat/widgets.rb', line 21

def render(name, value, attrs = nil)
  raise NotImplementedError
end

- (Object) value_from_formdata(data, name)



31
32
33
# File 'lib/bureaucrat/widgets.rb', line 31

def value_from_formdata(data, name)
  data[name]
end