Class: Clot::MultiDateTag

Inherits:
ClotTag
  • Object
show all
Defined in:
lib/clot/date_tags.rb

Instance Method Summary collapse

Methods inherited from ClotTag

#initialize

Methods included from TagHelper

#resolve_value, #split_params

Methods included from AttributeSetter

#set_attributes

Constructor Details

This class inherits a constructor from Clot::ClotTag

Instance Method Details

#personal_attributes(name, value) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/clot/date_tags.rb', line 230

def personal_attributes(name,value)
  case name
    when "discard_day" then
      @discard_day = true
    when "include_blank" then
      @include_blank = true
    when "minute_step" then
      @minute_step = "minute_step:#{value},"
    when "order" then
      @order = value
    when "start_year" then
      @start_year = "start_year:#{value},"
    when "prefix" then
      @prefix = ",prefix:'#{value}'"
    when "discard_type" then
      @discard_type = ",field_name:''"
    when "datetime_separator" then
      @datetime_separator = value
    when "date_separator" then
      @date_separator = value
    when "time_separator" then
      @time_separator = value
    when "include_seconds" then
      @include_seconds = true
    when "use_month_numbers" then
      @use_month_numbers = "use_month_numbers:true,"
    when /(.*)_prompt/ then
      value_string = value === true ? 'true' : "'#{value}'"
      instance_variable_set("@#{$1}_prompt".to_sym,",prompt:#{value_string}")
    when "prompt" then
      @prompt = ",prompt:true"
  end || super(name,value)
end

#render(context) ⇒ Object



264
265
266
267
268
269
270
271
272
273
# File 'lib/clot/date_tags.rb', line 264

def render(context)
  instance_variables.map(&:to_sym).each do |var|
    unless [:@_params, :@markup, :@tag_name].include? var
      instance_variable_set var, nil  #this is because the same parse tag is re-rendered
    end
  end
  @params = @_params.clone
  set_attributes(context)
  render_nested(context)
end

#render_units(units, context, separator = nil) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/clot/date_tags.rb', line 290

def render_units(units, context, separator = nil)
  data = ""
  not_first = false
  units.each do |unit|
     set_unit unit
     if not_first && separator
       data << separator
     end

     val = instance_variable_get("@#{unit}".to_sym)
     data << val.render(context)
     not_first = true
  end
  data
end

#set_primary_attributes(context) ⇒ Object



226
227
228
# File 'lib/clot/date_tags.rb', line 226

def set_primary_attributes(context)
  @time = resolve_value(@params.shift,context) || Time.zone.now
end

#set_unit(unit) ⇒ Object



275
276
277
278
279
280
# File 'lib/clot/date_tags.rb', line 275

def set_unit(unit)
    prompt = instance_variable_get("@#{unit}_prompt".to_sym)
    line = "#{@time.send(time_unit(unit).to_sym).to_s} #{@discard_type}#{@prefix}#{prompt || @prompt}"
    instance_variable_set "@#{unit}",
       "Clot::Select#{unit.capitalize}".constantize.new(".select_#{unit}", line,[])
end

#time_unit(unit) ⇒ Object



282
283
284
285
286
287
288
# File 'lib/clot/date_tags.rb', line 282

def time_unit(unit)
  case unit
    when "second" then "sec"
    when "minute" then "min"
    else unit
  end
end