module Caracal::Core::Tables
This module encapsulates all the functionality related to adding tables to the document.
Public Class Methods
included(base)
click to toggle source
# File lib/caracal/core/tables.rb, line 12 def self.included(base) base.class_eval do #------------------------------------------------------------- # Public Methods #------------------------------------------------------------- def table(*args, &block) options = Caracal::Utilities.extract_options!(args) options.merge!({ data: args.first }) if args.first model = Caracal::Core::Models::TableModel.new(options, &block) if respond_to?(:page_width) container_width = page_width - page_margin_left - page_margin_right model.calculate_width(container_width) end if model.valid? contents << model else raise Caracal::Errors::InvalidModelError, 'Table must be provided data for at least one cell.' end model end end end
Public Instance Methods
table(*args, &block)
click to toggle source
# File lib/caracal/core/tables.rb, line 19 def table(*args, &block) options = Caracal::Utilities.extract_options!(args) options.merge!({ data: args.first }) if args.first model = Caracal::Core::Models::TableModel.new(options, &block) if respond_to?(:page_width) container_width = page_width - page_margin_left - page_margin_right model.calculate_width(container_width) end if model.valid? contents << model else raise Caracal::Errors::InvalidModelError, 'Table must be provided data for at least one cell.' end model end