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
- #data_source_registry ⇒ Object
-
#default_styling(font: "Calibri", size: 10, align: :left, **options) ⇒ Object
Define the default styling to use when writing a column to the worksheet.
-
#list_source(source_symbol, title:, list: :from_data, inline: false) ⇒ Object
Add a list validator to the excel document.
-
#organization(string) ⇒ Object
Define an organization for the workbook.
- #protect_document(protect = true) ⇒ Object
- #protected? ⇒ Boolean
-
#sheet(sheet_number, &block) ⇒ Object
Define a sheet on this document.
-
#sheets ⇒ Array<ExcelTemplating::Document::Sheet>
The sheets defined for this document class.
- #template(path) ⇒ Object
-
#template_path ⇒ String
The template path.
-
#title(string) ⇒ Object
Define a title for this workbook.
Instance Method Details
#data_source_registry ⇒ Object
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
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, ** ) @default_styling = { name: font, size: size, align: align }.merge() end |
#list_source(source_symbol, title:, list: :from_data, inline: false) ⇒ Object
Add a list validator to the excel document
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.
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
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
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 |
#sheets ⇒ Array<ExcelTemplating::Document::Sheet>
Returns The sheets defined for this document class.
16 17 18 |
# File 'lib/excel_templating/document_dsl.rb', line 16 def sheets @sheets ||= [] end |
#template(path) ⇒ Object
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_path ⇒ String
Returns 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.
61 62 63 |
# File 'lib/excel_templating/document_dsl.rb', line 61 def title(string) @document_title = string end |