Sha256: 175389ffed1d39af7eafb831a1477f6e107b9e999c068d613961916b364d2e45

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 Bytes

Contents

require "active_support/core_ext/class/attribute"
require "active_support/inflector"
require_relative "renderer"

module PrawnCocktail
  class Document
    class_attribute :initializers
    self.initializers = []

    def self.initialize_template(&block)
      self.initializers += [ block ]
    end

    def self.helper(mod)
      initialize_template { extend mod }
    end

    def render
      renderer.render_data
    end

    def render_file(file)
      renderer.render_file(file)
    end

    def filename
      # Override in your subclass.
      nil
    end

    private

    def renderer
      @renderer ||= Renderer.new(template_name, data, initializers)
    end

    def template_name
      self.class.name.underscore
    end

    def data
      # Override in your subclass.
      {}
    end

    def initializers
      self.class.initializers
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prawn_cocktail-0.8.1 lib/prawn_cocktail/document.rb