easy_as_pie 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +72 -0
- data/README.md +14 -5
- data/VERSION +1 -1
- data/easy_as_pie.gemspec +6 -3
- data/lib/easy_as_pie/view_helper.rb +8 -3
- data/spec/easy_as_pie/view_helper_spec.rb +27 -0
- data/spec/spec_helper.rb +40 -6
- metadata +20 -4
- data/spec/easy_as_pie_spec.rb +0 -7
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,15 +1,76 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
actionmailer (3.2.8)
|
5
|
+
actionpack (= 3.2.8)
|
6
|
+
mail (~> 2.4.4)
|
7
|
+
actionpack (3.2.8)
|
8
|
+
activemodel (= 3.2.8)
|
9
|
+
activesupport (= 3.2.8)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.4)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.2)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.3)
|
17
|
+
activemodel (3.2.8)
|
18
|
+
activesupport (= 3.2.8)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.8)
|
21
|
+
activemodel (= 3.2.8)
|
22
|
+
activesupport (= 3.2.8)
|
23
|
+
arel (~> 3.0.2)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.8)
|
26
|
+
activemodel (= 3.2.8)
|
27
|
+
activesupport (= 3.2.8)
|
28
|
+
activesupport (3.2.8)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
arel (3.0.2)
|
32
|
+
builder (3.0.0)
|
4
33
|
diff-lcs (1.1.3)
|
34
|
+
erubis (2.7.0)
|
5
35
|
git (1.2.5)
|
36
|
+
hike (1.2.1)
|
37
|
+
i18n (0.6.0)
|
6
38
|
jeweler (1.8.4)
|
7
39
|
bundler (~> 1.0)
|
8
40
|
git (>= 1.2.5)
|
9
41
|
rake
|
10
42
|
rdoc
|
43
|
+
journey (1.0.4)
|
11
44
|
json (1.7.5)
|
45
|
+
mail (2.4.4)
|
46
|
+
i18n (>= 0.4.0)
|
47
|
+
mime-types (~> 1.16)
|
48
|
+
treetop (~> 1.4.8)
|
49
|
+
mime-types (1.19)
|
12
50
|
multi_json (1.3.6)
|
51
|
+
polyglot (0.3.3)
|
52
|
+
rack (1.4.1)
|
53
|
+
rack-cache (1.2)
|
54
|
+
rack (>= 0.4)
|
55
|
+
rack-ssl (1.3.2)
|
56
|
+
rack
|
57
|
+
rack-test (0.6.1)
|
58
|
+
rack (>= 1.0)
|
59
|
+
rails (3.2.8)
|
60
|
+
actionmailer (= 3.2.8)
|
61
|
+
actionpack (= 3.2.8)
|
62
|
+
activerecord (= 3.2.8)
|
63
|
+
activeresource (= 3.2.8)
|
64
|
+
activesupport (= 3.2.8)
|
65
|
+
bundler (~> 1.0)
|
66
|
+
railties (= 3.2.8)
|
67
|
+
railties (3.2.8)
|
68
|
+
actionpack (= 3.2.8)
|
69
|
+
activesupport (= 3.2.8)
|
70
|
+
rack-ssl (~> 1.3.2)
|
71
|
+
rake (>= 0.8.7)
|
72
|
+
rdoc (~> 3.4)
|
73
|
+
thor (>= 0.14.6, < 2.0)
|
13
74
|
rake (0.9.2.2)
|
14
75
|
rdoc (3.12)
|
15
76
|
json (~> 1.4)
|
@@ -25,6 +86,16 @@ GEM
|
|
25
86
|
multi_json (~> 1.0)
|
26
87
|
simplecov-html (~> 0.5.3)
|
27
88
|
simplecov-html (0.5.3)
|
89
|
+
sprockets (2.1.3)
|
90
|
+
hike (~> 1.2)
|
91
|
+
rack (~> 1.0)
|
92
|
+
tilt (~> 1.1, != 1.3.0)
|
93
|
+
thor (0.16.0)
|
94
|
+
tilt (1.3.3)
|
95
|
+
treetop (1.4.10)
|
96
|
+
polyglot
|
97
|
+
polyglot (>= 0.3.1)
|
98
|
+
tzinfo (0.3.33)
|
28
99
|
|
29
100
|
PLATFORMS
|
30
101
|
ruby
|
@@ -32,6 +103,7 @@ PLATFORMS
|
|
32
103
|
DEPENDENCIES
|
33
104
|
bundler (>= 1.0.0)
|
34
105
|
jeweler (>= 1.8.4)
|
106
|
+
rails (>= 3.0)
|
35
107
|
rdoc (>= 3.12)
|
36
108
|
rspec (>= 2.8.0)
|
37
109
|
simplecov (>= 0.5)
|
data/README.md
CHANGED
@@ -48,23 +48,32 @@ Get started
|
|
48
48
|
|
49
49
|
Follow Configuration instructions above and also include jQuery 1.7+.
|
50
50
|
|
51
|
-
|
51
|
+
Add the pie-chart element to your site to represent chart and add the `data-percent` attribute with the percent number the pie chart should have:
|
52
52
|
|
53
53
|
<div class="chart" data-percent="73">73%</div>
|
54
54
|
|
55
55
|
The engine adds a view helper `easy_as_pie(percent, label = nil)` to all Rails views ;)
|
56
|
+
Use as follows
|
57
|
+
|
58
|
+
Simple HAML example:
|
56
59
|
|
57
60
|
```haml
|
58
61
|
= easy_as_pie 73
|
59
62
|
```
|
60
63
|
|
64
|
+
ERB examples:
|
65
|
+
|
61
66
|
Or with a custom label:
|
62
67
|
|
63
68
|
```erb
|
64
69
|
<%= easy_as_pie (6/24.0 * 100), '6 done' %>
|
65
70
|
```
|
66
71
|
|
67
|
-
|
72
|
+
Customize `div` options, fx css `class`:
|
73
|
+
|
74
|
+
```erb
|
75
|
+
<%= easy_as_pie (6/24.0 * 100), '6 done', :class => 'pie-chart' %>
|
76
|
+
```
|
68
77
|
|
69
78
|
Finally you have to initialize the plugin with your desired configuration:
|
70
79
|
|
@@ -90,7 +99,7 @@ You can pass a set of these options to the initialize function to set a custom b
|
|
90
99
|
<tr>
|
91
100
|
<td><strong>barColor</strong></td>
|
92
101
|
<td>#ef1e25</td>
|
93
|
-
<td>The color of the
|
102
|
+
<td>The color of the circular bar. You can pass either a css valid color string like rgb, rgba hex or string colors. But you can also pass a function that accepts the current percentage as a value to return a dynamically generated color.</td>
|
94
103
|
</tr>
|
95
104
|
<tr>
|
96
105
|
<td><strong>trackColor</strong></td>
|
@@ -139,7 +148,7 @@ Public plugin methods
|
|
139
148
|
|
140
149
|
If you want to update the current percentage of the a pie chart, you can call the `update method. The instance of the plugin is saved in the jQuery-data.
|
141
150
|
|
142
|
-
|
151
|
+
```javascript
|
143
152
|
$(function() {
|
144
153
|
//create instance
|
145
154
|
$('.chart').easyPieChart({
|
@@ -150,7 +159,7 @@ $(function() {
|
|
150
159
|
$('.chart').data('easyPieChart').update(40);
|
151
160
|
}, 5000);
|
152
161
|
});
|
153
|
-
|
162
|
+
``
|
154
163
|
|
155
164
|
## Contributing to easy_as_pie
|
156
165
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/easy_as_pie.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "easy_as_pie"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = "2012-08-
|
12
|
+
s.date = "2012-08-31"
|
13
13
|
s.description = "Makes it easy to add Pie charts to Rails 3+ apps"
|
14
14
|
s.email = "kmandrup@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/easy_as_pie.rb",
|
30
30
|
"lib/easy_as_pie/engine.rb",
|
31
31
|
"lib/easy_as_pie/view_helper.rb",
|
32
|
-
"spec/
|
32
|
+
"spec/easy_as_pie/view_helper_spec.rb",
|
33
33
|
"spec/spec_helper.rb",
|
34
34
|
"vendor/assets/javascripts/excanvas.js",
|
35
35
|
"vendor/assets/javascripts/jquery.easy-pie-chart.js",
|
@@ -46,12 +46,14 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.specification_version = 3
|
47
47
|
|
48
48
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.0"])
|
49
50
|
s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
|
50
51
|
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
51
52
|
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
52
53
|
s.add_development_dependency(%q<jeweler>, [">= 1.8.4"])
|
53
54
|
s.add_development_dependency(%q<simplecov>, [">= 0.5"])
|
54
55
|
else
|
56
|
+
s.add_dependency(%q<rails>, [">= 3.0"])
|
55
57
|
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
56
58
|
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
57
59
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
@@ -59,6 +61,7 @@ Gem::Specification.new do |s|
|
|
59
61
|
s.add_dependency(%q<simplecov>, [">= 0.5"])
|
60
62
|
end
|
61
63
|
else
|
64
|
+
s.add_dependency(%q<rails>, [">= 3.0"])
|
62
65
|
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
63
66
|
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
64
67
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
@@ -2,10 +2,15 @@ module EasyAsPie
|
|
2
2
|
module ViewHelper
|
3
3
|
|
4
4
|
# <div class="chart" data-percent="73">73%</div>
|
5
|
-
def easy_as_pie percent,
|
5
|
+
def easy_as_pie percent, *args
|
6
6
|
raise ArgumentError, "Must take a percent argument" unless percent
|
7
|
-
pie_options = {:"data-percent" => percent}
|
8
|
-
|
7
|
+
pie_options = {:"data-percent" => percent, :class => 'chart'}
|
8
|
+
|
9
|
+
options = args.extract_options!
|
10
|
+
pie_options.merge!(options || {})
|
11
|
+
|
12
|
+
label = args.first || "#{percent}%"
|
13
|
+
|
9
14
|
content_tag :div, label, pie_options
|
10
15
|
end
|
11
16
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EasyAsPie::ViewHelper do
|
4
|
+
include ControllerTestHelpers,
|
5
|
+
EasyAsPie::ViewHelper
|
6
|
+
|
7
|
+
# <div class="chart" data-percent="73">73%</div>
|
8
|
+
describe '.easy_as_pie percent, *args' do
|
9
|
+
context 'no arguments' do
|
10
|
+
specify do
|
11
|
+
expect { easy_as_pie }.to raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context '50%' do
|
16
|
+
specify do
|
17
|
+
easy_as_pie(50).should == "<div class=\"chart\" data-percent=\"50\">50%</div>"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "50%, 'of rooms'" do
|
22
|
+
specify do
|
23
|
+
easy_as_pie(50, '50 rooms').should == "<div class=\"chart\" data-percent=\"50\">50 rooms</div>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,46 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rails'
|
4
|
+
require 'json'
|
5
|
+
require 'active_support'
|
6
|
+
require 'action_pack'
|
7
|
+
require 'action_view'
|
8
|
+
require 'action_controller'
|
9
|
+
require 'action_view/template'
|
10
|
+
|
3
11
|
require 'rspec'
|
4
12
|
require 'easy_as_pie'
|
5
13
|
|
6
|
-
#
|
7
|
-
|
8
|
-
|
14
|
+
# WorldFlags::Rails::Engine.add_view_ext
|
15
|
+
|
16
|
+
SPEC_DIR = File.dirname(__FILE__)
|
17
|
+
|
18
|
+
module ControllerTestHelpers
|
9
19
|
|
10
|
-
|
20
|
+
def self.included(base)
|
21
|
+
base.class_eval do
|
22
|
+
|
23
|
+
include ActionView::Helpers,
|
24
|
+
ActionView::Helpers::CaptureHelper,
|
25
|
+
ActionView::Helpers::JavaScriptHelper,
|
26
|
+
ActionView::Helpers::AssetTagHelper
|
11
27
|
|
28
|
+
# allow tabs.create to run by stubbing an output_buffer
|
29
|
+
attr_accessor :output_buffer
|
30
|
+
@output_buffer = ""
|
31
|
+
|
32
|
+
# stub content_for for testing
|
33
|
+
def content_for(name, content = nil, &block)
|
34
|
+
# this doesn't exist, and causes errors
|
35
|
+
@_content_for = {} unless defined? @_content_for
|
36
|
+
# we've got to initialize this, so we can concat to it
|
37
|
+
@_content_for[name] = '' if @_content_for[name].nil?
|
38
|
+
# now the rest is the same as in rails
|
39
|
+
content = capture(&block) if block_given?
|
40
|
+
@_content_for[name] << content if content
|
41
|
+
@_content_for[name] unless content
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
12
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_as_pie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: rspec
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,7 +127,7 @@ files:
|
|
111
127
|
- lib/easy_as_pie.rb
|
112
128
|
- lib/easy_as_pie/engine.rb
|
113
129
|
- lib/easy_as_pie/view_helper.rb
|
114
|
-
- spec/
|
130
|
+
- spec/easy_as_pie/view_helper_spec.rb
|
115
131
|
- spec/spec_helper.rb
|
116
132
|
- vendor/assets/javascripts/excanvas.js
|
117
133
|
- vendor/assets/javascripts/jquery.easy-pie-chart.js
|
@@ -132,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
148
|
version: '0'
|
133
149
|
segments:
|
134
150
|
- 0
|
135
|
-
hash:
|
151
|
+
hash: -4327613926852780385
|
136
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
153
|
none: false
|
138
154
|
requirements:
|