bumpspark 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/.document +2 -4
  2. data/.gitignore +16 -3
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.rvmrc +1 -0
  6. data/.travis.yml +5 -0
  7. data/Gemfile +4 -0
  8. data/{LICENSE → LICENSE.txt} +3 -1
  9. data/README.md +91 -0
  10. data/Rakefile +5 -59
  11. data/bumpspark.gemspec +21 -68
  12. data/exe/bumpspark +7 -0
  13. data/lib/bumpspark.rb +2 -8
  14. data/lib/bumpspark/formats/data_uri.rb +24 -0
  15. data/lib/bumpspark/graph.rb +7 -1
  16. data/lib/bumpspark/helper.rb +17 -0
  17. data/lib/bumpspark/railtie.rb +10 -0
  18. data/lib/bumpspark/version.rb +3 -0
  19. data/spec/dummy/Rakefile +7 -0
  20. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  21. data/spec/dummy/app/controllers/pages_controller.rb +4 -0
  22. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  23. data/spec/dummy/app/helpers/pages_helper.rb +2 -0
  24. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  25. data/spec/dummy/app/views/pages/home.html.erb +6 -0
  26. data/spec/dummy/config.ru +4 -0
  27. data/spec/dummy/config/application.rb +70 -0
  28. data/spec/dummy/config/boot.rb +6 -0
  29. data/spec/dummy/config/database.yml +25 -0
  30. data/spec/dummy/config/environment.rb +5 -0
  31. data/spec/dummy/config/environments/development.rb +37 -0
  32. data/spec/dummy/config/environments/test.rb +37 -0
  33. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  34. data/spec/dummy/config/initializers/inflections.rb +15 -0
  35. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  36. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  37. data/spec/dummy/config/initializers/session_store.rb +8 -0
  38. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  39. data/spec/dummy/config/locales/en.yml +5 -0
  40. data/spec/dummy/config/routes.rb +59 -0
  41. data/spec/dummy/log/.gitkeep +0 -0
  42. data/spec/dummy/public/404.html +26 -0
  43. data/spec/dummy/public/422.html +26 -0
  44. data/spec/dummy/public/500.html +25 -0
  45. data/spec/dummy/public/favicon.ico +0 -0
  46. data/spec/dummy/public/robots.txt +5 -0
  47. data/spec/dummy/script/rails +6 -0
  48. data/spec/helpers/application_helper_spec.rb +12 -0
  49. data/spec/lib/bumpspark/graph_spec.rb +30 -0
  50. data/spec/lib/bumpspark/helper_spec.rb +21 -0
  51. data/spec/spec_helper.rb +22 -0
  52. data/spec/support/matchers/valid_png.rb +9 -0
  53. metadata +190 -87
  54. data/README.markdown +0 -74
  55. data/VERSION +0 -1
  56. data/lib/bumpspark_helper.rb +0 -19
  57. data/rails/init.rb +0 -1
  58. data/test/bumpspark_helper_test.rb +0 -23
  59. data/test/bumpspark_test.rb +0 -32
  60. data/test/test_helper.rb +0 -10
data/.document CHANGED
@@ -1,5 +1,3 @@
1
- README.rdoc
1
+ README.md
2
2
  lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
3
+ LICENSE.txt
data/.gitignore CHANGED
@@ -1,5 +1,18 @@
1
- *.sw?
2
- .DS_Store
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
3
9
  coverage
4
- rdoc
10
+ doc/
11
+ lib/bundler/man
5
12
  pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ bin/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1 @@
1
+ 1.9.3-p362
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3-p362
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - jruby-19mode
5
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bumpspark.gemspec
4
+ gemspec
@@ -1,4 +1,6 @@
1
- Copyright (c) 2009 Bruce Williams (and collaborators at RedHanded)
1
+ Copyright (c) 2013 Bruce Williams and collaborators
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
@@ -0,0 +1,91 @@
1
+ Bumpspark
2
+ =========
3
+
4
+ [![Build Status](https://travis-ci.org/bruce/bumpspark.png)](https://travis-ci.org/bruce/bumpspark)
5
+
6
+ Generate "bumpspark"-style sparklines from Ruby & Rails. Bumpsparks
7
+ are sparklines which show discrete data points and highlight extremes.
8
+
9
+ Note: This library is based on _why's `bumpspark' code,
10
+ originally discussed and collaborated on at
11
+ [RedHanded](http://redhanded.hobix.com/inspect/sparklinesForMinimalists.html).
12
+
13
+ It has been refactored and built out as a gem suitable for inclusion
14
+ in Rails projects (and standalone Ruby code).
15
+
16
+ Credits
17
+ -------
18
+
19
+ Thanks to the original collaborators:
20
+
21
+ * _why (concept, BMP implementation)
22
+ * jzp (png)
23
+ * MenTaLguY (transparency)
24
+
25
+ Installation
26
+ ------------
27
+
28
+ ```
29
+ gem install bumpspark
30
+ ```
31
+
32
+ Usage
33
+ -----
34
+
35
+ ### From Rails
36
+
37
+ Add `bumpspark` as a dependency:
38
+
39
+ ```ruby
40
+ gem 'bumpspark'
41
+ ```
42
+
43
+ Use `bumpspark_tag` from your views or helpers, passing it the data
44
+ points you'd like graphed.
45
+
46
+ ```erb
47
+ <%= bumpspark_tag [12, 34, 12, 42, 12, 23] %>
48
+ ```
49
+
50
+ ### From Ruby
51
+
52
+ Simply create a `Bumpspark::Graph` instance and call `to_png` on it.
53
+
54
+ ```ruby
55
+ require 'bumpspark'
56
+
57
+ graph = Bumpspark::Graph.new [12, 34, 12, 42, 12, 23]
58
+
59
+ File.open('bumpspark.png', 'wb') do |file|
60
+ file.write graph.to_png
61
+ end
62
+ ```
63
+
64
+ ### From the commandline
65
+
66
+ Generate a bumpspark directly from the commandline.
67
+
68
+ ```
69
+ % cat temperature.txt
70
+ 23 25 33 22 25 33 22
71
+
72
+ % cat temperature.txt | bumpspark > temperature.png
73
+ ```
74
+
75
+ ### Note on Patches/Pull Requests
76
+
77
+ Please check the TODO file for information on things that need doing.
78
+
79
+ * Fork the project.
80
+ * Make your feature addition or bug fix.
81
+ * Add tests for it. This is important so I don't break it in a
82
+ future version unintentionally.
83
+ * Commit, do not mess with rakefile, version, or history.
84
+ (if you want to have your own version, that is fine but
85
+ bump version in a commit by itself I can ignore when I pull)
86
+ * Send me a pull request. Bonus points for topic branches.
87
+
88
+ ### Copyright
89
+
90
+ Copyright (c) 2009-2012 Bruce Williams, et al. See LICENSE for
91
+ details.
data/Rakefile CHANGED
@@ -1,62 +1,8 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require "bundler/gem_tasks"
3
2
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "bumpspark"
8
- gem.summary = %Q{Generates "bumpspark"-style sparklines for Ruby & Rails}
9
- gem.description = %Q{Generates transparent PNG "bumpspark"-style sparklines. Use from Ruby directly or as a Rails helper generating an image tag w/ built-in data, as conceived by whytheluckystiff.}
10
- gem.email = "bruce@codefluency.com"
11
- gem.homepage = "http://github.com/bruce/bumpspark"
12
- gem.authors = ["Bruce Williams"]
13
- gem.rubyforge_project = 'codefluency'
14
- # TESTING ONLY
15
- gem.add_development_dependency "thoughtbot-shoulda"
16
- gem.add_development_dependency "activesupport"
17
- gem.add_development_dependency "actionpack"
18
- gem.add_development_dependency "rmagick"
19
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
- end
21
- Jeweler::GemcutterTasks.new
22
- rescue LoadError
23
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.pattern = 'spec/{helpers,lib}/**/*_spec.rb'
24
6
  end
25
7
 
26
- require 'rake/testtask'
27
- Rake::TestTask.new(:test) do |test|
28
- test.libs << 'lib' << 'test'
29
- test.pattern = 'test/**/*_test.rb'
30
- test.verbose = true
31
- end
32
-
33
- begin
34
- require 'rcov/rcovtask'
35
- Rcov::RcovTask.new do |test|
36
- test.libs << 'test'
37
- test.pattern = 'test/**/*_test.rb'
38
- test.verbose = true
39
- end
40
- rescue LoadError
41
- task :rcov do
42
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
43
- end
44
- end
45
-
46
- task :test => :check_dependencies
47
-
48
- task :default => :test
49
-
50
- require 'rake/rdoctask'
51
- Rake::RDocTask.new do |rdoc|
52
- if File.exist?('VERSION')
53
- version = File.read('VERSION')
54
- else
55
- version = ""
56
- end
57
-
58
- rdoc.rdoc_dir = 'rdoc'
59
- rdoc.title = "bumpspark #{version}"
60
- rdoc.rdoc_files.include('README*')
61
- rdoc.rdoc_files.include('lib/**/*.rb')
62
- end
8
+ task :default => :spec
@@ -1,73 +1,26 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bumpspark/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{bumpspark}
8
- s.version = "1.1.1"
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "bumpspark"
8
+ gem.version = Bumpspark::VERSION
9
+ gem.authors = ["Bruce Williams"]
10
+ gem.email = ["brwcodes@gmail.com"]
11
+ gem.description = %q{Generates transparent PNG and Data URI bumpspark-style sparklines. Use from Ruby directly or as a Rails helper.}
12
+ gem.summary = %q{Generates bumpspark-style sparklines for Ruby & Rails}
13
+ gem.homepage = "http://github.com/bruce/bumpspark"
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Bruce Williams"]
12
- s.date = %q{2009-10-22}
13
- s.description = %q{Generates transparent PNG "bumpspark"-style sparklines. Use from Ruby directly or as a Rails helper generating an image tag w/ built-in data, as conceived by whytheluckystiff.}
14
- s.email = %q{bruce@codefluency.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.markdown"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.markdown",
24
- "Rakefile",
25
- "TODO.markdown",
26
- "VERSION",
27
- "bumpspark.gemspec",
28
- "lib/bumpspark.rb",
29
- "lib/bumpspark/formats/png.rb",
30
- "lib/bumpspark/formats/string.rb",
31
- "lib/bumpspark/graph.rb",
32
- "lib/bumpspark/scale.rb",
33
- "lib/bumpspark_helper.rb",
34
- "rails/init.rb",
35
- "test/bumpspark_helper_test.rb",
36
- "test/bumpspark_test.rb",
37
- "test/test_helper.rb"
38
- ]
39
- s.homepage = %q{http://github.com/bruce/bumpspark}
40
- s.rdoc_options = ["--charset=UTF-8"]
41
- s.require_paths = ["lib"]
42
- s.rubyforge_project = %q{codefluency}
43
- s.rubygems_version = %q{1.3.5}
44
- s.summary = %q{Generates "bumpspark"-style sparklines for Ruby & Rails}
45
- s.test_files = [
46
- "test/bumpspark_helper_test.rb",
47
- "test/bumpspark_test.rb",
48
- "test/test_helper.rb"
49
- ]
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.bindir = 'exe'
17
+ gem.executables = gem.files.grep(%r{^exe/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
50
20
 
51
- if s.respond_to? :specification_version then
52
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
- s.specification_version = 3
54
-
55
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
- s.add_development_dependency(%q<activesupport>, [">= 0"])
58
- s.add_development_dependency(%q<actionpack>, [">= 0"])
59
- s.add_development_dependency(%q<rmagick>, [">= 0"])
60
- else
61
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
62
- s.add_dependency(%q<activesupport>, [">= 0"])
63
- s.add_dependency(%q<actionpack>, [">= 0"])
64
- s.add_dependency(%q<rmagick>, [">= 0"])
65
- end
66
- else
67
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
68
- s.add_dependency(%q<activesupport>, [">= 0"])
69
- s.add_dependency(%q<actionpack>, [">= 0"])
70
- s.add_dependency(%q<rmagick>, [">= 0"])
71
- end
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'rspec-rails'
23
+ gem.add_development_dependency 'chunky_png'
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'rails', '3.2.11'
72
26
  end
73
-
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
4
+ require 'bumpspark'
5
+
6
+ data = ARGF.read.strip.split(/\D+/).map(&:to_i)
7
+ print Bumpspark::Graph.new(data).to_png
@@ -1,8 +1,2 @@
1
- require File.dirname(__FILE__) << "/bumpspark/formats/png"
2
- require File.dirname(__FILE__) << "/bumpspark/formats/string"
3
- require File.dirname(__FILE__) << "/bumpspark/scale"
4
- require File.dirname(__FILE__) << "/bumpspark/graph"
5
-
6
- module Bumpspark
7
- VERSION = File.read(File.dirname(__FILE__) << "/../VERSION").strip
8
- end
1
+ require "bumpspark/graph"
2
+ require "bumpspark/railtie" if defined?(Rails)
@@ -0,0 +1,24 @@
1
+ require "base64"
2
+ require "cgi"
3
+
4
+ module Bumpspark
5
+
6
+ module Formats
7
+
8
+ module DataURI
9
+
10
+ # Generate a Data URI
11
+ # @see http://en.wikipedia.org/wiki/Data_URI_scheme
12
+ #
13
+ # @return [String]
14
+ #
15
+ def to_data_uri
16
+ data = Base64.encode64(to_png).delete("\n")
17
+ "data:image/png;base64,#{CGI.escape(data)}"
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -1,3 +1,8 @@
1
+ require "bumpspark/scale"
2
+ require "bumpspark/formats/png"
3
+ require "bumpspark/formats/string"
4
+ require "bumpspark/formats/data_uri"
5
+
1
6
  module Bumpspark
2
7
 
3
8
  class Graph
@@ -5,6 +10,7 @@ module Bumpspark
5
10
  include Scale
6
11
  include Formats::PNG
7
12
  include Formats::String
13
+ include Formats::DataURI
8
14
 
9
15
  attr_reader :numbers, :scale
10
16
  def initialize(numbers, scale = 1)
@@ -14,4 +20,4 @@ module Bumpspark
14
20
 
15
21
  end
16
22
 
17
- end
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'base64'
2
+ require 'cgi'
3
+
4
+ module Bumpspark
5
+ module Helper
6
+
7
+ # Generate a bumpspark-style sparkline image tag
8
+ #
9
+ # @return [String]
10
+ #
11
+ def bumpspark_tag(numbers, html_opts={})
12
+ graph = Bumpspark::Graph.new(numbers)
13
+ tag(:img, html_opts.merge(src: graph.to_data_uri))
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module Bumpspark
2
+
3
+ class Railtie < Rails::Railtie
4
+ initializer "bumpspark.helper" do |app|
5
+ require "bumpspark/helper"
6
+ ActionView::Base.send(:include, Bumpspark::Helper)
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,3 @@
1
+ module Bumpspark
2
+ VERSION = "2.0.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,4 @@
1
+ class PagesController < ApplicationController
2
+ def home
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PagesHelper
2
+ end