Module: ExcelTemplating::DocumentDsl

Included in:
Document
Defined in:
lib/excel_templating/document_dsl.rb

Overview

The descriptor module for how to define your template class

Instance Method Summary collapse

Instance Method Details

#data_source_registryObject



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

def data_source_registry
  @data_source_registry ||= ExcelTemplating::Document::DataSourceRegistry.new
end

#default_styling(font: "Calibri", size: 10, align: :left, **options) ⇒ Object

Define the default styling to use when writing a column to the worksheet. See Writeexcel::Format

Parameters:

  • font (String) (defaults to: "Calibri")

    Set the font name

  • size (Integer) (defaults to: 10)

    font size

  • align (Symbol) (defaults to: :left)

    :left, :right, or :center

  • options (Hash)

    Additional options to pass to Format



71
72
73
74
75
76
77
# File 'lib/excel_templating/document_dsl.rb', line 71

def default_styling(font: "Calibri", size: 10, align: :left, ** options)
  @default_styling = {
    name: font,
    size: size,
    align: align
  }.merge(options)
end

#list_source(source_symbol, title:, list: :from_data, inline: false) ⇒ Object

Add a list validator to the excel document

Examples:

list_source :valid_foos, title: "Valid Foos", list: ['foo','bar'], inline: false

Parameters:

  • source_symbol (Symbol)

    symbol to registry for the validator

  • title (String)

    Title to show when displaying this validator

  • list (Array<String>|Symbol) (defaults to: :from_data)

    items to use for validation, you may also use :from_data and at render time the validation items will be fetched from key 'source_symbol'

  • inline (TrueClass|FalseClass) (defaults to: false)

    If true then the validator will be written to the document inline. Otherwise it will be written to a 'DataSheet'



51
52
53
# File 'lib/excel_templating/document_dsl.rb', line 51

def list_source(source_symbol, title:, list: :from_data, inline: false)
  data_source_registry.add_list(source_symbol, title, list, inline)
end

#organization(string) ⇒ Object

Define an organization for the workbook. May use mustaching.

Parameters:

  • string (String)


81
82
83
# File 'lib/excel_templating/document_dsl.rb', line 81

def organization(string)
  @document_organization = string
end

#protect_document(protect = true) ⇒ Object



34
35
36
# File 'lib/excel_templating/document_dsl.rb', line 34

def protect_document(protect=true)
  @protected = protect
end

#protected?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/excel_templating/document_dsl.rb', line 38

def protected?
  !!@protected
end

#sheet(sheet_number, &block) ⇒ Object

Define a sheet on this document

Examples:

sheet 1 do
  repeat_row 17, with: :people
end

Parameters:

  • sheet_number (Integer)
  • block (Proc)


27
28
29
30
31
32
# File 'lib/excel_templating/document_dsl.rb', line 27

def sheet(sheet_number, &block)
  sheet = ExcelTemplating::Document::Sheet.new(sheet_number)
  sheets << sheet
  sheet.instance_eval(&block)
  nil
end

#sheetsArray<ExcelTemplating::Document::Sheet>

Returns The sheets defined for this document class.

Returns:



16
17
18
# File 'lib/excel_templating/document_dsl.rb', line 16

def sheets
  @sheets ||= []
end

#template(path) ⇒ Object

Parameters:

  • path (String)

    Set the path to the template for this document class.

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/excel_templating/document_dsl.rb', line 10

def template(path)
  raise ArgumentError, "Template path must be a string." unless path.is_a?(String)
  @template_path = path
end

#template_pathString

Returns The template path.

Returns:

  • (String)

    The template path.



5
6
7
# File 'lib/excel_templating/document_dsl.rb', line 5

def template_path
  @template_path
end

#title(string) ⇒ Object

Define a title for this workbook. You may use mustaching here.

Parameters:

  • string (String)


61
62
63
# File 'lib/excel_templating/document_dsl.rb', line 61

def title(string)
  @document_title = string
end