Class: Sidebar

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
lib/sidebar.rb

Defined Under Namespace

Classes: ParamField

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Sidebar

Returns a new instance of Sidebar.



201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/sidebar.rb', line 201

def initialize(*args)
  if block_given?
    super(*args) { |instance| yield instance }
  else
    super(*args)
  end
  self.class.param_fields.each do |field|
    unless config.has_key?(field.key)
      config[field.key] = field.default
    end
  end
end

Class Method Details

.description(desc = nil) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/sidebar.rb', line 161

def description(desc = nil)
  if desc
    @description = desc
  else
    @description
  end
end

.display_name(new_dn = nil) ⇒ Object



185
186
187
188
# File 'lib/sidebar.rb', line 185

def display_name(new_dn = nil)
  @display_name = new_dn if new_dn
  @display_name || short_name.humanize
end

.fieldmapObject



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

def fieldmap
  @fieldmap ||= {}
end

.instantiate(attrs = nil, allocating = false) ⇒ Object



190
191
192
193
194
195
196
197
198
# File 'lib/sidebar.rb', line 190

def  instantiate(attrs = nil, allocating = false)
    doc = super(attrs,allocating)
    param_fields.each do |field|
      unless doc.config.has_key?(field.key)
        doc.config[field.key] = field.default
      end
    end
    doc      
end

.lifetime(timeout = nil) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/sidebar.rb', line 169

def lifetime(timeout = nil)
  if timeout
    @lifetime = timeout
  else
    @lifetime
  end
end

.param_fieldsObject



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

def param_fields
  @param_fields ||= []
end

.param_fields=(newval) ⇒ Object



157
158
159
# File 'lib/sidebar.rb', line 157

def param_fields=(newval)
  @param_fields = newval
end

.parse_sidebar(sidebar) ⇒ Object



133
134
135
# File 'lib/sidebar.rb', line 133

def parse_sidebar(sidebar)
  self.find_by :name => sidebar.to_s
end

.path_nameObject



181
182
183
# File 'lib/sidebar.rb', line 181

def path_name
  self.to_s.underscore
end

.setting(key, default = nil, options = { }) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/sidebar.rb', line 137

def setting(key, default=nil, options = { })
  return if instance_methods.include?(key.to_s)
  param_fields << ParamField.build(key.to_s, default, options)
  fieldmap.update(key.to_s => param_fields.last)
  self.send(:define_method, key) do
    self.config[key.to_s]
  end
  self.send(:define_method, "#{key}=") do |newval|
    self.config[key.to_s] = newval
  end
end

.short_nameObject



177
178
179
# File 'lib/sidebar.rb', line 177

def short_name
  self.to_s.underscore.split(%r{_}).first
end

Instance Method Details

#content_partialObject



245
246
247
# File 'lib/sidebar.rb', line 245

def content_partial
  "/#{self.class.path_name}/content"
end

#descriptionObject



233
234
235
# File 'lib/sidebar.rb', line 233

def description
  self.class.description
end

#display_nameObject



241
242
243
# File 'lib/sidebar.rb', line 241

def display_name
  self.class.display_name
end

#fieldmap(field = nil) ⇒ Object



225
226
227
228
229
230
231
# File 'lib/sidebar.rb', line 225

def fieldmap(field = nil)
  if field
    self.class.fieldmap[field.to_s]
  else
    self.class.fieldmap
  end
end

#html_idObject



214
215
216
# File 'lib/sidebar.rb', line 214

def html_id
  short_name + '-' + id.to_s
end

#lifetimeObject



255
256
257
# File 'lib/sidebar.rb', line 255

def lifetime
  self.class.lifetime
end

#param_fieldsObject



221
222
223
# File 'lib/sidebar.rb', line 221

def param_fields
  self.class.param_fields
end

#parse_request(params, contents, current_user) ⇒ Object



218
219
# File 'lib/sidebar.rb', line 218

def parse_request(params,contents,current_user)
end

#short_nameObject



237
238
239
# File 'lib/sidebar.rb', line 237

def short_name
  self.class.short_name
end

#to_locals_hashObject



249
250
251
252
253
# File 'lib/sidebar.rb', line 249

def to_locals_hash
  param_fields.inject({ :sidebar => self }) do |hash, field|
    hash.merge(field.key => config[field.key])
  end
end