neqa_high_charts 0.0.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: 0d1918b6870ac0cbd8a8820a7022430307287df4
4
+ data.tar.gz: 09c1e777c516afa765869f9135c14a1166c17ada
5
+ SHA512:
6
+ metadata.gz: bae1209b1c36c093e28137c94148ac1d106140d8b204cf7e398346585a9b28f7065ad3deb8fc1e920ea79776db1c29d185f528914ee3715c45dbd59f8c8f8cfa
7
+ data.tar.gz: 8437993b22e58da887c6d8f8572ca7131744cf4ae64e093d2865b61495f626235ba96c0bb72d55021163bd02d7e39d70dc9b5583054edf286695b604c5a9ece9
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in neqa_high_charts.gemspec
4
+ gemspec
5
+
6
+ group :test, :development do
7
+ gem 'rspec'
8
+ gem 'rails'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 俞其峰
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ [![Build Status](https://travis-ci.org/beyondalbert/neqa_high_charts.svg)](https://travis-ci.org/beyondalbert/neqa_high_charts)
2
+
3
+ # NeqaHighCharts
4
+
5
+ help generate high charts in rails!
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'neqa_high_charts', :git => 'git@github.com:beyondalbert/neqa_high_charts.git'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install neqa_high_charts
20
+
21
+ ## Usage
22
+
23
+ see usage demo: https://github.com/beyondalbert/rails-high-charts-demo
24
+
25
+ ## How this gem works
26
+
27
+ Deal the high charts options as the Class NeqaHighCharts::HighChart's attributes, so we can set them in your ruby code!
28
+
29
+ Then use view helper to change this attributes to html and js code!
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ require "neqa_high_charts/version"
2
+ require "neqa_high_charts/high_chart"
3
+ require "neqa_high_charts/views_helper"
4
+ if defined?(::Rails::Railtie)
5
+ require File.join(File.dirname(__FILE__), *%w[neqa_high_charts railtie])
6
+ require File.join(File.dirname(__FILE__), *%w[neqa_high_charts engine]) if ::Rails.version.to_s >= '3.1'
7
+ end
8
+
9
+ module NeqaHighCharts
10
+ end
@@ -0,0 +1,6 @@
1
+ module NeqaHighCharts
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ module NeqaHighCharts
2
+ class HighChart
3
+ attr_accessor :chart, :colors, :credits, :drilldown, :exporting, :labels, :legend, :loading, :navigation, :noData, :pane, :plotOptions, :series, :subtitle, :title, :tooltip, :xAxis, :yAxis, :scrollbar
4
+
5
+ def initialize
6
+ self.tap do |high_chart|
7
+ # high_chart.defaults_options
8
+ yield high_chart if block_given?
9
+ end
10
+ end
11
+
12
+ def defaults_options
13
+ self.title = {text: nil}
14
+ self.legend = {layout: "vertical", labels: {}}
15
+ self.xAxis = {}
16
+ self.yAxis = {title: {text: nil}, labels: {}}
17
+ self.tooltip = {enabled: true}
18
+ self.subtitle = {}
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: UTF-8
2
+ module NeqaHighCharts
3
+ class Railtie < ::Rails::Railtie
4
+ config.before_configuration do
5
+ if config.action_view.javascript_expansions
6
+ config.action_view.javascript_expansions[:high_charts] |= %w(highcharts exporting)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module NeqaHighCharts
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,84 @@
1
+ module NeqaHighCharts
2
+ module ViewsHelper
3
+ def high_chart(div_id, object, div_html_options = {})
4
+ div_html_options = {width: "100%", height: "100%"}.merge(div_html_options)
5
+ div_style = generate_div_style_from_hash div_html_options
6
+ div_el =<<-DIV
7
+ <div id="#{div_id}" style="#{div_style}"></div>
8
+ DIV
9
+ graph =<<-HCJS
10
+ <script type="text/javascript">
11
+ $(function () {
12
+ $("##{div_id}").highcharts({
13
+ #{option_generate(object)}
14
+ });
15
+ });
16
+ </script>
17
+ HCJS
18
+
19
+ div_el + graph
20
+ end
21
+
22
+ def option_generate(object)
23
+ options = ''
24
+ object.instance_variables.each do |v|
25
+ v_name = v.to_s.delete("@")
26
+ v_value = object.instance_variable_get(v)
27
+ if v_value.is_a? Hash
28
+ j_value = '{' + generate_json_from_hash(v_value) + '}'
29
+ else
30
+ j_value = '[' + generate_json_from_array(v_value) + ']'
31
+ end
32
+ option =<<-OPTION
33
+ #{v_name}: #{j_value},
34
+ OPTION
35
+ options += option
36
+ end
37
+ options
38
+ end
39
+
40
+ private
41
+
42
+ def generate_json_from_hash hash
43
+ hash.each_pair.map do |key, value|
44
+ k = key.to_s.camelize.gsub!(/\b\w/) { $&.downcase }
45
+ %|#{k}: #{generate_json_from_value value}|
46
+ end.flatten.join(',')
47
+ end
48
+
49
+ def generate_json_from_value value
50
+ if value.is_a? Hash
51
+ %|{ #{generate_json_from_hash value} }|
52
+ elsif value.is_a? Array
53
+ %|[ #{generate_json_from_array value} ]|
54
+ elsif value.is_a?(String) && (value.include?('function(') || value.include?('Highcharts.'))
55
+ value
56
+ else
57
+ value.to_json
58
+ end
59
+ end
60
+
61
+ def generate_json_from_array array
62
+ array.map { |value| generate_json_from_value(value) }.join(",")
63
+ end
64
+
65
+ def generate_div_style_from_hash hash
66
+ style_str = ""
67
+ hash.each_pair do |key, val|
68
+ if ["width", "height"].include? key.to_s
69
+ if val.is_a? Integer
70
+ style_str += "#{key}: #{val}px;"
71
+ warn "[deprecated] old high_chart function parameters set: high_chart('div-id', hc-object, width: 400, height: 400) will be deprecated, please set in new way: high_chart('div-id', hc-object, width: '400px', height: '400px')"
72
+ else
73
+ style_str += "#{key}: #{val};"
74
+ end
75
+ else
76
+ style_str += "#{key}: #{val};"
77
+ end
78
+ end
79
+ style_str
80
+ end
81
+ end
82
+ end
83
+
84
+ ActionView::Base.send :include, NeqaHighCharts::ViewsHelper
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: neqa_high_charts 0.0.1 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "neqa_high_charts"
6
+ s.version = "0.0.1"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib"]
10
+ s.authors = ["beyondalbert"]
11
+ s.date = "2014-12-03"
12
+ s.description = "easy high chart generate gem"
13
+ s.email = ["beyondalbert@gmail.com"]
14
+ s.files = [".gitignore", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "lib/neqa_high_charts.rb", "lib/neqa_high_charts/engine.rb", "lib/neqa_high_charts/high_chart.rb", "lib/neqa_high_charts/railtie.rb", "lib/neqa_high_charts/version.rb", "lib/neqa_high_charts/views_helper.rb", "neqa_high_charts.gemspec"]
15
+ s.homepage = ""
16
+ s.licenses = ["MIT"]
17
+ s.rubygems_version = "2.2.2"
18
+ s.summary = "easy high chart generate gem"
19
+
20
+ if s.respond_to? :specification_version then
21
+ s.specification_version = 4
22
+
23
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
24
+ s.add_development_dependency(%q<bundler>, ["~> 1.3"])
25
+ s.add_development_dependency(%q<rake>, [">= 0"])
26
+ else
27
+ s.add_dependency(%q<bundler>, ["~> 1.3"])
28
+ s.add_dependency(%q<rake>, [">= 0"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<bundler>, ["~> 1.3"])
32
+ s.add_dependency(%q<rake>, [">= 0"])
33
+ end
34
+ s.add_development_dependency "rspec"
35
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neqa_high_charts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - beyondalbert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: easy high chart generate gem
56
+ email:
57
+ - beyondalbert@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/neqa_high_charts.rb
68
+ - lib/neqa_high_charts/engine.rb
69
+ - lib/neqa_high_charts/high_chart.rb
70
+ - lib/neqa_high_charts/railtie.rb
71
+ - lib/neqa_high_charts/version.rb
72
+ - lib/neqa_high_charts/views_helper.rb
73
+ - neqa_high_charts.gemspec
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: easy high chart generate gem
98
+ test_files: []