Module: Uniword::Builder
- Defined in:
- lib/uniword/builder.rb,
lib/uniword/builder/run_utils.rb,
lib/uniword/builder/has_borders.rb,
lib/uniword/builder/has_shading.rb,
lib/uniword/builder/run_builder.rb,
lib/uniword/builder/sdt_builder.rb,
lib/uniword/builder/toc_builder.rb,
lib/uniword/builder/base_builder.rb,
lib/uniword/builder/list_builder.rb,
lib/uniword/builder/chart_builder.rb,
lib/uniword/builder/image_builder.rb,
lib/uniword/builder/style_builder.rb,
lib/uniword/builder/table_builder.rb,
lib/uniword/builder/theme_builder.rb,
lib/uniword/builder/comment_builder.rb,
lib/uniword/builder/section_builder.rb,
lib/uniword/builder/comment_anchorer.rb,
lib/uniword/builder/deterministic_id.rb,
lib/uniword/builder/document_builder.rb,
lib/uniword/builder/footnote_builder.rb,
lib/uniword/builder/numbering_builder.rb,
lib/uniword/builder/paragraph_builder.rb,
lib/uniword/builder/table_row_builder.rb,
lib/uniword/builder/watermark_builder.rb,
lib/uniword/builder/table_cell_builder.rb,
lib/uniword/builder/bibliography_builder.rb,
lib/uniword/builder/header_footer_builder.rb
Overview
Builder module provides a construction API for OOXML models.
The Builder API orchestrates the creation and manipulation of OOXML model objects without adding convenience methods to the model classes themselves.
Defined Under Namespace
Modules: DeterministicId, HasBorders, HasShading, RunUtils Classes: BaseBuilder, BibliographyBuilder, ChartBuilder, CommentAnchorer, CommentBuilder, DocumentBuilder, FootnoteBuilder, HeaderFooterBuilder, ImageBuilder, ListBuilder, NumberingBuilder, ParagraphBuilder, RunBuilder, SdtBuilder, SectionBuilder, StyleBuilder, TableBuilder, TableCellBuilder, TableRowBuilder, ThemeBuilder, TocBuilder, WatermarkBuilder
Class Method Summary collapse
-
.date_field(format: "M/d/yyyy") ⇒ Wordprocessingml::Paragraph
Factory: creates a paragraph containing a DATE field.
-
.floating_image(path, width: nil, height: nil, align: nil, wrap: :square, behind_text: false) ⇒ Wordprocessingml::Drawing
Factory: creates a floating image Drawing NOTE: This does NOT register the image in the document's image_parts.
-
.hyperlink(target, text = nil, **options) ⇒ Wordprocessingml::Hyperlink
Factory: creates a Hyperlink with optional text run.
-
.image(path, width: nil, height: nil) ⇒ Wordprocessingml::Run
Factory: creates a Run containing an inline image Drawing NOTE: This does NOT register the image in the document's image_parts.
-
.line_break ⇒ Wordprocessingml::Run
Factory: creates a Run containing a line break.
-
.page_break ⇒ Wordprocessingml::Run
Factory: creates a page break Run.
-
.page_number_field ⇒ Wordprocessingml::Paragraph
Factory: creates a paragraph containing a PAGE field.
-
.tab ⇒ Wordprocessingml::Run
Factory: creates a Run containing a tab character.
-
.tab_element ⇒ Wordprocessingml::Tab
Factory: creates a bare Tab element for direct assignment to Run#tab.
-
.tab_stop(position:, alignment: :left, leader: nil) ⇒ Properties::TabStop
Factory: creates a TabStop.
-
.text(content, **formatting) ⇒ Wordprocessingml::Run
Factory: creates a Run with optional formatting.
-
.time_field(format: "h:mm:ss am/pm") ⇒ Wordprocessingml::Paragraph
Factory: creates a paragraph containing a TIME field.
-
.total_pages_field ⇒ Wordprocessingml::Paragraph
Factory: creates a paragraph containing a NUMPAGES field.
Class Method Details
.date_field(format: "M/d/yyyy") ⇒ Wordprocessingml::Paragraph
Factory: creates a paragraph containing a DATE field
199 200 201 |
# File 'lib/uniword/builder.rb', line 199 def self.date_field(format: "M/d/yyyy") build_field_paragraph(" DATE \\@ \"#{format}\" ") end |
.floating_image(path, width: nil, height: nil, align: nil, wrap: :square, behind_text: false) ⇒ Wordprocessingml::Drawing
Factory: creates a floating image Drawing NOTE: This does NOT register the image in the document's image_parts. Use DocumentBuilder#floating_image instead for proper DOCX packaging.
137 138 139 140 141 142 |
# File 'lib/uniword/builder.rb', line 137 def self.floating_image(path, width: nil, height: nil, align: nil, wrap: :square, behind_text: false) ImageBuilder.create_floating(nil, path, width: width, height: height, align: align, wrap: wrap, behind_text: behind_text) end |
.hyperlink(target, text = nil, **options) ⇒ Wordprocessingml::Hyperlink
Factory: creates a Hyperlink with optional text run
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/uniword/builder.rb', line 88 def self.hyperlink(target, text = nil, **) hl = Wordprocessingml::Hyperlink.new hl.target = target if text color = .fetch(:color, "0000FF") ul = .fetch(:underline, true) run = self.text(text, color: color, underline: ul ? "single" : nil) hl.runs << run end hl end |
.image(path, width: nil, height: nil) ⇒ Wordprocessingml::Run
Factory: creates a Run containing an inline image Drawing NOTE: This does NOT register the image in the document's image_parts. Use DocumentBuilder#image instead for proper DOCX packaging.
122 123 124 |
# File 'lib/uniword/builder.rb', line 122 def self.image(path, width: nil, height: nil) ImageBuilder.create_drawing(nil, path, width: width, height: height) end |
.line_break ⇒ Wordprocessingml::Run
Factory: creates a Run containing a line break
175 176 177 178 179 |
# File 'lib/uniword/builder.rb', line 175 def self.line_break run = Wordprocessingml::Run.new run.break = Wordprocessingml::Break.new(type: "line") run end |
.page_break ⇒ Wordprocessingml::Run
Factory: creates a page break Run
147 148 149 150 151 |
# File 'lib/uniword/builder.rb', line 147 def self.page_break run = Wordprocessingml::Run.new run.break = Wordprocessingml::Break.new(type: "page") run end |
.page_number_field ⇒ Wordprocessingml::Paragraph
Factory: creates a paragraph containing a PAGE field
184 185 186 |
# File 'lib/uniword/builder.rb', line 184 def self.page_number_field build_field_paragraph(" PAGE ") end |
.tab ⇒ Wordprocessingml::Run
Factory: creates a Run containing a tab character. Use this with ParagraphBuilder#<< to append a tab to a paragraph.
158 159 160 161 162 |
# File 'lib/uniword/builder.rb', line 158 def self.tab run = Wordprocessingml::Run.new run.tab = tab_element run end |
.tab_element ⇒ Wordprocessingml::Tab
Factory: creates a bare Tab element for direct assignment to Run#tab. Most callers should use .tab instead, which wraps the Tab in a Run.
168 169 170 |
# File 'lib/uniword/builder.rb', line 168 def self.tab_element Wordprocessingml::Tab.new end |
.tab_stop(position:, alignment: :left, leader: nil) ⇒ Properties::TabStop
Factory: creates a TabStop
106 107 108 109 110 111 112 |
# File 'lib/uniword/builder.rb', line 106 def self.tab_stop(position:, alignment: :left, leader: nil) Properties::TabStop.new( position: position, alignment: alignment.to_s, leader: leader, ) end |
.text(content, **formatting) ⇒ Wordprocessingml::Run
Factory: creates a Run with optional formatting
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/uniword/builder.rb', line 59 def self.text(content, **formatting) run = Wordprocessingml::Run.new(text: content) return run if formatting.empty? props = Wordprocessingml::RunProperties.new props.bold = Properties::Bold.new(value: true) if formatting[:bold] props.italic = Properties::Italic.new(value: true) if formatting[:italic] if formatting[:underline] val = formatting[:underline] == true ? "single" : formatting[:underline].to_s props.underline = Properties::Underline.new(value: val) end props.color = Properties::ColorValue.new(value: formatting[:color].to_s) if formatting[:color] props.size = Properties::FontSize.new(value: formatting[:size].to_i * 2) if formatting[:size] props.font = formatting[:font] if formatting[:font] props.highlight = Properties::Highlight.new(value: formatting[:highlight].to_s) if formatting[:highlight] props.strike = Properties::Strike.new(value: true) if formatting[:strike] props.small_caps = Properties::SmallCaps.new(value: true) if formatting[:small_caps] props.caps = Properties::Caps.new(value: true) if formatting[:caps] run.properties = props run end |
.time_field(format: "h:mm:ss am/pm") ⇒ Wordprocessingml::Paragraph
Factory: creates a paragraph containing a TIME field
207 208 209 |
# File 'lib/uniword/builder.rb', line 207 def self.time_field(format: "h:mm:ss am/pm") build_field_paragraph(" TIME \\@ \"#{format}\" ") end |
.total_pages_field ⇒ Wordprocessingml::Paragraph
Factory: creates a paragraph containing a NUMPAGES field
191 192 193 |
# File 'lib/uniword/builder.rb', line 191 def self.total_pages_field build_field_paragraph(" NUMPAGES ") end |