class HexaPDF::Document::Layout::ChildrenCollector
- end
end
column << document.layout.lorem_ipsum_box # adding a Box instance
column.text(“Text in column”)
list.column(columns: 3) do |column| # registered box name
list.image(image_path) # layout method without _box suffix
list.text_box(“Some text here”) # layout method
document.layout.box(:list) do |list| # list is a ChildrenCollector
Example:
children.
The special method #multiple allows adding multiple boxes as a single array to the collected
list, column, … - Any name registered with the configuration option
layout.boxes.map
.
suffix.
text, formatted_text, image, … - Any method accepted by the Layout class without the _box
text_box, formatted_text_box, image_box, … - Any method accepted by the Layout class.
#<< -
This appends the given box to the list.
A box can be added to the list of collected children in the following ways:
to collect the children for the created box.
be seemlessly doable when creating the parent node. It is yieled, for example, by Layout#box
This class is used when a box can contain child boxes and the creation of such boxes should
- Any method accepted by the Layout class.
- Any method accepted by the Layout class without the _box
- Any name registered with the configuration option
def self.collect(layout)
def self.collect(layout) collector = new(layout) yield(collector) collector.children end
def <<(box)
def <<(box) @children << box end
def initialize(layout)
Create a new ChildrenCollector for the given +layout+ (a HexaPDF::Document::Layout)
def initialize(layout) @layout = layout @children = [] end
def method_missing(name, *args, **kwargs, &block)
def method_missing(name, *args, **kwargs, &block) if @layout.box_creation_method?(name) box = @layout.send(name, *args, **kwargs, &block) @children << box box else super end end
def multiple(&block)
Yields a ChildrenCollector instance and adds the collected children as a single array to
def multiple(&block) @children << self.class.collect(@layout, &block) end
def respond_to_missing?(name, _private)
def respond_to_missing?(name, _private) @layout.box_creation_method?(name) || super end