bootstrap_progressbar 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bootstrap_progressbar/helper.rb +60 -58
- data/lib/bootstrap_progressbar/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 268dd4c0b64651b82e1d4ab971b3da0989eb09b1
|
4
|
+
data.tar.gz: b645d9464c28e131d6e119257a6c57ab9ad5d85a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66a1e3985eeddf27feb2c1849cdb847c8478058d938d8c298ac1a293892006b79ea4c5076cc5c9df886824780e16ddc5da4342f83bd7a94f655524a615ebf065
|
7
|
+
data.tar.gz: de4c17fef798764ff99774415f4a5d5283f4c0658594a3ae2947a82bb7207e5cbea85de8f46fb92b185a71d388b4f540ce0ebbb641e0219534139120c59d8562
|
@@ -1,78 +1,80 @@
|
|
1
|
-
module BootstrapProgressbar
|
2
|
-
module
|
1
|
+
module BootstrapProgressbar
|
2
|
+
module Helper
|
3
|
+
module Private
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def self.check_percent(percent)
|
6
|
+
if percent < 0 || percent > 1
|
7
|
+
throw ArgumentError.new('the percent(first argument) should between 0 to 1')
|
8
|
+
end
|
7
9
|
end
|
8
|
-
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
# generate a bootstrap progress-bar with a percent and custom options
|
12
|
+
# Params:
|
13
|
+
# +percent+:: +Fixnum+ between 0 to 1.00
|
14
|
+
# +options+::
|
15
|
+
# alternative: ['success', 'danger', 'warning', 'info']
|
16
|
+
# striped: boolean
|
17
|
+
# active: boolean
|
18
|
+
# label: boolean
|
19
|
+
# class: a string contained more given class
|
20
|
+
def self.only_progress_bar(percent, options = {})
|
21
|
+
percent *= 100
|
22
|
+
percent = percent.to_i
|
23
|
+
|
24
|
+
case options[:alternative]
|
25
|
+
when 'success'
|
26
|
+
alternative = 'progress-bar-success'
|
27
|
+
when 'danger'
|
28
|
+
alternative = 'progress-bar-danger'
|
29
|
+
when 'warning'
|
30
|
+
alternative = 'progress-bar-warning'
|
31
|
+
when 'info'
|
32
|
+
alternative = 'progress-bar-info'
|
33
|
+
else
|
34
|
+
alternative = ''
|
35
|
+
end
|
22
36
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
alternative = 'progress-bar-danger'
|
28
|
-
when 'warning'
|
29
|
-
alternative = 'progress-bar-warning'
|
30
|
-
when 'info'
|
31
|
-
alternative = 'progress-bar-info'
|
37
|
+
if options[:active]
|
38
|
+
striped = "progress-bar-striped active"
|
39
|
+
elsif options[:striped]
|
40
|
+
striped = "progress-bar-striped"
|
32
41
|
else
|
33
|
-
|
34
|
-
|
42
|
+
striped = ""
|
43
|
+
end
|
35
44
|
|
36
|
-
|
37
|
-
striped = "progress-bar-striped active"
|
38
|
-
elsif options[:striped]
|
39
|
-
striped = "progress-bar-striped"
|
40
|
-
else
|
41
|
-
striped = ""
|
42
|
-
end
|
45
|
+
clazz = options[:class] if options[:class]
|
43
46
|
|
44
|
-
|
47
|
+
unless options[:label]
|
48
|
+
percent_and_label = "<span class='sr-only'>#{percent}%</span>"
|
49
|
+
else
|
50
|
+
percent_and_label = "#{percent}%"
|
51
|
+
end
|
45
52
|
|
46
|
-
|
47
|
-
percent_and_label = "<span class='sr-only'>#{percent}%</span>"
|
48
|
-
else
|
49
|
-
percent_and_label = "#{percent}%"
|
53
|
+
"<div class='#{[clazz, 'progress-bar', alternative, striped].join(' ').strip()}' role='progressbar' aria-valuenow='#{percent}' aria-valuemin='0' aria-valuemax='100' style='width: #{percent}%'>#{percent_and_label}</div>"
|
50
54
|
end
|
51
55
|
|
52
|
-
"<div class='#{[clazz, 'progress-bar', alternative, striped].join(' ').strip()}' role='progressbar' aria-valuenow='#{percent}' aria-valuemin='0' aria-valuemax='100' style='width: #{percent}%'>#{percent_and_label}</div>"
|
53
56
|
end
|
54
57
|
|
55
|
-
|
58
|
+
include Private
|
56
59
|
|
57
|
-
|
60
|
+
# generate progress and progress-bar inside
|
61
|
+
def progress_bar(percent, options = {})
|
62
|
+
Private.check_percent(percent)
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
|
64
|
+
if options[:class]
|
65
|
+
clazz = options[:class]
|
66
|
+
options[:class] = ""
|
67
|
+
end
|
68
|
+
progress_bar = Private.only_progress_bar(percent, options)
|
62
69
|
|
63
|
-
|
64
|
-
clazz = options[:class]
|
65
|
-
options[:class] = ""
|
70
|
+
raw "<div class='#{[clazz, 'progress'].join(' ').strip()}'>#{progress_bar}</div>"
|
66
71
|
end
|
67
|
-
progress_bar = Private.only_progress_bar(percent, options)
|
68
72
|
|
69
|
-
|
70
|
-
|
73
|
+
# only generate the progress-bar
|
74
|
+
def simple_progress_bar(percent, options = {})
|
75
|
+
Private.check_percent(percent)
|
76
|
+
raw Private.only_progress_bar(percent, options)
|
77
|
+
end
|
71
78
|
|
72
|
-
# only generate the progress-bar
|
73
|
-
def simple_progress_bar(percent, options = {})
|
74
|
-
Private.check_percent(percent)
|
75
|
-
raw Private.only_progress_bar(percent, options)
|
76
79
|
end
|
77
|
-
|
78
80
|
end
|