Sha256: 5472c22010cda11ed7d3d0bf9354375f254c80865034ae307d4197f5962ef858

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# coding: utf-8

module Thinreports
  module Layout

    class Base
      EXT_NAME = 'tlf'
      include Utils

      class << self
        # @param [String] filename
        # @return [Thinreports::Layout::Format]
        # @raise [Thinreports::Errors::InvalidLayoutFormat]
        # @raise [Thinreports::Errors::IncompatibleLayoutFormat]
        def load_format(filename)
          filename += ".#{EXT_NAME}" unless filename =~/\.#{EXT_NAME}$/

          unless File.exist?(filename)
            raise Thinreports::Errors::LayoutFileNotFound
          end
          # Build format.
          Thinreports::Layout::Format.build(filename)
        end
      end

      attr_reader :format

      # @return [String]
      attr_reader :filename

      # @return [Symbol]
      attr_reader :id

      # @param [String] filename
      # @param [Hash] options
      # @option options [Symbol] :id (nil)
      def initialize(filename, options = {})
        @filename = filename
        @format   = self.class.load_format(filename)
        @id       = options[:id]
      end

      # @return [Boolean] Return the true if is default layout.
      def default?
        @id.nil?
      end

      # @yield [config]
      # @yieldparam [List::Configuration] config
      # @return [List::Configuration]
      def config(&block)
        @config ||= Layout::Configuration.new(self)
        call_block_in(@config, &block)
      end

      # @param [Thinreports::Report::Base] parent
      # @param [Hash] options ({})
      # @option option [Boolean] :count (true)
      # @return [Page]
      def new_page(parent, options = {})
        Report::Page.new(parent, self, options)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinreports-0.8.2 lib/thinreports/layout/base.rb