Permalink
Browse files

Updated style

  • Loading branch information...
1 parent f5eb5ef commit 26814664c2dc38feefc402a51e915956f5b3e2c8 @ankane committed Mar 11, 2015
Showing with 57 additions and 21 deletions.
  1. +41 −0 .rubocop.yml
  2. +1 −1 Gemfile
  3. +1 −1 Rakefile
  4. +5 −5 chartkick.gemspec
  5. +3 −3 lib/chartkick.rb
  6. +3 −5 lib/chartkick/engine.rb
  7. +3 −5 lib/chartkick/helper.rb
  8. +0 −1 test/chartkick_test.rb
View
@@ -0,0 +1,41 @@
+Lint/UnusedMethodArgument:
+ Enabled: false
+
+Style/StringLiterals:
+ EnforcedStyle: double_quotes
+
+Style/SpaceInsideHashLiteralBraces:
+ EnforcedStyle: no_space
+
+Style/HashSyntax:
+ EnforcedStyle: ruby19
+
+Style/Lambda:
+ Enabled: false
+
+Style/Documentation:
+ Enabled: false
+
+Style/SignalException:
+ Enabled: false
+
+Metrics/AbcSize:
+ Enabled: false
+
+Metrics/BlockNesting:
+ Enabled: false
+
+Metrics/ClassLength:
+ Enabled: false
+
+Metrics/CyclomaticComplexity:
+ Enabled: false
+
+Metrics/LineLength:
+ Enabled: false
+
+Metrics/MethodLength:
+ Enabled: false
+
+Metrics/PerceivedComplexity:
+ Enabled: false
View
@@ -1,4 +1,4 @@
-source 'https://rubygems.org'
+source "https://rubygems.org"
# Specify your gem's dependencies in chartkick.gemspec
gemspec
View
@@ -1,7 +1,7 @@
require "bundler/gem_tasks"
require "rake/testtask"
-task :default => :test
+task default: :test
Rake::TestTask.new do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
View
@@ -1,19 +1,19 @@
# coding: utf-8
-lib = File.expand_path('../lib', __FILE__)
+lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
-require 'chartkick/version'
+require "chartkick/version"
Gem::Specification.new do |spec|
spec.name = "chartkick"
spec.version = Chartkick::VERSION
spec.authors = ["Andrew Kane"]
spec.email = ["acekane1@gmail.com"]
- spec.description = %q{Create beautiful Javascript charts with one line of Ruby}
- spec.summary = %q{Create beautiful Javascript charts with one line of Ruby}
+ spec.description = "Create beautiful Javascript charts with one line of Ruby"
+ spec.summary = "Create beautiful Javascript charts with one line of Ruby"
spec.homepage = ""
spec.license = "MIT"
- spec.files = `git ls-files`.split($/)
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
View
@@ -15,9 +15,9 @@ class << self
# use Enumerable so it can be called on arrays
module Enumerable
def chart_json
- if is_a?(Hash) and (key = keys.first) and key.is_a?(Array) and key.size == 2
- group_by{|k, v| k[0] }.map do |name, data|
- {name: name, data: data.map{|k, v| [k[1], v] }}
+ if is_a?(Hash) && (key = keys.first) && key.is_a?(Array) && key.size == 2
+ group_by { |k, _v| k[0] }.map do |name, data|
+ {name: name, data: data.map { |k, v| [k[1], v] }}
end
else
self
@@ -1,16 +1,14 @@
module Chartkick
class Engine < ::Rails::Engine
-
- initializer "precompile", :group => :all do |app|
+ initializer "precompile", group: :all do |app|
# use a proc instead of a string
- app.config.assets.precompile << Proc.new{|path| path == "chartkick.js" }
+ app.config.assets.precompile << proc { |path| path == "chartkick.js" }
end
- initializer "helper" do |app|
+ initializer "helper" do
ActiveSupport.on_load(:action_view) do
include Helper
end
end
-
end
end
@@ -3,7 +3,6 @@
module Chartkick
module Helper
-
def line_chart(data_source, options = {})
chartkick_chart "LineChart", data_source, options
end
@@ -40,9 +39,9 @@ def chartkick_chart(klass, data_source, options, &block)
element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}"
height = options.delete(:height) || "300px"
# content_for: nil must override default
- content_for = options.has_key?(:content_for) ? options.delete(:content_for) : Chartkick.content_for
+ content_for = options.key?(:content_for) ? options.delete(:content_for) : Chartkick.content_for
- html = (options.delete(:html) || %[<div id="%{id}" style="height: %{height}; text-align: center; color: #999; line-height: %{height}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">Loading...</div>]) % {id: ERB::Util.html_escape(element_id), height: ERB::Util.html_escape(height)}
+ html = (options.delete(:html) || %(<div id="%{id}" style="height: %{height}; text-align: center; color: #999; line-height: %{height}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">Loading...</div>)) % {id: ERB::Util.html_escape(element_id), height: ERB::Util.html_escape(height)}
js = <<JS
<script type="text/javascript">
@@ -61,12 +60,11 @@ def chartkick_chart(klass, data_source, options, &block)
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
def chartkick_deep_merge(hash_a, hash_b)
hash_a = hash_a.dup
- hash_b.each_pair do |k,v|
+ hash_b.each_pair do |k, v|
tv = hash_a[k]
hash_a[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
end
hash_a
end
-
end
end
@@ -26,5 +26,4 @@ def test_options_not_mutated
line_chart @data, options
assert_equal "boom", options[:id]
end
-
end

0 comments on commit 2681466

Please sign in to comment.