Sha256: 72a626f7a00adcfc2baea93149efbb5d837cb892414dc55a26742c1ccd6f1d1d

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

require 'open-uri' # for open(http://...)
module Elegant
  class Footer
    include Prawn::View

    def initialize(document, options = {})
      @document = document
      @text, @url = options.values_at :text, :url
    end

    # Draws in the header of each page a horizontal line, the name of the
    # author, the title and the page number. The author must be provided in
    # the configuration, and the title when initializing the document.
    def render
      repeat(:all) do
        transparent(0.25) { stroke_horizontal_line 0, bounds.width, at: 0 }
        render_author
        render_text if @text
      end
      render_page_number
    end

  private

    def render_author
      options = {at: [0, -6], width: 50, height: 10, size: 7, valign: :top}
      text_box Elegant.configuration.author, options
    end

    def render_text
      text = @url ? "<link href='#{@url}'>#{@text}</link>" : @text
      left = 50
      options = {size: 7, align: :center, valign: :top, inline_format: true}
      options[:at] = [left, -6]
      options[:width] = bounds.width - 2 * left
      options[:height] = 10
      text_box text, options
    end

    def render_page_number
      options = {width: 50, height: 10, size: 7, align: :right, valign: :top}
      options[:at] = [bounds.width - options[:width], -6]
      number_pages "Page <page>", options
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
elegant-1.1.0 lib/elegant/footer.rb
elegant-1.0.0 lib/elegant/footer.rb