bootstrap_progressbar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 292e340e27434f91a96c7aaf5ef7d1817d719908
4
+ data.tar.gz: e4d7e48b911dd3da71eb6a90ec019fe1583d4168
5
+ SHA512:
6
+ metadata.gz: 19b00b4f120da9d3244cf71e42b667b1fde2a64a7e48a6638719d264031346693f3d321da49c62552e9ebb8b435815b4a79f75cc0e0bf1842c0912d0b5768d1a
7
+ data.tar.gz: 20d571c9f27b186755305c4df0ec109ab24a496aec63f2be8f5528aea80135c3715405683938e04c192c2f3b08ed44832a5bad20f82d0d08ae46de2724a5a85c
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ rails-bootstrap-progressbar
2
+ ===========================
3
+
4
+ still under construction...
5
+
6
+ ## description
7
+
8
+ Bootstrap_progressbar will make it super easy to create beautiful-looking progress bar in rails using Bootstrap 3
9
+
10
+ ## run the test
11
+
12
+ To init environment:
13
+
14
+ $ cd test/dummy && bundle exec rake RAILS_ENV=test && cd ../../
15
+
16
+ Then you can:
17
+
18
+ $ bundle exec rake test
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env rake
2
+ # encoding: UTF-8
3
+
4
+ begin
5
+ require 'bundler/setup'
6
+ rescue LoadError
7
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ end
9
+
10
+ Bundler::GemHelper.install_tasks
11
+
12
+ require 'rake/testtask'
13
+
14
+ Rake::TestTask.new(:test) do |t|
15
+ t.libs << 'lib'
16
+ t.libs << 'test'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = false
19
+ end
20
+
21
+
22
+ task :default => :test
@@ -0,0 +1,78 @@
1
+ module BootstrapProgressbar::Helper
2
+ module Private
3
+
4
+ def self.check_percent(percent)
5
+ if percent < 0 || percent > 1
6
+ throw ArgumentError.new('the percent(first argument) should between 0 to 1')
7
+ end
8
+ end
9
+
10
+ # generate a bootstrap progress-bar with a percent and custom options
11
+ # Params:
12
+ # +percent+:: +Fixnum+ between 0 to 1.00
13
+ # +options+::
14
+ # alternative: ['success', 'danger', 'warning', 'info']
15
+ # striped: boolean
16
+ # active: boolean
17
+ # label: boolean
18
+ # class: a string contained more given class
19
+ def self.only_progress_bar(percent, options = {})
20
+ percent *= 100
21
+ percent = percent.to_i
22
+
23
+ case options[:alternative]
24
+ when 'success'
25
+ alternative = 'progress-bar-success'
26
+ when 'danger'
27
+ alternative = 'progress-bar-danger'
28
+ when 'warning'
29
+ alternative = 'progress-bar-warning'
30
+ when 'info'
31
+ alternative = 'progress-bar-info'
32
+ else
33
+ alternative = ''
34
+ end
35
+
36
+ if options[:active]
37
+ striped = "progress-bar-striped active"
38
+ elsif options[:striped]
39
+ striped = "progress-bar-striped"
40
+ else
41
+ striped = ""
42
+ end
43
+
44
+ clazz = options[:class] if options[:class]
45
+
46
+ unless options[:label]
47
+ percent_and_label = "<span class='sr-only'>#{percent}%</span>"
48
+ else
49
+ percent_and_label = "#{percent}%"
50
+ end
51
+
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
+ end
54
+
55
+ end
56
+
57
+ include Private
58
+
59
+ # generate progress and progress-bar inside
60
+ def progress_bar(percent, options = {})
61
+ Private.check_percent(percent)
62
+
63
+ if options[:class]
64
+ clazz = options[:class]
65
+ options[:class] = ""
66
+ end
67
+ progress_bar = Private.only_progress_bar(percent, options)
68
+
69
+ raw "<div class='#{[clazz, 'progress'].join(' ').strip()}'>#{progress_bar}</div>"
70
+ end
71
+
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
+ end
77
+
78
+ end
@@ -0,0 +1,3 @@
1
+ module BootstrapProgressbar
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'bootstrap_progressbar/helper'
2
+
3
+ module BootstrapProgressbar
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
9
+
10
+ ActionView::Base.send :include, BootstrapProgressbar::Helper
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ class BootstrapProgressbarTest < ActionView::TestCase
4
+ include BootstrapProgressbar::Helper
5
+
6
+ test "check percent: the percent should between 0 to 1" do
7
+ begin
8
+ progress_bar(2)
9
+ rescue ArgumentError => e
10
+ assert_equal 'uncaught throw #<ArgumentError: the percent(first argument) should between 0 to 1>', e.message
11
+ end
12
+ end
13
+
14
+ test "generate progress bar ok" do
15
+ result = progress_bar(0.5)
16
+ assert_equal "<div class='progress'><div class='progress-bar' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'><span class='sr-only'>50%</span></div></div>", result
17
+ end
18
+
19
+ test "generate progress bar with label" do
20
+ result = progress_bar(0.5, label: true)
21
+ assert_equal "<div class='progress'><div class='progress-bar' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'>50%</div></div>", result
22
+ end
23
+
24
+ test "generate progress bar with alternative: success" do
25
+ result = progress_bar(0.5, alternative: 'success')
26
+ assert_equal "<div class='progress'><div class='progress-bar progress-bar-success' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'><span class='sr-only'>50%</span></div></div>", result
27
+ end
28
+
29
+ test "generate progress bar with alternative: info" do
30
+ result = progress_bar(0.5, alternative: 'info')
31
+ assert_equal "<div class='progress'><div class='progress-bar progress-bar-info' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'><span class='sr-only'>50%</span></div></div>", result
32
+ end
33
+
34
+ test "generate progress bar with alternative: danger" do
35
+ result = progress_bar(0.5, alternative: 'danger')
36
+ assert_equal "<div class='progress'><div class='progress-bar progress-bar-danger' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'><span class='sr-only'>50%</span></div></div>", result
37
+ end
38
+
39
+ test "generate progress bar with alternative: warning" do
40
+ result = progress_bar(0.5, alternative: 'warning')
41
+ assert_equal "<div class='progress'><div class='progress-bar progress-bar-warning' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'><span class='sr-only'>50%</span></div></div>", result
42
+ end
43
+
44
+ test "support striped progress bar" do
45
+ result = progress_bar(0.5, alternative: 'success', striped: true)
46
+ assert_equal "<div class='progress'><div class='progress-bar progress-bar-success progress-bar-striped' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'><span class='sr-only'>50%</span></div></div>", result
47
+ end
48
+
49
+ test "support active, striped progress bar" do
50
+ # set active true will also set striped true
51
+ result = progress_bar(0.5, alternative: 'success', active: true)
52
+ assert_equal "<div class='progress'><div class='progress-bar progress-bar-success progress-bar-striped active' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'><span class='sr-only'>50%</span></div></div>", result
53
+ end
54
+
55
+ test "support adding extra class to progress" do
56
+ # you can add min-width css rule for class more
57
+ result = progress_bar(0.5, class: 'more')
58
+ assert_equal "<div class='more progress'><div class='progress-bar' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'><span class='sr-only'>50%</span></div></div>", result
59
+ end
60
+
61
+ # simple_progress_bar support all options for progress_bar
62
+ test "use simple_progress_bar to generate simple progress-bar" do
63
+ # so that stacked progress bars can be supported
64
+ result = simple_progress_bar(0.5)
65
+ assert_equal "<div class='progress-bar' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'><span class='sr-only'>50%</span></div>", result
66
+ end
67
+
68
+ test "support adding extra class to progress-bar" do
69
+ result = simple_progress_bar(0.5, class: 'more')
70
+ assert_equal "<div class='more progress-bar' role='progressbar' aria-valuenow='50' aria-valuemin='0' aria-valuemax='100' style='width: 50%'><span class='sr-only'>50%</span></div>", result
71
+ end
72
+
73
+ end
@@ -0,0 +1,5 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstrap_progressbar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - spacewander
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: bootstrap_progressbar makes it super easy to create beautiful-looking
42
+ progress bar in rails using Bootstrap 3
43
+ email:
44
+ - spacewanderlzx@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - Rakefile
51
+ - lib/bootstrap_progressbar.rb
52
+ - lib/bootstrap_progressbar/helper.rb
53
+ - lib/bootstrap_progressbar/version.rb
54
+ - test/bootstrap_progressbar_test.rb
55
+ - test/test_helper.rb
56
+ homepage: https://github.com/spacewander/rails-bootstrap-progressbar
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: build Bootstrap 3 progress bar quickly in rails
80
+ test_files:
81
+ - test/test_helper.rb
82
+ - test/bootstrap_progressbar_test.rb