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

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

#initialize(attrs = nil) ⇒ Widget

Returns a new instance of Widget.



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

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

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



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

def attrs
  @attrs
end

#is_requiredObject

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

.id_for_label(id_) ⇒ Object



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

def self.id_for_label(id_)
  id_
end

Instance Method Details

#build_attrs(extra_attrs = nil, options = {}) ⇒ Object



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

#has_changed?(initial, data) ⇒ Boolean

Returns:

  • (Boolean)


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

#hidden?Boolean

Returns:

  • (Boolean)


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

def hidden?
  false
end

#initialize_copy(original) ⇒ Object



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

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

#needs_multipart?Boolean

Returns:

  • (Boolean)


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

def needs_multipart?
  false
end

#render(name, value, attrs = nil) ⇒ Object

Raises:

  • (NotImplementedError)


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

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

#value_from_formdata(data, name) ⇒ Object



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

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