Sha256: dfdd0fa958028a97f7453a77c47a6ded61db81c03391159fe8c3e6e8fb6fa673

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'caracal/core/models/table_model'
require 'caracal/errors'


module Caracal
  module Core
    
    # This module encapsulates all the functionality related to adding tables
    # to the document.
    #
    module Tables
      def self.included(base)
        base.class_eval do
          
          #-------------------------------------------------------------
          # Public Methods
          #-------------------------------------------------------------
          
          def table(data, options = {}, &block)
            options.merge!({ data: data })
            
            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
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caracal-0.1.1 lib/caracal/core/tables.rb