Class: Bureaucrat::Widgets::Widget

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

Direct Known Subclasses

CheckboxInput, Input, Select, Textarea

Constant Summary

Constants included from Utils

Utils::ESCAPES

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

conditional_escape, escape, flatatt, format_string, make_bool, make_float, mark_safe, pretty_name, security_hash

Constructor Details

#initialize(attrs = nil) ⇒ Widget

Returns a new instance of Widget.



116
117
118
# File 'lib/bureaucrat/widgets.rb', line 116

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

Class Attribute Details

.is_hiddenObject

Returns the value of attribute is_hidden.



102
103
104
# File 'lib/bureaucrat/widgets.rb', line 102

def is_hidden
  @is_hidden
end

.needs_multipart_formObject

Returns the value of attribute needs_multipart_form.



102
103
104
# File 'lib/bureaucrat/widgets.rb', line 102

def needs_multipart_form
  @needs_multipart_form
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



114
115
116
# File 'lib/bureaucrat/widgets.rb', line 114

def attrs
  @attrs
end

Class Method Details

.id_for_label(id_) ⇒ Object



139
140
141
# File 'lib/bureaucrat/widgets.rb', line 139

def self.id_for_label(id_)
  id_
end

.inherited(c) ⇒ Object



104
105
106
107
108
# File 'lib/bureaucrat/widgets.rb', line 104

def inherited(c)
  super(c)
  c.is_hidden = is_hidden
  c.needs_multipart_form = needs_multipart_form
end

Instance Method Details

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



129
130
131
132
133
# File 'lib/bureaucrat/widgets.rb', line 129

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)


143
144
145
146
147
# File 'lib/bureaucrat/widgets.rb', line 143

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

#hidden?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/bureaucrat/widgets.rb', line 149

def hidden?
  self.class.is_hidden
end

#initialize_copy(original) ⇒ Object



120
121
122
123
# File 'lib/bureaucrat/widgets.rb', line 120

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

#mediaObject



153
154
155
# File 'lib/bureaucrat/widgets.rb', line 153

def media
  Media.new
end

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

Raises:

  • (NotImplementedError)


125
126
127
# File 'lib/bureaucrat/widgets.rb', line 125

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

#value_from_datahash(data, files, name) ⇒ Object



135
136
137
# File 'lib/bureaucrat/widgets.rb', line 135

def value_from_datahash(data, files, name)
  data[name]
end