Sha256: a0f74c08092a941a76ee5f73327b4a09f268e4b0ca40dd9be3fcca7468b7f13f

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

module Vidibus
  module Helpers
    module Extensions
      module View

        # Renders flash message.
        # TODO: Make it more flexible!
        def render_flash
          return unless flash.any?
          level = flash.keys.last
          %(<div id="flash" class="#{level}"><div>#{flash[level]}</div></div>).html_safe
        end

        # Returns next number for tab order.
        def autotab
          @autotab ||= 0
          @autotab += 1
        end

        # 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"
        #
        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
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vidibus-helpers-0.0.5 lib/vidibus/helpers/extensions/view.rb
vidibus-helpers-0.0.4 lib/vidibus/helpers/extensions/view.rb
vidibus-helpers-0.0.3 lib/vidibus/helpers/extensions/view.rb