Class: Prawn::LabelSheet
- Inherits:
-
Object
- Object
- Prawn::LabelSheet
- Includes:
- View
- Defined in:
- lib/prawn/label_sheet.rb,
lib/prawn/label_sheet/version.rb,
lib/prawn/label_sheet/configuration.rb
Overview
Document supporting bulk label/sticker generation
Defined Under Namespace
Classes: Configuration, Error
Constant Summary collapse
- VERSION =
Gem version
'0.2.0'
Class Attribute Summary collapse
-
.config ⇒ Prawn::LabelSheet::Configuration
Current configuration.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Override Prawn::View#document.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
Class Method Summary collapse
-
.configure {|config| ... } ⇒ Object
Modify configuration.
-
.generate(filename, labels, **options) {|doc, item| ... } ⇒ Object
Render and persist a set of label sheets.
Instance Method Summary collapse
-
#initialize(labels, **options) {|doc, item| ... } ⇒ LabelSheet
constructor
A new instance of LabelSheet.
-
#make_label(item, _options) {|doc, item| ... } ⇒ Integer
Generate individual label.
Constructor Details
#initialize(labels, **options) {|doc, item| ... } ⇒ LabelSheet
Returns a new instance of LabelSheet.
37 38 39 40 41 42 43 44 45 |
# File 'lib/prawn/label_sheet.rb', line 37 def initialize(labels, **, &block) @layout = setup_layout([:layout]).merge(info: [:info]) @document = setup_document([:document], @layout) @count = 0 @break_on = [:break_on] labels.each { |label| make_label(label, , &block) } end |
Class Attribute Details
.config ⇒ Prawn::LabelSheet::Configuration
Current configuration
32 33 34 |
# File 'lib/prawn/label_sheet/configuration.rb', line 32 def config @config ||= Configuration.new end |
Instance Attribute Details
#document ⇒ Object (readonly)
Override Prawn::View#document
17 18 19 |
# File 'lib/prawn/label_sheet.rb', line 17 def document @document end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
18 19 20 |
# File 'lib/prawn/label_sheet.rb', line 18 def layout @layout end |
Class Method Details
.configure {|config| ... } ⇒ Object
Modify configuration
39 40 41 |
# File 'lib/prawn/label_sheet/configuration.rb', line 39 def configure yield config end |
.generate(filename, labels, **options) {|doc, item| ... } ⇒ Object
Render and persist a set of label sheets
26 27 28 29 |
# File 'lib/prawn/label_sheet.rb', line 26 def self.generate(filename, labels, **, &block) pdf = new(labels, **, &block) pdf.document.render_file(filename) end |
Instance Method Details
#make_label(item, _options) {|doc, item| ... } ⇒ Integer
Generate individual label
53 54 55 56 57 58 |
# File 'lib/prawn/label_sheet.rb', line 53 def make_label(item, ) break_page if break_page?(item) @document.grid(*gridref).bounding_box { yield @document, item } @count += 1 end |