Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added Gemfile and Rakefile so it could build. Added label_height and

label_width options for labels that have a covering
  • Loading branch information...
commit e0ce3bf93a8be0fedea045152d4c018e201d4308 1 parent 6216d5f
@dsisnero authored
View
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in prawn-labels.gemspec
+gemspec
View
2  Rakefile
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
View
9 examples/hello_labels.rb
@@ -6,6 +6,9 @@
"Jordan", "Chris", "Jon", "Mike", "Kelly", "Bob", "Greg",
"Jordan", "Chris", "Jon", "Mike", "Kelly", "Bob", "Greg"]
-Prawn::Labels.generate("hello_labels.pdf", fancy_names, :type => "Avery5160") do |pdf, name|
- pdf.text name
-end
+Prawn::Labels.generate("hello_labels.pdf", fancy_names,:outline => true,:type => "tyton") do |pdf, name|
+ pdf.pad(10) do
+ pdf.text name, :align => :center
+ end
+
+end
View
37 lib/prawn/labels.rb
@@ -19,15 +19,24 @@ def self.generate(file_name, data, options = {}, &block)
def initialize(data, options={}, &block)
types_file = File.join(File.dirname(__FILE__), 'types.yaml')
types = YAML.load_file(types_file)
+ @debug = options[:debug]
+ @outline = options[:outline]
unless @type = types[options[:type]]
raise "Label Type Unknown '#{options[:type]}'"
end
@document = Document.new :left_margin => type["left_margin"],
- :right_margin => type["right_margin"]
-
+ :right_margin => type["right_margin"],
+ :bottom_margin => type["bottom_margin"],
+ :top_margin => type["top_margin"]
+
generate_grid @type
+
+ @label_width = type["label_width"]
+ @label_height = type["label_height"]
+
+ @document.grid.show_all if @debug
data.each_with_index do |record, i|
create_label(i, record) do |pdf, record|
@@ -43,12 +52,12 @@ def generate_grid(type)
@document.instance_eval do
define_grid :columns => type["columns"],
- :rows => type["rows"],
- :column_gutter => type["column_gutter"],
- :row_gutter => type["row_gutter"]
+ :rows => type["rows"],
+ :column_gutter => type["column_gutter"],
+ :row_gutter => type["row_gutter"]
end
end
-
+
def row_col_from_index(i)
index = (@document.page_number - 1) * (@document.grid.rows * @document.grid.columns)
@@ -66,14 +75,24 @@ def row_col_from_index(i)
generate_grid @type
[0,0]
end
-
+
def create_label(i,record,&block)
p = row_col_from_index(i)
b = @document.grid(p.first, p.last)
@document.bounding_box b.top_left, :width => b.width, :height => b.height do
- yield(@document, record)
+ @document.stroke_bounds if @outline
+ if @label_width || @label_height
+ width = @label_width || @document.bounds.width
+ height = @label_height || @document.bounds.height
+ @document.bounding_box @document.bounds.top_left, :width => width, :height => height do
+ @document.stroke_bounds if @debug || @outline
+ yield(@document,record)
+ end
+ else
+ yield(@document, record)
+ end
end
end
end
-end
+end
View
5 lib/prawn/labels/version.rb
@@ -0,0 +1,5 @@
+module Prawn
+ module Labels
+ VERSION = "0.0.1"
+ end
+end
View
12 lib/prawn/types.yaml
@@ -12,4 +12,14 @@ Avery5160:
TEST:
left_margin: 123
right_margin: 789
-
+tyton:
+ page_size: LETTER
+ top_margin: 72
+ bottom_margin: 5.7
+ left_margin: 24.09
+ right_margin: 19.84
+ row_gutter: 7.08
+ column_gutter: 21.6
+ columns: 4
+ rows: 3
+ label_height: 56.69
View
22 prawn-labels.gemspec
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "prawn/labels/version"
+
+Gem::Specification.new do |s|
+ s.name = "prawn-labels"
+ s.version = Prawn::Labels::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Jordan Byron"]
+ s.email = ["jordan@ducksoupsoftware.com"]
+ s.homepage = ""
+ s.summary = %q{A Simple helper to generate labels for Prawn PDFs}
+ s.description = %q{Makes it easy to generate labels using prawn}
+
+ s.rubyforge_project = "prawn-labels"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+ s.add_dependency('prawn')
+end
Please sign in to comment.
Something went wrong with that request. Please try again.