lablr 0.0.1

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.
Binary file
@@ -0,0 +1,9 @@
1
+ README.textile
2
+ Rakefile
3
+ assets/layouts/label.html.erb
4
+ assets/templates/_avery_5163.erb
5
+ init.rb
6
+ lablr-0.0.1.gemspec
7
+ lib/lablr.rb
8
+ test.rb
9
+ Manifest
@@ -0,0 +1,37 @@
1
+ h1. Lablr
2
+
3
+ Lablr is a Ruby Gem for generating printable labels in a variety of formats(pdf, html, etc.) and templates.
4
+
5
+ h2. Supported Label Templates
6
+
7
+ The following templates are supported by Lablr:
8
+
9
+ * Avery 5163/5963
10
+
11
+ h2. Requirements
12
+
13
+ Lablr uses HTMLDOC and the htmldoc gem to generate pdf files. You need to install HTMLDOC like so:
14
+
15
+ <pre>
16
+ sudo apt-get install
17
+ </pre>
18
+
19
+ Then install the htmldoc gem:
20
+ <pre>
21
+ sudo gem install htmldoc
22
+ </pre>
23
+
24
+ h2. Installation
25
+ <pre>
26
+ gem install Lablr
27
+ </pre>
28
+
29
+ h2. Usage
30
+
31
+ <pre>
32
+ # Generate PDF Label Sheet
33
+ Lablr.generate_labels(:template => :avery_5163, :format => :pdf, :content => "Test Label!")
34
+
35
+ # Generate PDF and write to file
36
+ Lablr.generate_labels(:template => :avery_5163, :format => :pdf, :content => "Test Label!", :to_file => "x.pdf")
37
+
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('lablr', '0.0.1') do |p|
6
+ p.description = "A Ruby Gem for generating printable labels in a variety of formats(pdf, html, etc.) and templates."
7
+ p.url = "https://github.com/hulihanapplications/Lablr"
8
+ p.author = "Hulihan Applications"
9
+ p.email = "dave@hulihanapplications.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.runtime_dependencies = ["htmldoc >=0.2.3"]
12
+ end
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+
4
+ </head>
5
+ <body>
6
+ <%= yield %>
7
+ </body>
8
+ </html>
@@ -0,0 +1,41 @@
1
+ <%
2
+ options ||= Hash.new
3
+ options[:cell_width] ||= 320
4
+ options[:cell_height] ||= 172
5
+ options[:spacer_center_width] ||= 15
6
+ options[:title_1] ||= ""
7
+ options[:title_2] ||= ""
8
+ options[:title_3] ||= ""
9
+ options[:notes_1] ||= ""
10
+ options[:notes_2] ||= ""
11
+ options[:notes_3] ||= ""
12
+ options[:img] ||= ""
13
+ %>
14
+ <div class="sheet">
15
+ <table <%= self.style[:border] ? "border=1" : "border=0" %> align=center>
16
+ <% for i in (0..4) %>
17
+ <tr>
18
+ <!--
19
+ <td width=9>
20
+ &nbsp;
21
+ </td>
22
+ -->
23
+ <td <%= "width=#{options[:cell_width]} height=#{options[:cell_height]}" %> valign=top>
24
+ <%#= "#{options[:cell_width]}x#{options[:cell_height]}" %>
25
+ <%= self.content %>
26
+ </td>
27
+ <td <%= "width=#{options[:spacer_center_width]}" %>>
28
+ &nbsp;
29
+ </td>
30
+ <td <%= "width=#{options[:cell_width]} height=#{options[:cell_height]}" %> valign=top>
31
+ <%= self.content %>
32
+ </td>
33
+ <!--
34
+ <td width=9>
35
+ &nbsp;
36
+ </td>
37
+ -->
38
+ </tr>
39
+ <% end %>
40
+ </table>
41
+ </div>
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "lablr.rb"
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{lablr}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Hulihan Applications"]
9
+ s.cert_chain = ["/aqpwr/.ssl/gem/gem-public_cert.pem"]
10
+ s.date = %q{2010-11-22}
11
+ s.description = %q{A Ruby Gem for generating printable labels in a variety of formats(pdf, html, etc.) and templates.}
12
+ s.email = %q{dave@hulihanapplications.com}
13
+ s.extra_rdoc_files = ["README.textile", "lib/lablr.rb"]
14
+ s.files = ["README.textile", "Rakefile", "assets/layouts/label.html.erb", "assets/templates/_avery_5163.erb", "init.rb", "lablr-0.0.1.gemspec", "lib/lablr.rb", "test.rb", "Manifest", "lablr.gemspec"]
15
+ s.homepage = %q{https://github.com/hulihanapplications/Lablr}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Lablr", "--main", "README.textile"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{lablr}
19
+ s.rubygems_version = %q{1.3.7}
20
+ s.signing_key = %q{/aqpwr/.ssl/gem/gem-private_key.pem}
21
+ s.summary = %q{A Ruby Gem for generating printable labels in a variety of formats(pdf, html, etc.) and templates.}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<htmldoc>, [">= 0.2.3"])
29
+ else
30
+ s.add_dependency(%q<htmldoc>, [">= 0.2.3"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<htmldoc>, [">= 0.2.3"])
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{lablr}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Hulihan Applications"]
9
+ s.cert_chain = ["/aqpwr/.ssl/gem/gem-public_cert.pem"]
10
+ s.date = %q{2010-11-22}
11
+ s.description = %q{A Ruby Gem for generating printable labels in a variety of formats(pdf, html, etc.) and templates.}
12
+ s.email = %q{dave@hulihanapplications.com}
13
+ s.extra_rdoc_files = ["README.textile", "lib/lablr.rb"]
14
+ s.files = ["README.textile", "Rakefile", "assets/layouts/label.html.erb", "assets/templates/_avery_5163.erb", "init.rb", "lablr-0.0.1.gemspec", "lib/lablr.rb", "test.rb", "Manifest", "lablr.gemspec"]
15
+ s.homepage = %q{https://github.com/hulihanapplications/Lablr}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Lablr", "--main", "README.textile"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{lablr}
19
+ s.rubygems_version = %q{1.3.7}
20
+ s.signing_key = %q{/aqpwr/.ssl/gem/gem-private_key.pem}
21
+ s.summary = %q{A Ruby Gem for generating printable labels in a variety of formats(pdf, html, etc.) and templates.}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<htmldoc>, [">= 0.2.3"])
29
+ else
30
+ s.add_dependency(%q<htmldoc>, [">= 0.2.3"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<htmldoc>, [">= 0.2.3"])
34
+ end
35
+ end
@@ -0,0 +1,93 @@
1
+ require "htmldoc"
2
+ require "erb"
3
+
4
+ module Lablr
5
+ def self.GEM_ROOT
6
+ return File.join(File.dirname(File.join(__FILE__)), "..")
7
+ end
8
+
9
+ class Template # templates define label layout(with erb) and rendering
10
+ attr_accessor :erb, :name, :content, :style
11
+ #@erb_template = nil
12
+ #@name = nil
13
+
14
+ def initialize(options = {})
15
+ @erb = options[:erb] ||= nil
16
+ @name = options[:name] ||= nil
17
+ @content = options[:content] ||= "No Content Set"
18
+ @style = options[:style] ||= TemplateStyle.new
19
+ @erb = ERB.new(File.read(File.join(Lablr.GEM_ROOT, "assets", "templates", "_" + @name.to_s + ".erb")))
20
+ end
21
+
22
+ def getBinding # make binding accessible to pass into erb
23
+ return binding()
24
+ end
25
+
26
+ # You can Render this template by
27
+ end
28
+
29
+ class TemplateStyle # visual styles for Templates
30
+ attr_accessor :options
31
+
32
+ def initialize(options = {})
33
+ # Set defaults
34
+ options[:borders] = true if options[:borders].nil? # border around labels
35
+
36
+ @options = options
37
+ end
38
+ end
39
+
40
+ def self.generate_labels(options = {})
41
+ options[:format] ||= :pdf
42
+ options[:template] ||= :avery_5163
43
+ options[:content] ||= "No Content Set"
44
+ options[:style] ||= TemplateStyle.new
45
+ options[:to_file] ||= nil # to a specific file
46
+
47
+ template = Lablr::Template.new(:name => options[:template].to_s, :content => options[:content], :style => options[:style])
48
+ rendered_template = template.erb.result(template.getBinding) # render erb template
49
+ #puts data
50
+ if options[:format] == :pdf
51
+ data = Lablr.render_to_pdf(rendered_template)
52
+ elsif options[:format] == :html
53
+ data = rendered_template
54
+ end
55
+ #puts rendered_template
56
+ if options[:to_file] # write to file
57
+ file = File.basename(options[:to_file], "." + options[:format].to_s) + "." + options[:format].to_s
58
+ File.open(file, "w"){|f| f.write(data)}
59
+ return "Labels written to #{File.basename(file)}"
60
+ else # return data
61
+ return data
62
+ end
63
+ end
64
+
65
+
66
+
67
+ def self.render_to_pdf(html) # create a pdf
68
+ #data = render_to_string(options)
69
+ pdf = PDF::HTMLDoc.new
70
+ pdf.set_option :bodycolor, :white
71
+ pdf.set_option :toc, false
72
+ pdf.set_option :portrait, true
73
+ pdf.set_option :links, false
74
+ pdf.set_option :webpage, true
75
+ pdf.set_option :top, '0cm'
76
+ pdf.set_option :left, '0cm'
77
+ pdf.set_option :right, '0cm'
78
+ pdf.set_option :bottom, '0cm'
79
+ pdf.footer ".1."
80
+ pdf << html
81
+ pdf.generate
82
+ end
83
+
84
+ module VERSION #:nodoc:
85
+ MAJOR = 0
86
+ MINOR = 0
87
+ TINY = 1
88
+
89
+ STRING = [MAJOR, MINOR, TINY].join(".")
90
+ end
91
+
92
+
93
+ end
data/test.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "rubygems"
2
+ require "lablr"
3
+
4
+ #puts Lablr.GEM_ROOT
5
+ # template = Lablr::Template.new(:name => "avery_5163", :content => "Testing...")
6
+ #puts template.erb.result(template.getBinding)
7
+
8
+ #puts Lablr.generate_labels(:template => :avery_5163, :format => :pdf, :content => "Test Label!")
9
+ puts Lablr.generate_labels(:template => :avery_5163, :format => :pdf, :content => "Test Label!", :to_file => "x.pdf", :style => {:border => false})
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lablr
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Hulihan Applications
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain:
17
+ - |
18
+ -----BEGIN CERTIFICATE-----
19
+ MIIDRjCCAi6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBJMQ0wCwYDVQQDDARkYXZl
20
+ MSMwIQYKCZImiZPyLGQBGRYTaHVsaWhhbmFwcGxpY2F0aW9uczETMBEGCgmSJomT
21
+ 8ixkARkWA2NvbTAeFw0xMDExMjIyMTUxMzNaFw0xMTExMjIyMTUxMzNaMEkxDTAL
22
+ BgNVBAMMBGRhdmUxIzAhBgoJkiaJk/IsZAEZFhNodWxpaGFuYXBwbGljYXRpb25z
23
+ MRMwEQYKCZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
24
+ CgKCAQEAxNMbIxxvKYHyRV6qUmCMQQqY8+b4bFJ3k941sTxeDv0hNnfABz73wrHV
25
+ q1v0iUaNN7EgniQhH2hA0xmEIcHWWeJJ0eomYJbcWdR1Vmx3qr8OZf4bRhtcINOY
26
+ S/wBQ32vwwDnwpqbNT5SejwEzO5GhLThMwtEF8CkTCCNPIxa5JekTY5zLjUjGXHk
27
+ Wkxe2sHYoME2vGF2GBsMZcA0DdaNR5YfhMPpZ1BplUMKe4JFiOJvY/yxSPhQZLWk
28
+ ai3ZjeZ7V1gUq8cUucV//Fb64q2BqmfRAyb1aTKkZk039ynDQ6Nr8QGzfTmyEgcQ
29
+ 1QgrtaBZ+Rgx0D2eOfqP5uVrpQeGNQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1Ud
30
+ DwQEAwIEsDAdBgNVHQ4EFgQU1dpUE4OmQ+15s1dn///kQpx9NlMwDQYJKoZIhvcN
31
+ AQEFBQADggEBAEHWCFdnW9OMbuIvJsCEHHG/4GDpxgVrzf+FEhnQ9c929wE6nbLN
32
+ 9J5Aktbxw6GBBnNTUJr5NBz6xk31F9esUUxER+pN8UqFuOlGwDVxjvPzflUgD0A4
33
+ r7vlAKMk3trBD5nMIJKoW02RK2SElrjdjq8K/FMGcGIl1kXWs+lePPh9WE0iFL7D
34
+ R252y/PK8xRlA0qwJAz6BG78k8DJnkUNwgZI4FHrjIL1bnH9aJQBsVSYqrv+1Hgx
35
+ WCa1RP53Lsw2rCM/m9V8FUNo8ens2QC1LgDx44DgmnmziCXOVtTGFN8BOgWLeu7A
36
+ b2yC21SpXEO7VfhMU2RwQVMVJ9x87DpKoko=
37
+ -----END CERTIFICATE-----
38
+
39
+ date: 2010-11-22 00:00:00 -07:00
40
+ default_executable:
41
+ dependencies:
42
+ - !ruby/object:Gem::Dependency
43
+ name: htmldoc
44
+ prerelease: false
45
+ requirement: &id001 !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 17
51
+ segments:
52
+ - 0
53
+ - 2
54
+ - 3
55
+ version: 0.2.3
56
+ type: :runtime
57
+ version_requirements: *id001
58
+ description: A Ruby Gem for generating printable labels in a variety of formats(pdf, html, etc.) and templates.
59
+ email: dave@hulihanapplications.com
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ extra_rdoc_files:
65
+ - README.textile
66
+ - lib/lablr.rb
67
+ files:
68
+ - README.textile
69
+ - Rakefile
70
+ - assets/layouts/label.html.erb
71
+ - assets/templates/_avery_5163.erb
72
+ - init.rb
73
+ - lablr-0.0.1.gemspec
74
+ - lib/lablr.rb
75
+ - test.rb
76
+ - Manifest
77
+ - lablr.gemspec
78
+ has_rdoc: true
79
+ homepage: https://github.com/hulihanapplications/Lablr
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --line-numbers
85
+ - --inline-source
86
+ - --title
87
+ - Lablr
88
+ - --main
89
+ - README.textile
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 11
107
+ segments:
108
+ - 1
109
+ - 2
110
+ version: "1.2"
111
+ requirements: []
112
+
113
+ rubyforge_project: lablr
114
+ rubygems_version: 1.3.7
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: A Ruby Gem for generating printable labels in a variety of formats(pdf, html, etc.) and templates.
118
+ test_files: []
119
+
Binary file