brocade 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -0
- data/Rakefile +9 -50
- data/brocade.gemspec +21 -0
- data/install.rb +1 -1
- data/lib/brocade/has_barcode.rb +14 -5
- data/lib/brocade/version.rb +3 -0
- metadata +45 -33
- data/.document +0 -5
- data/.gitignore +0 -21
- data/VERSION +0 -1
data/README.md
CHANGED
@@ -53,6 +53,17 @@ Now you get this:
|
|
53
53
|
# deletes barcode image.
|
54
54
|
|
55
55
|
|
56
|
+
## 'Advanced' Usage
|
57
|
+
|
58
|
+
You can pass options to Brocade to control the PNG it generates. For example:
|
59
|
+
|
60
|
+
class Item < ActiveRecord::Base
|
61
|
+
has_barcode :margin => 5, :height => 40
|
62
|
+
end
|
63
|
+
|
64
|
+
These options are passed through to Barby's [PNG Outputter][pngout]. Note that setting the width makes no difference.
|
65
|
+
|
66
|
+
|
56
67
|
## Installation.
|
57
68
|
|
58
69
|
Install as a gem. In your `config.rb`:
|
@@ -101,3 +112,4 @@ Copyright (c) 2010 Andy Stewart. See LICENSE for details.
|
|
101
112
|
[barby]: http://github.com/toretore/barby
|
102
113
|
[paperclip]: http://github.com/thoughtbot/paperclip
|
103
114
|
[png]: http://seattlerb.rubyforge.org/png/
|
115
|
+
[pngout]: http://github.com/toretore/barby/blob/master/lib/barby/outputter/png_outputter.rb#L58
|
data/Rakefile
CHANGED
@@ -1,56 +1,15 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "brocade"
|
8
|
-
gem.summary = %Q{Generates barcodes for Rails ActiveRecord models.}
|
9
|
-
gem.email = "boss@airbladesoftware.com"
|
10
|
-
gem.homepage = "http://github.com/airblade/brocade"
|
11
|
-
gem.authors = ["Andy Stewart"]
|
12
|
-
gem.add_dependency 'barby'
|
13
|
-
# Use v1.1.0 of png because 1.2.0 causes problems.
|
14
|
-
# http://groups.google.com/group/ruby-barby/browse_thread/thread/03a082f9a1202106
|
15
|
-
gem.add_dependency 'png', '1.1.0'
|
16
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
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: gem install jeweler"
|
22
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
23
3
|
|
24
4
|
require 'rake/testtask'
|
25
|
-
Rake::TestTask.new(:test) do |test|
|
26
|
-
test.libs << 'lib' << 'test'
|
27
|
-
test.pattern = 'test/**/test_*.rb'
|
28
|
-
test.verbose = true
|
29
|
-
end
|
30
5
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
rescue LoadError
|
39
|
-
task :rcov do
|
40
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
41
|
-
end
|
6
|
+
desc 'Test the brocade plugin.'
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.libs << 'test'
|
10
|
+
t.pattern = 'test/**/*_test.rb'
|
11
|
+
t.verbose = true
|
42
12
|
end
|
43
13
|
|
44
|
-
|
45
|
-
|
14
|
+
desc 'Default: run unit tests.'
|
46
15
|
task :default => :test
|
47
|
-
|
48
|
-
require 'rake/rdoctask'
|
49
|
-
Rake::RDocTask.new do |rdoc|
|
50
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
51
|
-
|
52
|
-
rdoc.rdoc_dir = 'rdoc'
|
53
|
-
rdoc.title = "brocade #{version}"
|
54
|
-
rdoc.rdoc_files.include('README*')
|
55
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
-
end
|
data/brocade.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift 'lib'
|
2
|
+
require 'brocade/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'brocade'
|
6
|
+
s.version = Brocade::VERSION
|
7
|
+
s.summary = 'Generates barcodes for Rails ActiveRecord models.'
|
8
|
+
s.description = s.summary
|
9
|
+
s.homepage = 'http://github.com/airblade/brocade'
|
10
|
+
s.authors = ['Andy Stewart']
|
11
|
+
s.email = 'boss@airbladesoftware.com'
|
12
|
+
s.files = %w[ LICENSE README.md Rakefile brocade.gemspec ]
|
13
|
+
s.files += %w[ init.rb install.rb ]
|
14
|
+
s.files += Dir.glob("lib/**/*")
|
15
|
+
s.test_files = Dir.glob("test/**/*")
|
16
|
+
s.require_path = 'lib'
|
17
|
+
|
18
|
+
s.add_dependency 'barby', '0.3.2'
|
19
|
+
s.add_dependency 'png', '1.1.0' # Note problems with 1.2.0.
|
20
|
+
end
|
21
|
+
|
data/install.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
puts '
|
1
|
+
puts 'You have chosen wisely.'
|
data/lib/brocade/has_barcode.rb
CHANGED
@@ -11,7 +11,11 @@ module Brocade
|
|
11
11
|
end
|
12
12
|
|
13
13
|
module ClassMethods
|
14
|
-
def has_barcode
|
14
|
+
def has_barcode(options = {})
|
15
|
+
cattr_accessor :options
|
16
|
+
self.options = options
|
17
|
+
|
18
|
+
# Lazily load.
|
15
19
|
send :include, InstanceMethods
|
16
20
|
|
17
21
|
after_create :create_barcode
|
@@ -20,6 +24,8 @@ module Brocade
|
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
27
|
+
# Wrap the methods below in a module so we can include them
|
28
|
+
# only in the ActiveRecord models which declare `has_brocade`.
|
23
29
|
module InstanceMethods
|
24
30
|
# Returns the name of the method (as a symbol) to call to get the
|
25
31
|
# data to be barcoded.
|
@@ -33,18 +39,21 @@ module Brocade
|
|
33
39
|
:code128
|
34
40
|
end
|
35
41
|
|
36
|
-
def create_barcode
|
42
|
+
def create_barcode(opts = {})
|
37
43
|
barcode = Barby::Code128B.new send(barcodable)
|
38
44
|
path = barcode_path
|
39
45
|
FileUtils.mkdir_p File.dirname(path)
|
40
46
|
File.open(path, 'wb') do |f|
|
41
|
-
|
47
|
+
# Barby's PNG Outputter defaults to a margin of 10px and height of 100px.
|
48
|
+
# NOTE: setting the width makes no difference.
|
49
|
+
# http://github.com/toretore/barby/blob/master/lib/barby/outputter/png_outputter.rb
|
50
|
+
f.write barcode.to_png(self.class.options.merge(opts))
|
42
51
|
end
|
43
52
|
FileUtils.chmod 0644, path
|
44
53
|
end
|
45
54
|
|
46
|
-
def update_barcode
|
47
|
-
create_barcode if changed.include? barcodable
|
55
|
+
def update_barcode(opts = {})
|
56
|
+
create_barcode(opts) if changed.include? barcodable
|
48
57
|
end
|
49
58
|
|
50
59
|
def destroy_barcode
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brocade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Andy Stewart
|
@@ -9,59 +15,59 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-10-28 00:00:00 +01:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: barby
|
17
23
|
type: :runtime
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
20
27
|
requirements:
|
21
|
-
- - "
|
28
|
+
- - "="
|
22
29
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
30
|
+
hash: 23
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
- 3
|
34
|
+
- 2
|
35
|
+
version: 0.3.2
|
36
|
+
requirement: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: png
|
27
39
|
type: :runtime
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
30
43
|
requirements:
|
31
44
|
- - "="
|
32
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 19
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 1
|
50
|
+
- 0
|
33
51
|
version: 1.1.0
|
34
|
-
|
35
|
-
|
36
|
-
name: thoughtbot-shoulda
|
37
|
-
type: :development
|
38
|
-
version_requirement:
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: "0"
|
44
|
-
version:
|
45
|
-
description:
|
52
|
+
requirement: *id002
|
53
|
+
description: Generates barcodes for Rails ActiveRecord models.
|
46
54
|
email: boss@airbladesoftware.com
|
47
55
|
executables: []
|
48
56
|
|
49
57
|
extensions: []
|
50
58
|
|
51
|
-
extra_rdoc_files:
|
52
|
-
|
53
|
-
- README.md
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
54
61
|
files:
|
55
|
-
- .document
|
56
|
-
- .gitignore
|
57
62
|
- LICENSE
|
58
63
|
- README.md
|
59
64
|
- Rakefile
|
60
|
-
-
|
65
|
+
- brocade.gemspec
|
61
66
|
- init.rb
|
62
67
|
- install.rb
|
63
|
-
- lib/brocade.rb
|
64
68
|
- lib/brocade/has_barcode.rb
|
69
|
+
- lib/brocade/version.rb
|
70
|
+
- lib/brocade.rb
|
65
71
|
- test/helper.rb
|
66
72
|
- test/test_brocade.rb
|
67
73
|
has_rdoc: true
|
@@ -69,26 +75,32 @@ homepage: http://github.com/airblade/brocade
|
|
69
75
|
licenses: []
|
70
76
|
|
71
77
|
post_install_message:
|
72
|
-
rdoc_options:
|
73
|
-
|
78
|
+
rdoc_options: []
|
79
|
+
|
74
80
|
require_paths:
|
75
81
|
- lib
|
76
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
77
84
|
requirements:
|
78
85
|
- - ">="
|
79
86
|
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
80
90
|
version: "0"
|
81
|
-
version:
|
82
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
83
93
|
requirements:
|
84
94
|
- - ">="
|
85
95
|
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
86
99
|
version: "0"
|
87
|
-
version:
|
88
100
|
requirements: []
|
89
101
|
|
90
102
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.3.
|
103
|
+
rubygems_version: 1.3.7
|
92
104
|
signing_key:
|
93
105
|
specification_version: 3
|
94
106
|
summary: Generates barcodes for Rails ActiveRecord models.
|
data/.document
DELETED
data/.gitignore
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.1
|