css3-progress-bar-rails 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,3 +7,6 @@ rvm:
7
7
  - jruby
8
8
  # - rbx-19mode # rbx-19mode dies on nokogiri dependency
9
9
  - rbx-18mode
10
+ branches:
11
+ only:
12
+ - master
@@ -3,13 +3,14 @@
3
3
  module Css3ProgressBarsHelper
4
4
 
5
5
  # Accepts a value between 0 and 100 that represents the percentage amount displayed
6
- # as filled on the progress bar's div style.
6
+ # as filled on the progress bar's div style. Numbers greater than 100 will be
7
+ # returned as 100, likewise numbers less than 0 will be returned as 0.
7
8
  #
8
9
  # An options hash may also be passed to the method, with boolean options for
9
10
  # :rounded and :tiny. Pass a string in the :color option from the available
10
11
  # choices of 'green', 'orange', 'pink', 'blue', and 'purple'.
11
12
  def progress_bar percentage, *opts
12
- validate_percentage(percentage)
13
+ percentage = scrub_percentage(percentage)
13
14
  options = opts.extract_options!
14
15
 
15
16
  html_classes = setup_default_container_classes
@@ -17,7 +18,7 @@ module Css3ProgressBarsHelper
17
18
  if options[:rounded] && options[:rounded] == true
18
19
  handle_rounded_classes(html_classes)
19
20
  end
20
-
21
+
21
22
  if options[:tiny] && options[:tiny] == true
22
23
  handle_tiny_classes(html_classes)
23
24
  end
@@ -36,12 +37,14 @@ module Css3ProgressBarsHelper
36
37
  # values. As there is a limit to the number of colors, only the first five
37
38
  # elements of the array will be used.
38
39
  #
40
+ # An error will be raised if the values passed in are greater than 100 when summed.
41
+ #
39
42
  # An options hash may also be passed to the method, with a boolean option available for :tiny
40
43
  def combo_progress_bar percentages, *opts
41
44
  validate_percentages(percentages[0..4])
42
45
  options = opts.extract_options!
43
46
  html_classes = setup_default_container_classes
44
-
47
+
45
48
  if options[:tiny] && options[:tiny] == true
46
49
  handle_tiny_classes(html_classes)
47
50
  end
@@ -56,15 +59,19 @@ module Css3ProgressBarsHelper
56
59
  end
57
60
 
58
61
  protected
59
-
60
- # Yeah, if you pass a string that non-numeric, it'll validate because 'string'.to_i returns 0.
61
- # I can live with it.
62
- def validate_percentage percentage
63
- (0..100).to_a.include?(percentage.to_i) ? true : (raise ArgumentError, "Invalid Percentage Value")
62
+ # Raising errors was kind of stupid for single progress bars, so instead
63
+ # return the percentage amount if it's betwee 0 and 100. If it's > 100,
64
+ # return 100. If it's < 0, return 0.
65
+ def scrub_percentage percentage
66
+ p = percentage.to_i
67
+ return p if (0..100).to_a.include?(p)
68
+ p > 100 ? 100 : 0
64
69
  end
65
70
 
66
71
  def validate_percentages percentages
67
- percentages.each{|p|validate_percentage(p)}
72
+ if percentages.map(&:to_i).inject(:+) > 100
73
+ raise Css3ProgressBars::ComboBarError, "Values passed to combo bar exceed 100%"
74
+ end
68
75
  end
69
76
 
70
77
  def setup_default_container_classes
@@ -109,3 +116,6 @@ module Css3ProgressBarsHelper
109
116
  content_tag :div, bar_html, :class => classes.join(' ')
110
117
  end
111
118
  end
119
+ module Css3ProgressBars
120
+ class ComboBarError < ArgumentError; end
121
+ end
@@ -5,9 +5,9 @@ require "css3-progress-bar-rails/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "css3-progress-bar-rails"
7
7
  s.version = Css3::Progress::Bar::Rails::VERSION
8
- s.authors = ["Nicholas Fine"]
9
- s.email = ["nicholas.fine@gmail.com"]
10
- s.homepage = ""
8
+ s.authors = ["Nicholas Fine", "Josh Sullivan"]
9
+ s.email = ["nicholas.fine@gmail.com", "josh@dipperstove.com"]
10
+ s.homepage = "http://ndfine.com/2012/01/03/css3-progress-bars-for-rails.html"
11
11
  s.summary = %q{Integrates Josh Sullivan's CSS3 Progress Bars into Rails 3.1+ Projects.}
12
12
  s.description = %q{Integrates Josh Sullivan's CSS3 Progress Bars into Rails and adds ActionView helpers for generation.}
13
13
 
@@ -18,8 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
21
  s.add_runtime_dependency "rails"
24
22
  s.add_development_dependency "minitest"
25
23
  s.add_development_dependency "nokogiri"
@@ -4,3 +4,5 @@ module Css3ProgressBars
4
4
  class Engine < Rails::Engine
5
5
  end
6
6
  end
7
+
8
+
@@ -2,7 +2,7 @@ module Css3
2
2
  module Progress
3
3
  module Bar
4
4
  module Rails
5
- VERSION = "0.2.2"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
8
8
  end
@@ -10,8 +10,8 @@ describe Css3ProgressBarsHelper do
10
10
  describe '#combo_progress_bar' do
11
11
  describe 'given a collection that contains an invalid percentage value' do
12
12
  it 'raises an 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
13
+ proc {combo_progress_bar([1,2,888])}.must_raise Css3ProgressBars::ComboBarError
14
+ proc {combo_progress_bar([1,2,'99999',4,5])}.must_raise Css3ProgressBars::ComboBarError
15
15
  end
16
16
  end
17
17
  describe 'given a collection of valid percentage values' do
@@ -37,13 +37,19 @@ describe Css3ProgressBarsHelper do
37
37
 
38
38
  describe '#progress_bar' do
39
39
  describe 'given an invalid percentage value' do
40
- it 'raises an ArgumentError' do
41
- proc {progress_bar(101)}.must_raise ArgumentError
42
- proc {progress_bar(-1)}.must_raise ArgumentError
43
- proc {progress_bar('1000')}.must_raise ArgumentError
40
+ describe 'greater than 100' do
41
+ it 'sets the progress div width to 100' do
42
+ Nokogiri::HTML(progress_bar(101)).search('div.progress').first.attributes["style"].value.must_equal "width: 100%;"
43
+ Nokogiri::HTML(progress_bar(10100)).search('div.progress').first.attributes["style"].value.must_equal "width: 100%;"
44
+ end
44
45
  end
45
- end
46
46
 
47
+ describe 'less than 0' do
48
+ it 'sets the progress div width to 0' do
49
+ Nokogiri::HTML(progress_bar(-203)).search('div.progress').first.attributes["style"].value.must_equal "width: 0%;"
50
+ end
51
+ end
52
+ end
47
53
  describe 'given a valid percentage value' do
48
54
  describe 'with the color option' do
49
55
  describe 'set to an invalid color' do
metadata CHANGED
@@ -1,16 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css3-progress-bar-rails
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease:
5
- version: 0.2.2
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
6
11
  platform: ruby
7
12
  authors:
8
13
  - Nicholas Fine
14
+ - Josh Sullivan
9
15
  autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2012-01-10 00:00:00 -06:00
19
+ date: 2012-01-13 00:00:00 -06:00
14
20
  default_executable:
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
@@ -21,6 +27,9 @@ dependencies:
21
27
  requirements:
22
28
  - - ">="
23
29
  - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
24
33
  version: "0"
25
34
  type: :runtime
26
35
  version_requirements: *id001
@@ -32,6 +41,9 @@ dependencies:
32
41
  requirements:
33
42
  - - ">="
34
43
  - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
35
47
  version: "0"
36
48
  type: :development
37
49
  version_requirements: *id002
@@ -43,12 +55,16 @@ dependencies:
43
55
  requirements:
44
56
  - - ">="
45
57
  - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
46
61
  version: "0"
47
62
  type: :development
48
63
  version_requirements: *id003
49
64
  description: Integrates Josh Sullivan's CSS3 Progress Bars into Rails and adds ActionView helpers for generation.
50
65
  email:
51
66
  - nicholas.fine@gmail.com
67
+ - josh@dipperstove.com
52
68
  executables: []
53
69
 
54
70
  extensions: []
@@ -68,7 +84,7 @@ files:
68
84
  - lib/css3-progress-bar-rails/version.rb
69
85
  - test/css3_progress_bars_helper_test.rb
70
86
  has_rdoc: true
71
- homepage: ""
87
+ homepage: http://ndfine.com/2012/01/03/css3-progress-bars-for-rails.html
72
88
  licenses: []
73
89
 
74
90
  post_install_message:
@@ -81,17 +97,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
97
  requirements:
82
98
  - - ">="
83
99
  - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
84
103
  version: "0"
85
104
  required_rubygems_version: !ruby/object:Gem::Requirement
86
105
  none: false
87
106
  requirements:
88
107
  - - ">="
89
108
  - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
90
112
  version: "0"
91
113
  requirements: []
92
114
 
93
115
  rubyforge_project: css3-progress-bar-rails
94
- rubygems_version: 1.6.2
116
+ rubygems_version: 1.4.2
95
117
  signing_key:
96
118
  specification_version: 3
97
119
  summary: Integrates Josh Sullivan's CSS3 Progress Bars into Rails 3.1+ Projects.