Method: Megatron::ProgressHelper#progress_bar

Defined in:
app/helpers/megatron/progress_helper.rb

#progress_bar(percentage, options = {}) ⇒ 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
# File 'app/helpers/megatron/progress_helper.rb', line 3

def progress_bar(percentage, options={})
  
  options = {
    percentage: percentage,
    label_position: 'before'
  }.merge(options)

  if options[:label] == true
    options[:label] = "#{percentage}%"
  end

  width = if options[:width]
    "width: #{options.delete(:width)};"
  else
    ''
  end

  color = options.delete(:color) || 'blue'

  (:span, class: 'progress-bar-wrapper') { 
    if options[:label] && options[:label_position].to_s == 'before'
      concat (:span, class: "progress-bar-label"){ options[:label] }
    end
    concat (:span, class: 'progress-bar', data: options, style: width) { 
      (:span, class: "progress-bar-fill #{color}-bg", style: "width: #{percentage}%"){}
    }
    if options[:label] && options[:label_position].to_s == 'after'
      concat (:span, class: "progress-bar-label"){ options[:label] }
    end
  }
end