Module: Vidibus::Helpers::Extensions::View

Defined in:
lib/vidibus/helpers/extensions/view.rb

Instance Method Summary collapse

Instance Method Details

#autotabObject

Returns next number for tab order.



15
16
17
18
# File 'lib/vidibus/helpers/extensions/view.rb', line 15

def autotab
  @autotab ||= 0
  @autotab += 1
end

#number_to_duration(seconds, options = {}) ⇒ Object

Formats a number or float as human duration.

Examples:

number_to_duration(24.5)                  # => "00:25"
number_to_duration(24.5, :hours => true)  # => "00:00:25"
number_to_duration(3654)                  # => "01:00:54"
number_to_duration(3654, :hours => false) # => "60:54"


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vidibus/helpers/extensions/view.rb', line 29

def number_to_duration(seconds, options = {})
  hours = options[:hours]
  seconds = seconds.to_f.round
  hour = (seconds / 3600).floor unless hours == false
  min  = (seconds / 60).floor
  sec  = (seconds % 60).round
  if hours != false and (hours == true or hour > 0)
    min -= hour * 60
    output = "%02d:" % hour
  else
    output = ''
  end
  output + "%02d:%02d" % [ min, sec ]
end

#render_flashObject

Renders flash message. TODO: Make it more flexible!



8
9
10
11
12
# File 'lib/vidibus/helpers/extensions/view.rb', line 8

def render_flash
  return unless flash.any?
  level = flash.keys.last
  %(<div id="flash" class="#{level}"><div>#{flash[level]}</div></div>).html_safe
end