54 lines
1.5 KiB
Ruby
54 lines
1.5 KiB
Ruby
require 'fourmi/prawn/utils/extensions/text_align'
|
|
|
|
module Fourmi::Prawn::Utils
|
|
module Extensions
|
|
module Box
|
|
def textbox(content = nil, height = 40)
|
|
bounding_box([0, cursor], height: content.blank? && !block_given? ? height : nil, width: bounds.width) do
|
|
pad(5) do
|
|
indent(5) do
|
|
text content unless content.blank?
|
|
yield if block_given?
|
|
end
|
|
end
|
|
stroke_bounds
|
|
end
|
|
end
|
|
|
|
def padded_box(position, padding, **options, &block)
|
|
rounded = options.delete(:rounded)
|
|
rounded = true if rounded.nil?
|
|
|
|
bounding_box position, options do
|
|
bounding_box [padding, bounds.top - padding], width: bounds.width - 2 * padding, height: bounds.height > 2 * padding ? bounds.height - 2 * padding : nil do
|
|
yield block
|
|
move_down padding
|
|
end
|
|
if rounded
|
|
stroke_rounded_bounds
|
|
else
|
|
stroke_bounds
|
|
end
|
|
end
|
|
end
|
|
|
|
def filled_box(color, x: 0, y: cursor, width: bounds.width, height: 150, &block)
|
|
fill_color(color) do
|
|
fill_rectangle [x, y], width, height
|
|
end
|
|
bounding_box([x, y], width: width, height: height, &block)
|
|
end
|
|
|
|
def list(text, options = {})
|
|
float { indent(5) { text '- ' } }
|
|
indent 15 do
|
|
textj text, options
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
require 'prawn/document'
|
|
Prawn::Document.extensions << Prawn::Extensions::Box
|