class Caracal::Core::Models::TableCellModel
This class handles block options passed to tables via their data collections.
Attributes
cell_background[R]
accessors
cell_colspan[R]
cell_margins[R]
cell_rowspan[R]
cell_vertical_align[R]
cell_width[R]
Public Class Methods
new(options={}, &block)
click to toggle source
initialization
Calls superclass method
Caracal::Core::Models::BaseModel::new
# File lib/caracal/core/models/table_cell_model.rb, line 33 def initialize(options={}, &block) @cell_background = DEFAULT_CELL_BACKGROUND @cell_margins = DEFAULT_CELL_MARGINS @cell_vertical_align = DEFAULT_CELL_VERTICAL_ALIGN if content = options.delete(:content) if content.is_a? BaseModel contents << content else p content, options.dup, &block end end super options, &block p_klass = Caracal::Core::Models::ParagraphModel # the final tag in a table cell unless contents.last.is_a? p_klass # *must* be a paragraph for OOXML contents << p_klass.new(content: '') # to not throw an error. end end
Public Instance Methods
apply_styles(opts={})
click to toggle source
This method allows styles to be applied to this cell from the table level. It attempts to add the style first to the instance, and then to any sub-models that respond to the method.
In all cases, invalid options will simply be ignored.
# File lib/caracal/core/models/table_cell_model.rb, line 75 def apply_styles(opts={}) # make dup of options so we don't # harm args sent to sibling cells options = opts.dup # first, try apply to self options.each do |(k,v)| send(k, v) if respond_to?(k) end # prevent top-level attrs from trickling down options.delete_if { |(k,v)| option_keys.include?(k) } # then, try apply to contents contents.each do |model| options.each do |k,v| model.send(k, v) if model.respond_to?(k) end # finally, apply to runs. options do trickle down # because paragraph-level styles don't seem to # affect runs within tables. weirdsies. if model.respond_to?(:runs) model.runs.each do |run| options.each do |k,v| run.send(k, v) if run.respond_to?(k) end end end end end
calculate_width(default_width)
click to toggle source
# File lib/caracal/core/models/table_cell_model.rb, line 107 def calculate_width(default_width) width(default_width) unless cell_width.to_i > 0 container_width = cell_width - cell_margin_left - cell_margin_right contents.each do |model| if model.respond_to?(:calculate_width) model.calculate_width(container_width) # will always be a TableModel end end end
contents()
click to toggle source
Private Instance Methods
option_keys()
click to toggle source
# File lib/caracal/core/models/table_cell_model.rb, line 172 def option_keys [:background, :margins, :width, :vertical_align, :rowspan, :colspan] end