Class: Laser::Cutter::Renderer::MetaRenderer
- Defined in:
- lib/laser/cutter/renderer/meta_renderer.rb
Overview
Draws the block of settings at the bottom left of a PDF, under a banner that names the gem.
Constant Summary collapse
- META_KEYS =
The settings printed, in order, when they are set.
%i(units width height depth front_height slope thickness notch lid kerf stroke padding margin page_size page_layout).freeze
- WIDTH =
The block, in points: its width, the height of the banner above the settings, the height of one line of them, and the space under the last.
140- BANNER_HEIGHT =
55- LINE_HEIGHT =
8.2- FOOTER_HEIGHT =
4
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#config, #enclosure, #page_manager, #subject
Instance Method Summary collapse
-
#fields ⇒ Hash{Symbol => Object}
The settings the block prints, in order.
-
#initialize(config = {}) ⇒ MetaRenderer
constructor
A new instance of MetaRenderer.
- #render(pdf = nil) ⇒ void
Methods inherited from Base
Constructor Details
#initialize(config = {}) ⇒ MetaRenderer
Returns a new instance of MetaRenderer.
23 24 25 26 27 |
# File 'lib/laser/cutter/renderer/meta_renderer.rb', line 23 def initialize(config = {}) self.config = config height = BANNER_HEIGHT + (fields.size * LINE_HEIGHT) + FOOTER_HEIGHT self.enclosure = Laser::Cutter::Geometry::Rect.create(Laser::Cutter::Geometry::Point[1, 1], WIDTH, height) end |
Instance Method Details
#fields ⇒ Hash{Symbol => Object}
The settings the block prints, in order. The block is as tall as they need: one line too many would start a second page.
33 34 35 36 37 38 |
# File 'lib/laser/cutter/renderer/meta_renderer.rb', line 33 def fields = config.to_hash [:page_size] ||= 'custom' .delete(:page_layout) if [:page_size].eql?('custom') META_KEYS.select { |key| [key] }.to_h { |key| [key, [key]] } end |
#render(pdf = nil) ⇒ void
This method returns an undefined value.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/laser/cutter/renderer/meta_renderer.rb', line 42 def render(pdf = nil) = <<-EOF Made with Laser Cutter Ruby Gem (v#{Laser::Cutter::VERSION}) Credits to Prawn for ruby PDF generation, and BoxMaker for inspiration. Online: http://makeabox.io/ Source: https://github.com/kigster/laser-cutter EOF = BLUE = BANNER_HEIGHT = fields.keys.join(": \n") + ": \n" = fields.values.join("\n") rect = enclosure pdf.instance_eval do self.line_width = 0.2.mm float do bounding_box([rect.p1.x, rect.h + rect.p1.y], width: rect.w, height: rect.h) do stroke_color stroke_bounds # Print banner indent 10 do font('Helvetica', size: 6) do text , color: end end # print values of the config, in two parts – keys right aligned first, values left aligned second. float do bounding_box([0, rect.h - ], width: rect.w, height: rect.h - ) do float do bounding_box([0, rect.h - ], width: 70, height: rect.h - ) do indent 10 do font('Helvetica', size: 7) do text , color: , align: :right end end end end float do bounding_box([60, rect.h - ], width: 70, height: rect.h - ) do indent 10 do font('Helvetica', size: 7) do text , color: end end end end end end end end end end |