has_barcode 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -3
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +33 -8
- data/Rakefile +9 -41
- data/has_barcode.gemspec +22 -63
- data/lib/has_barcode/configuration.rb +6 -5
- data/lib/has_barcode/version.rb +3 -0
- data/lib/has_barcode.rb +8 -1
- data/spec/spec_helper.rb +2 -8
- metadata +109 -69
- data/VERSION +0 -1
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use default@has_barcode --create
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -1,24 +1,49 @@
|
|
1
1
|
= has_barcode
|
2
2
|
|
3
|
-
|
3
|
+
{<img src="https://secure.travis-ci.org/dpickett/has_barcode.png" />}[http://travis-ci.org/dpickett/has_barcode]
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
A nice wrapper for Barcode generation using {barby}[https://github.com/toretore/barby].
|
6
|
+
|
7
|
+
class Product
|
8
|
+
include HasBarcode
|
9
|
+
|
10
|
+
has_barcode :barcode,
|
11
|
+
:outputter => :png,
|
8
12
|
:type => :code_39,
|
9
|
-
:value => Proc.new{|p| p.number}
|
13
|
+
:value => Proc.new { |p| p.number }
|
10
14
|
|
11
15
|
def number
|
12
16
|
self.id
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
16
|
-
|
17
|
-
|
20
|
+
Product.new.barcode # => Barby::Code39 object
|
21
|
+
Product.new.barcode_data # => <Barby::Code39 object>.to_png
|
22
|
+
|
23
|
+
== Why has_barcode is a good choice for Heroku
|
24
|
+
Other libraries – such as {barcode_generator}[https://github.com/anujluthra/barcode-generator] – commonly rely on {gbarcode}[https://github.com/ahx/gbarcode], a GNU Barcode C library. This is problem since you need to install GNU barcode which {Heroku does not support}[https://github.com/perezd/barcoder/issues/1]. Luckily <tt>has_barcode</tt> doesn't have this dependency.
|
25
|
+
|
26
|
+
A typical Heroku setup might look like:
|
27
|
+
|
28
|
+
class Coupon < ActiveRecord::Base
|
29
|
+
include HasBarcode
|
30
|
+
|
31
|
+
has_barcode :barcode,
|
32
|
+
:outputter => :svg,
|
33
|
+
:type => :code_39,
|
34
|
+
:value => Proc.new { |c| c.id }
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
Notice we're using the <tt>svg</tt> outputter. This is good choice since it doesn't need to store images in the file system, which can be an issue given {Heroku's read only file system}[http://devcenter.heroku.com/articles/read-only-filesystem].
|
39
|
+
|
40
|
+
To display your barcode in the view, do something like:
|
41
|
+
|
42
|
+
@coupon.barcode_data.html_safe
|
18
43
|
|
19
44
|
|
20
45
|
== Note on Patches/Pull Requests
|
21
|
-
|
46
|
+
|
22
47
|
* Fork the project.
|
23
48
|
* Make your feature addition or bug fix.
|
24
49
|
* Add tests for it. This is important so I don't break it in a
|
data/Rakefile
CHANGED
@@ -1,47 +1,15 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
3
|
|
4
4
|
begin
|
5
|
-
require '
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "has_barcode"
|
8
|
-
gem.summary = %Q{Nice class method wrapper for Barby}
|
9
|
-
gem.description = %Q{Nice class method wrapper for Barby}
|
10
|
-
gem.email = "dpickett@enlightsolutions.com"
|
11
|
-
gem.homepage = "http://github.com/dpickett/has_barcode"
|
12
|
-
gem.authors = ["Dan Pickett"]
|
13
|
-
gem.add_dependency "activesupport"
|
14
|
-
gem.add_dependency "barby"
|
15
|
-
gem.add_development_dependency "rspec"
|
16
|
-
gem.add_development_dependency "yard"
|
17
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
-
end
|
19
|
-
Jeweler::GemcutterTasks.new
|
20
|
-
rescue LoadError
|
21
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
22
|
-
end
|
23
|
-
|
24
|
-
require 'spec/rake/spectask'
|
25
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
|
-
spec.libs << 'lib' << 'spec'
|
27
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
-
end
|
29
|
-
|
30
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
-
spec.libs << 'lib' << 'spec'
|
32
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
-
spec.rcov = true
|
34
|
-
end
|
5
|
+
require 'rspec/core/rake_task'
|
35
6
|
|
36
|
-
|
7
|
+
desc "Run specs"
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
|
+
end
|
37
10
|
|
38
|
-
task :default => :spec
|
11
|
+
task :default => :spec
|
39
12
|
|
40
|
-
begin
|
41
|
-
require 'yard'
|
42
|
-
YARD::Rake::YardocTask.new
|
43
13
|
rescue LoadError
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
14
|
+
puts "RSpec is not installed"
|
15
|
+
end
|
data/has_barcode.gemspec
CHANGED
@@ -1,67 +1,26 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/has_barcode/version', __FILE__)
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Dan Pickett"]
|
6
|
+
gem.email = ["dpickett@enlightsolutions.com"]
|
7
|
+
gem.description = %q{Nice class method wrapper for Barby}
|
8
|
+
gem.summary = %q{Nice class method wrapper for Barby}
|
9
|
+
gem.homepage = ""
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
"VERSION",
|
26
|
-
"has_barcode.gemspec",
|
27
|
-
"lib/has_barcode.rb",
|
28
|
-
"lib/has_barcode/configuration.rb",
|
29
|
-
"spec/has_barcode/configuration_spec.rb",
|
30
|
-
"spec/has_barcode_spec.rb",
|
31
|
-
"spec/models/has_png_barcode.rb",
|
32
|
-
"spec/spec_helper.rb"
|
33
|
-
]
|
34
|
-
s.homepage = %q{http://github.com/dpickett/has_barcode}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
-
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.3.5}
|
38
|
-
s.summary = %q{Nice class method wrapper for Barby}
|
39
|
-
s.test_files = [
|
40
|
-
"spec/has_barcode/configuration_spec.rb",
|
41
|
-
"spec/has_barcode_spec.rb",
|
42
|
-
"spec/models/has_png_barcode.rb",
|
43
|
-
"spec/spec_helper.rb"
|
44
|
-
]
|
45
|
-
|
46
|
-
if s.respond_to? :specification_version then
|
47
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
-
s.specification_version = 3
|
49
|
-
|
50
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
52
|
-
s.add_runtime_dependency(%q<barby>, [">= 0"])
|
53
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
54
|
-
s.add_development_dependency(%q<yard>, [">= 0"])
|
55
|
-
else
|
56
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
57
|
-
s.add_dependency(%q<barby>, [">= 0"])
|
58
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
60
|
-
end
|
61
|
-
else
|
62
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
63
|
-
s.add_dependency(%q<barby>, [">= 0"])
|
64
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
65
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
66
|
-
end
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "has_barcode"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = HasBarcode::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency("activesupport", [">= 3"])
|
19
|
+
gem.add_dependency("i18n")
|
20
|
+
gem.add_dependency("barby", [">= 0"])
|
21
|
+
gem.add_dependency("rake")
|
22
|
+
|
23
|
+
gem.add_development_dependency("rspec", [">= 0"])
|
24
|
+
gem.add_development_dependency("chunky_png", [">= 0"])
|
25
|
+
gem.add_development_dependency("yard", [">= 0"])
|
67
26
|
end
|
@@ -2,16 +2,17 @@ module HasBarcode
|
|
2
2
|
class Configuration
|
3
3
|
attr_reader :name, :barcode_class, :outputter_class
|
4
4
|
def initialize(*args)
|
5
|
-
opts = args.
|
6
|
-
opts.symbolize_keys!
|
5
|
+
opts = ActiveSupport::HashWithIndifferentAccess.new(args.last.kind_of?(Hash) ? (args.last || {}) : {})
|
7
6
|
|
8
7
|
@name = args.first
|
9
|
-
|
8
|
+
|
9
|
+
require "barby/barcode/#{opts[:type]}"
|
10
|
+
@barcode_class = Barby.const_get(ActiveSupport::Inflector.classify("#{opts[:type].to_s}"))
|
10
11
|
|
11
12
|
require "barby/outputter/#{opts[:outputter]}_outputter"
|
12
|
-
@outputter = Barby.const_get("#{opts[:outputter]}_outputter"
|
13
|
+
@outputter = Barby.const_get(ActiveSupport::Inflector.classify("#{opts[:outputter]}_outputter"))
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
+
|
16
17
|
end
|
17
18
|
end
|
data/lib/has_barcode.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require "rubygems"
|
2
|
+
require "i18n"
|
2
3
|
require "active_support"
|
4
|
+
require "active_support/hash_with_indifferent_access.rb"
|
5
|
+
require "active_support/inflector.rb"
|
3
6
|
require "barby"
|
4
7
|
|
5
8
|
require "has_barcode/configuration"
|
@@ -16,7 +19,11 @@ module HasBarcode
|
|
16
19
|
@@barcode_configurations[args.first] = HasBarcode::Configuration.new(options)
|
17
20
|
|
18
21
|
define_method args.first do
|
19
|
-
|
22
|
+
if options[:type] == :code_128
|
23
|
+
@@barcode_configurations[args.first].barcode_class.new(options[:value].call(self), 'A')
|
24
|
+
else
|
25
|
+
@@barcode_configurations[args.first].barcode_class.new(options[:value].call(self))
|
26
|
+
end
|
20
27
|
end
|
21
28
|
|
22
29
|
define_method "#{args.first}_data" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
1
|
require 'has_barcode'
|
4
|
-
require 'spec'
|
5
|
-
require 'spec/autorun'
|
6
2
|
|
7
|
-
require '
|
3
|
+
require 'rspec'
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
5
|
+
require "#{File.dirname(__FILE__)}/models/has_png_barcode"
|
metadata
CHANGED
@@ -1,110 +1,150 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_barcode
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- Dan Pickett
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-01-03 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: activesupport
|
16
|
+
requirement: &2152242240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3'
|
17
22
|
type: :runtime
|
18
|
-
|
19
|
-
version_requirements:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
- !
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152242240
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: i18n
|
27
|
+
requirement: &2152240260 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2152240260
|
36
|
+
- !ruby/object:Gem::Dependency
|
26
37
|
name: barby
|
38
|
+
requirement: &2152236320 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2152236320
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &2152234440 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
type: :runtime
|
28
|
-
|
29
|
-
version_requirements:
|
30
|
-
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: "0"
|
34
|
-
version:
|
35
|
-
- !ruby/object:Gem::Dependency
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2152234440
|
58
|
+
- !ruby/object:Gem::Dependency
|
36
59
|
name: rspec
|
60
|
+
requirement: &2152233000 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2152233000
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: chunky_png
|
71
|
+
requirement: &2152231480 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
37
77
|
type: :development
|
38
|
-
|
39
|
-
version_requirements:
|
40
|
-
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: "0"
|
44
|
-
version:
|
45
|
-
- !ruby/object:Gem::Dependency
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2152231480
|
80
|
+
- !ruby/object:Gem::Dependency
|
46
81
|
name: yard
|
82
|
+
requirement: &2152208620 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
47
88
|
type: :development
|
48
|
-
|
49
|
-
version_requirements:
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: "0"
|
54
|
-
version:
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2152208620
|
55
91
|
description: Nice class method wrapper for Barby
|
56
|
-
email:
|
92
|
+
email:
|
93
|
+
- dpickett@enlightsolutions.com
|
57
94
|
executables: []
|
58
|
-
|
59
95
|
extensions: []
|
60
|
-
|
61
|
-
|
62
|
-
- LICENSE
|
63
|
-
- README.rdoc
|
64
|
-
files:
|
96
|
+
extra_rdoc_files: []
|
97
|
+
files:
|
65
98
|
- .document
|
66
99
|
- .gitignore
|
100
|
+
- .rspec
|
101
|
+
- .rvmrc
|
102
|
+
- .travis.yml
|
103
|
+
- Gemfile
|
67
104
|
- LICENSE
|
68
105
|
- README.rdoc
|
69
106
|
- Rakefile
|
70
|
-
- VERSION
|
71
107
|
- has_barcode.gemspec
|
72
108
|
- lib/has_barcode.rb
|
73
109
|
- lib/has_barcode/configuration.rb
|
110
|
+
- lib/has_barcode/version.rb
|
74
111
|
- spec/has_barcode/configuration_spec.rb
|
75
112
|
- spec/has_barcode_spec.rb
|
76
113
|
- spec/models/has_png_barcode.rb
|
77
114
|
- spec/spec_helper.rb
|
78
|
-
|
79
|
-
homepage: http://github.com/dpickett/has_barcode
|
115
|
+
homepage: ''
|
80
116
|
licenses: []
|
81
|
-
|
82
117
|
post_install_message:
|
83
|
-
rdoc_options:
|
84
|
-
|
85
|
-
require_paths:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
86
120
|
- lib
|
87
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: 3109394384331655147
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
hash: 3109394384331655147
|
99
139
|
requirements: []
|
100
|
-
|
101
140
|
rubyforge_project:
|
102
|
-
rubygems_version: 1.
|
141
|
+
rubygems_version: 1.8.6
|
103
142
|
signing_key:
|
104
143
|
specification_version: 3
|
105
144
|
summary: Nice class method wrapper for Barby
|
106
|
-
test_files:
|
145
|
+
test_files:
|
107
146
|
- spec/has_barcode/configuration_spec.rb
|
108
147
|
- spec/has_barcode_spec.rb
|
109
148
|
- spec/models/has_png_barcode.rb
|
110
149
|
- spec/spec_helper.rb
|
150
|
+
has_rdoc:
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.1
|