css3-progress-bar-rails 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,7 @@ module Css3ProgressBarsHelper
|
|
9
9
|
# :rounded and :tiny. Pass a string in the :color option from the available
|
10
10
|
# choices of 'green', 'orange', 'pink', 'blue', and 'purple'.
|
11
11
|
def progress_bar percentage, *opts
|
12
|
+
validate_percentage(percentage)
|
12
13
|
options = opts.extract_options!
|
13
14
|
|
14
15
|
html_classes = setup_default_container_classes
|
@@ -37,6 +38,7 @@ module Css3ProgressBarsHelper
|
|
37
38
|
#
|
38
39
|
# An options hash may also be passed to the method, with a boolean option available for :tiny
|
39
40
|
def combo_progress_bar percentages, *opts
|
41
|
+
validate_percentages(percentages[0..4])
|
40
42
|
options = opts.extract_options!
|
41
43
|
html_classes = setup_default_container_classes
|
42
44
|
|
@@ -55,6 +57,14 @@ module Css3ProgressBarsHelper
|
|
55
57
|
|
56
58
|
protected
|
57
59
|
|
60
|
+
def validate_percentage percentage
|
61
|
+
(0..100).to_a.include?(percentage.to_i) ? true : (raise ArgumentError, "Invalid Percentage Value")
|
62
|
+
end
|
63
|
+
|
64
|
+
def validate_percentages percentages
|
65
|
+
percentages.each{|p|validate_percentage(p)}
|
66
|
+
end
|
67
|
+
|
58
68
|
def setup_default_container_classes
|
59
69
|
{
|
60
70
|
:container_classes => %w(bar_container),
|
@@ -3,11 +3,44 @@ require 'nokogiri'
|
|
3
3
|
require 'action_view'
|
4
4
|
require './app/helpers/css3_progress_bars_helper'
|
5
5
|
include ActionView::Helpers
|
6
|
+
include ActionView::Context
|
6
7
|
include Css3ProgressBarsHelper
|
7
8
|
|
8
9
|
describe Css3ProgressBarsHelper do
|
10
|
+
describe '#combo_progress_bar' do
|
11
|
+
describe 'given a collection that contains an invalid percentage value' do
|
12
|
+
it 'raises and ArgumentError' do
|
13
|
+
proc {combo_progress_bar([1,2,888])}.must_raise ArgumentError
|
14
|
+
proc {combo_progress_bar([1,2,'99999',4,5])}.must_raise ArgumentError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe 'given a collection of valid percentage values' do
|
18
|
+
describe 'with the tiny option' do
|
19
|
+
it 'sets the correct tiny classes in the divs' do
|
20
|
+
doc = Nokogiri::HTML(combo_progress_bar([1,2,3,4], :tiny => true))
|
21
|
+
doc.search('div.bar_container').first.attributes["class"].value.must_match /container_tiny/
|
22
|
+
doc.search('div.bar_mortice').first.attributes["class"].value.must_match /mortice_tiny/
|
23
|
+
doc.search('div.progress').first.attributes["class"].value.must_match /progress_tiny/
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns the correct number of divs' do
|
28
|
+
Nokogiri::HTML(combo_progress_bar([1,2,3,4,5])).search('div').count.must_equal 7
|
29
|
+
Nokogiri::HTML(combo_progress_bar([1,2,3,4])).search('div').count.must_equal 6
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
9
34
|
describe '#progress_bar' do
|
10
|
-
describe 'given
|
35
|
+
describe 'given an invalid percentage value' do
|
36
|
+
it 'raises an ArgumentError' do
|
37
|
+
proc {progress_bar(101)}.must_raise ArgumentError
|
38
|
+
proc {progress_bar(-1)}.must_raise ArgumentError
|
39
|
+
proc {progress_bar('1000')}.must_raise ArgumentError
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'given a valid percentage value' do
|
11
44
|
describe 'with the color option' do
|
12
45
|
describe 'set to an invalid color' do
|
13
46
|
it 'sets no color classes in the divs' do
|
@@ -48,12 +81,12 @@ describe Css3ProgressBarsHelper do
|
|
48
81
|
|
49
82
|
describe 'with no options' do
|
50
83
|
it 'returns the correct number of divs' do
|
51
|
-
Nokogiri::HTML(progress_bar(3)).search('div').count.
|
84
|
+
Nokogiri::HTML(progress_bar(3)).search('div').count.must_equal 3
|
52
85
|
end
|
53
86
|
|
54
87
|
it 'sets the correct style in the progress div' do
|
55
|
-
Nokogiri::HTML(progress_bar(44)).search('div.progress').first.attributes["style"].value.
|
56
|
-
Nokogiri::HTML(progress_bar(88)).search('div.progress').first.attributes["style"].value.
|
88
|
+
Nokogiri::HTML(progress_bar(44)).search('div.progress').first.attributes["style"].value.must_equal "width: 44%;"
|
89
|
+
Nokogiri::HTML(progress_bar(88)).search('div.progress').first.attributes["style"].value.must_equal "width: 88%;"
|
57
90
|
end
|
58
91
|
end
|
59
92
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: css3-progress-bar-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &14890920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *14890920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: minitest
|
27
|
-
requirement: &
|
27
|
+
requirement: &14890500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *14890500
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nokogiri
|
38
|
-
requirement: &
|
38
|
+
requirement: &14889900 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *14889900
|
47
47
|
description: Integrates Josh Sullivan's CSS3 Progress Bars into Rails and adds ActionView
|
48
48
|
helpers for generation.
|
49
49
|
email:
|