easy_pie_chart 0.1.1

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: b09e31c313fa7636b8854333780320a5dc705b43
4
+ data.tar.gz: faae06003607c0ce3e9cdc68dc69c78e84d0a390
5
+ SHA512:
6
+ metadata.gz: 270dd57d02a20fa246072fd1e0ee81de3bc2eb1d7fd2b4f30863db837eaddfa973d81cd7d89d4592b32ac6ff9fb5d200d8c72aa86d6a84a08d2d8f8639a7f9c6
7
+ data.tar.gz: 17207f6669f843d5dc0a34625c3ef4d3c0c40e1a40588bf851fcaeb6d0802829cc004fc84cb123eb58d882415e83058046976031d8e2cf4d58413d483f2cf892
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '>= 3.0'
4
+
5
+ group :development do
6
+ gem "rspec", ">= 2.8.0"
7
+ gem "rdoc", ">= 3.12"
8
+ gem "bundler", ">= 1.0.0"
9
+ gem "jeweler", ">= 1.8.4"
10
+ gem "simplecov",">= 0.5"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,109 @@
1
+ GEM
2
+ remote: http://rubygems.org/
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)
33
+ diff-lcs (1.1.3)
34
+ erubis (2.7.0)
35
+ git (1.2.5)
36
+ hike (1.2.1)
37
+ i18n (0.6.0)
38
+ jeweler (1.8.4)
39
+ bundler (~> 1.0)
40
+ git (>= 1.2.5)
41
+ rake
42
+ rdoc
43
+ journey (1.0.4)
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)
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)
74
+ rake (0.9.2.2)
75
+ rdoc (3.12)
76
+ json (~> 1.4)
77
+ rspec (2.11.0)
78
+ rspec-core (~> 2.11.0)
79
+ rspec-expectations (~> 2.11.0)
80
+ rspec-mocks (~> 2.11.0)
81
+ rspec-core (2.11.1)
82
+ rspec-expectations (2.11.2)
83
+ diff-lcs (~> 1.1.3)
84
+ rspec-mocks (2.11.2)
85
+ simplecov (0.6.4)
86
+ multi_json (~> 1.0)
87
+ simplecov-html (~> 0.5.3)
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)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ bundler (>= 1.0.0)
105
+ jeweler (>= 1.8.4)
106
+ rails (>= 3.0)
107
+ rdoc (>= 3.12)
108
+ rspec (>= 2.8.0)
109
+ simplecov (>= 0.5)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Kristian Mandrup
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,173 @@
1
+ Easy as pie
2
+ ==============
3
+
4
+ A little Rails wrapper for [easy-pie-chart](https://github.com/Nahrae/easy_pie_chart) which adds the assets to the asset pipeline and adds some useful Rails helpers.
5
+
6
+ Usage
7
+ -----------
8
+
9
+ In Gemfile:
10
+
11
+ `gem 'easy_pie_chart'`
12
+
13
+ Configuration
14
+ -----------
15
+
16
+ In `application.css` manifest file:
17
+
18
+ ```css
19
+ /*
20
+ * require jquery.easy-pie-chart
21
+ */
22
+ ```
23
+
24
+ Using Compass, f.ex in `application.css.scss.erb`
25
+
26
+ ```
27
+ @import 'jquery.easy-pie-chart';
28
+ ```
29
+
30
+ In `application.js` manifest file:
31
+
32
+ ```javascript
33
+ //= require jquery.easy-pie-chart
34
+ ```
35
+
36
+ Optionally include `excanvas` as well, which can be used if/when canvas is not available!
37
+
38
+ Easy pie chart
39
+ -----------
40
+
41
+ Easy pie chart is a jQuery plugin that uses the canvas element to render simple pie charts for single values.
42
+ These chars are highly customizable and very easy to implement.
43
+
44
+ ![](https://github.com/rendro/easy-pie-chart/raw/master/img/easy-pie-chart.png)
45
+
46
+ Get started
47
+ -----------
48
+
49
+ Follow Configuration instructions above and also include jQuery 1.7+.
50
+
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
+
53
+ <div class="chart" data-percent="73">73%</div>
54
+
55
+ The engine adds a view helper `easy_pie_chart(percent, label = nil)` to all Rails views ;)
56
+ Use as follows
57
+
58
+ Simple HAML example:
59
+
60
+ ```haml
61
+ = easy_pie_chart 73
62
+ ```
63
+
64
+ ERB examples:
65
+
66
+ Or with a custom label:
67
+
68
+ ```erb
69
+ <%= easy_pie_chart (6/24.0 * 100), '6 done' %>
70
+ ```
71
+
72
+ Customize `div` options, fx css `class`:
73
+
74
+ ```erb
75
+ <%= easy_pie_chart (6/24.0 * 100), '6 done', :class => 'pie-chart' %>
76
+ ```
77
+
78
+ Finally you have to initialize the plugin with your desired configuration:
79
+
80
+ ```javascript
81
+ $(document).ready(function() {
82
+ $('.chart').easyPieChart({
83
+ //your configuration goes here
84
+ });
85
+ });
86
+ ```
87
+
88
+ Configuration parameter
89
+ -----------------------
90
+
91
+ You can pass a set of these options to the initialize function to set a custom behaviour and look for the plugin.
92
+
93
+ <table>
94
+ <tr>
95
+ <th>Property (Type)</th>
96
+ <th>Default</th>
97
+ <th>Description</th>
98
+ </tr>
99
+ <tr>
100
+ <td><strong>barColor</strong></td>
101
+ <td>#ef1e25</td>
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>
103
+ </tr>
104
+ <tr>
105
+ <td><strong>trackColor</strong></td>
106
+ <td>#f2f2f2</td>
107
+ <td>The color of the track for the bar, false to disable rendering.</td>
108
+ </tr>
109
+ <tr>
110
+ <td><strong>scaleColor</strong></td>
111
+ <td>#dfe0e0</td>
112
+ <td>The color of the scale lines, false to disable rendering.</td>
113
+ </tr>
114
+ <tr>
115
+ <td><strong>lineCap</strong></td>
116
+ <td>round</td>
117
+ <td>Defines how the ending of the bar line looks like. Possible values are: <code>butt</code>, <code>round</code> and <code>square</code>.</td>
118
+ </tr>
119
+ <tr>
120
+ <td><strong>lineWidth</strong></td>
121
+ <td>3</td>
122
+ <td>Width of the bar line in px.</td>
123
+ </tr>
124
+ <tr>
125
+ <td><strong>size</strong></td>
126
+ <td>110</td>
127
+ <td>Size of the pie chart in px. It will always be a square.</td>
128
+ </tr>
129
+ <tr>
130
+ <td><strong>animate</strong></td>
131
+ <td>false</td>
132
+ <td>Time in milliseconds for a eased animation of the bar growing, or false to deactivate.</td>
133
+ </tr>
134
+ <tr>
135
+ <td><strong>onStart</strong></td>
136
+ <td>$.noop</td>
137
+ <td>Callback function that is called at the start of any animation (only if animate is not false).</td>
138
+ </tr>
139
+ <tr>
140
+ <td><strong>onStop</strong></td>
141
+ <td>$.noop</td>
142
+ <td>Callback function that is called at the end of any animation (only if animate is not false).</td>
143
+ </tr>
144
+ </table>
145
+
146
+ Public plugin methods
147
+ -----------
148
+
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.
150
+
151
+ ```javascript
152
+ $(function() {
153
+ //create instance
154
+ $('.chart').easyPieChart({
155
+ animate: 2000
156
+ });
157
+ //update instance after 5 sec
158
+ setTimeout(function() {
159
+ $('.chart').data('easyPieChart').update(40);
160
+ }, 5000);
161
+ });
162
+ ``
163
+
164
+ ## Contributing to easy_pie_chart
165
+
166
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
167
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
168
+ * Fork the project.
169
+ * Start a feature/bugfix branch.
170
+ * Commit and push until you are happy with your contribution.
171
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
172
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
173
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "easy_pie_chart"
18
+ gem.homepage = "http://github.com/kristianmandrup/easy_pie_chart"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Rails asset wrapper for jQuery easy-pie-chart}
21
+ gem.description = %Q{Makes it easy to add Pie charts to Rails 3+ apps}
22
+ gem.email = "kmandrup@gmail.com"
23
+ gem.authors = ["Kristian Mandrup"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "easy_pie_chart #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "easy_pie_chart"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nahrae Jin"]
12
+ s.date = "2015-01-02"
13
+ s.description = "Makes it easy to add Pie charts to Rails 4+ apps"
14
+ s.email = "jinnahrae@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "easy_pie_chart.gemspec",
29
+ "lib/easy_pie_chart.rb",
30
+ "lib/easy_pie_chart/engine.rb",
31
+ "lib/easy_pie_chart/view_helper.rb",
32
+ "spec/easy_pie_chart/view_helper_spec.rb",
33
+ "spec/spec_helper.rb",
34
+ "vendor/assets/javascripts/excanvas.js",
35
+ "vendor/assets/javascripts/jquery.easy-pie-chart.js",
36
+ "vendor/assets/javascripts/jquery.easy-pie-chart.js.coffee",
37
+ "vendor/assets/stylesheets/jquery.easy-pie-chart.css"
38
+ ]
39
+ s.homepage = "http://github.com/Nahrae/easy_pie_chart"
40
+ s.licenses = ["MIT"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = "1.8.24"
43
+ s.summary = "Rails asset wrapper for jQuery easy-pie-chart"
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<rails>, [">= 3.0"])
50
+ s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
51
+ s.add_development_dependency(%q<rdoc>, [">= 3.12"])
52
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, [">= 1.8.4"])
54
+ s.add_development_dependency(%q<simplecov>, [">= 0.5"])
55
+ else
56
+ s.add_dependency(%q<rails>, [">= 3.0"])
57
+ s.add_dependency(%q<rspec>, [">= 2.8.0"])
58
+ s.add_dependency(%q<rdoc>, [">= 3.12"])
59
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, [">= 1.8.4"])
61
+ s.add_dependency(%q<simplecov>, [">= 0.5"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<rails>, [">= 3.0"])
65
+ s.add_dependency(%q<rspec>, [">= 2.8.0"])
66
+ s.add_dependency(%q<rdoc>, [">= 3.12"])
67
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, [">= 1.8.4"])
69
+ s.add_dependency(%q<simplecov>, [">= 0.5"])
70
+ end
71
+ end
72
+
@@ -0,0 +1,9 @@
1
+ module EasyAsPie
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ initializer 'easy as pie config' do
5
+ ActionView::Base.send :include, EasyAsPie::ViewHelper
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module EasyAsPie
2
+ module ViewHelper
3
+
4
+ # <div class="chart" data-percent="73">73%</div>
5
+ def easy_pie_chart percent, *args
6
+ raise ArgumentError, "Must take a percent argument" unless percent
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
+
14
+ content_tag :div, label, pie_options
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ require 'easy_pie_chart/view_helper'
2
+ require 'easy_pie_chart/engine' if defined?(::Rails::Engine)
@@ -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_pie_chart percent, *args' do
9
+ context 'no arguments' do
10
+ specify do
11
+ expect { easy_pie_chart }.to raise_error(ArgumentError)
12
+ end
13
+ end
14
+
15
+ context '50%' do
16
+ specify do
17
+ easy_pie_chart(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_pie_chart(50, '50 rooms').should == "<div class=\"chart\" data-percent=\"50\">50 rooms</div>"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
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
+
11
+ require 'rspec'
12
+ require 'easy_pie_chart'
13
+
14
+ # WorldFlags::Rails::Engine.add_view_ext
15
+
16
+ SPEC_DIR = File.dirname(__FILE__)
17
+
18
+ module ControllerTestHelpers
19
+
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
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
+
46
+ end