Class: ExcelTemplating::Document

Inherits:
Object
  • Object
show all
Extended by:
DocumentDsl
Defined in:
lib/excel_templating/document.rb

Overview

The base document class for an ExcelTemplating. Inherit from document to create your own ExcelTemplating that you may then use to generate Excel Spreadsheets from the template you supply.

Examples:

class MyTemplate < ExcelTemplating::Document
  template "my_template.mustache.xlsx"
  title "My title: {{my_company}}"
  organization "{{organization_name}}"
  default_styling(
    text_wrap: 0,
    font: "Calibri",
    size: 10,
    align: :left,
  )
  sheet 1 do
    repeat_row 17, with: :people
  end
end

Defined Under Namespace

Classes: DataSourceRegistry, Sheet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DocumentDsl

data_source_registry, default_styling, list_source, organization, protect_document, protected?, sheet, sheets, template, template_path, title

Constructor Details

#initialize(data) ⇒ Document

Create a new document with given data. 'all_sheets' is available to the template on each sheet. otherwise each numeric key in 'sheet_data' provides the data for that specific sheet. For example {foo: 'bar', 1 => "foo"}

Parameters:

  • data (Hash)

    Hash with variables for rendering.



45
46
47
# File 'lib/excel_templating/document.rb', line 45

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



59
60
61
# File 'lib/excel_templating/document.rb', line 59

def data
  @data
end

Class Method Details

.document_default_stylingHash

Returns The default styling for the document.

Returns:

  • (Hash)

    The default styling for the document



37
38
39
# File 'lib/excel_templating/document.rb', line 37

def document_default_styling
  @default_styling || default_styling
end

.document_organizationString

Returns The document organization.

Returns:

  • (String)

    The document organization



32
33
34
# File 'lib/excel_templating/document.rb', line 32

def document_organization
  @document_organization
end

.document_titleString

The non Dsl Methods, not expected to be used as part of the document description

Returns:

  • (String)

    The document title



27
28
29
# File 'lib/excel_templating/document.rb', line 27

def document_title
  @document_title
end

Instance Method Details

#render(&block) ⇒ Object

Render this template.

Examples:

instance = MyTemplate.new(all_sheets: {foo: 1},1 => {bar: "foo"})
instance.render do |file_path|
  FileUtils.cp(file_path, somewhere_else)
end


55
56
57
# File 'lib/excel_templating/document.rb', line 55

def render(&block)
  new_renderer.render(&block)
end