Class: Caracal::Core::Models::TableCellModel
- Defined in:
- lib/caracal/core/models/table_cell_model.rb
Overview
This class handles block options passed to tables via their data collections.
Instance Attribute Summary collapse
-
#cell_background ⇒ Object
readonly
accessors.
-
#cell_margins ⇒ Object
readonly
Returns the value of attribute cell_margins.
-
#cell_width ⇒ Object
readonly
Returns the value of attribute cell_width.
Instance Method Summary collapse
-
#apply_styles(opts = {}) ⇒ Object
This method allows styles to be applied to this cell from the table level.
- #calculate_width(default_width) ⇒ Object
-
#contents ⇒ Object
DATA ACCESSORS =======================.
-
#initialize(options = {}, &block) ⇒ TableCellModel
constructor
initialization.
-
#valid? ⇒ Boolean
VALIDATION ===========================.
Constructor Details
#initialize(options = {}, &block) ⇒ TableCellModel
initialization
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/caracal/core/models/table_cell_model.rb', line 28 def initialize(={}, &block) @cell_background = DEFAULT_CELL_BACKGROUND @cell_margins = DEFAULT_CELL_MARGINS if content = .delete(:content) p content, .dup end super , &block end |
Instance Attribute Details
#cell_background ⇒ Object (readonly)
accessors
23 24 25 |
# File 'lib/caracal/core/models/table_cell_model.rb', line 23 def cell_background @cell_background end |
#cell_margins ⇒ Object (readonly)
Returns the value of attribute cell_margins.
25 26 27 |
# File 'lib/caracal/core/models/table_cell_model.rb', line 25 def cell_margins @cell_margins end |
#cell_width ⇒ Object (readonly)
Returns the value of attribute cell_width.
24 25 26 |
# File 'lib/caracal/core/models/table_cell_model.rb', line 24 def cell_width @cell_width end |
Instance Method Details
#apply_styles(opts = {}) ⇒ Object
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.
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 |
# File 'lib/caracal/core/models/table_cell_model.rb', line 60 def apply_styles(opts={}) # make dup of options so we don't # harm args sent to sibling cells = opts.dup # first, try apply to self .each do |(k,v)| send(k, v) if respond_to?(k) end # prevent top-level attrs from trickling down .delete_if { |(k,v)| option_keys.include?(k) } # then, try apply to contents contents.each do |model| .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| .each do |k,v| run.send(k, v) if run.respond_to?(k) end end end end end |
#calculate_width(default_width) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/caracal/core/models/table_cell_model.rb', line 92 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 ⇒ Object
DATA ACCESSORS =======================
46 47 48 |
# File 'lib/caracal/core/models/table_cell_model.rb', line 46 def contents @contents ||= [] end |
#valid? ⇒ Boolean
VALIDATION ===========================
141 142 143 |
# File 'lib/caracal/core/models/table_cell_model.rb', line 141 def valid? contents.size > 0 end |