Module: Tungsten::ProgressBarHelper

Defined in:
app/helpers/tungsten/progress_bar_helper.rb

Instance Method Summary collapse

Instance Method Details

#progress_bar(completion, options = {}, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/tungsten/progress_bar_helper.rb', line 3

def progress_bar(completion, options={}, &block)
  if completion > 1
    raise "Completion must be between 0 and 1, You passed: #{completion}"
  end

  # No need for floats
  completion = (completion*100).to_i

  options[:class] = "progress-bar #{options[:class]}".strip
  
  label = block_given? ? capture(&block) : options.delete(:label)

  description_detail = options.delete(:description_detail)
  description_status = options.delete(:description_status)

  outline_class = "progress-bar-outline #{ 'full-width' if options[:full_width] }".strip
  fill_class = "progress-bar-fill #{options.delete(:color)}".strip
  description_class = "progress-bar-description #{ 'full-width' if options[:full_width] }".strip
  
  set_aria! options, {
    role:      'progressbar',
    valuemin:  0,
    valuemax:  100,
    valuenow:  completion,
    valuetext: strip_tags(label)
  }

  ( :div, class: "progress-bar-wrapper #{ 'with-label' if label } #{ 'with-description' if description_status || description_detail }" ) {
    concat ( :div, class: 'progress-bar-label') {
      concat ( :div, class: 'progress-bar-label-content' ) { label }
    } if label
    concat ( :div, options ) {
      concat ( :div, class: outline_class ) {
        tag.div class: fill_class, style: "width: #{completion}%"
      }
      concat ( :div, class: 'progress-bar-percentage') { "#{completion}%" } if options[:description_status]
      concat ( :div, class: description_class ) { 
        concat ( :div, class: 'progress-bar-description-detail' ) { description_detail }
        concat ( :div, class: 'progress-bar-description-status' ) { description_status }
      } if description_detail || description_status
    }
  }
end