Module: Uniword::Builder
- Defined in:
- lib/uniword/builder.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/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: HasBorders, HasShading Classes: BaseBuilder, BibliographyBuilder, ChartBuilder, 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 with a tab character.
-
.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
187 188 189 |
# File 'lib/uniword/builder.rb', line 187 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.
135 136 137 138 139 140 |
# File 'lib/uniword/builder.rb', line 135 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
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/uniword/builder.rb', line 86 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.
120 121 122 |
# File 'lib/uniword/builder.rb', line 120 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
163 164 165 166 167 |
# File 'lib/uniword/builder.rb', line 163 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
145 146 147 148 149 |
# File 'lib/uniword/builder.rb', line 145 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
172 173 174 |
# File 'lib/uniword/builder.rb', line 172 def self.page_number_field build_field_paragraph(" PAGE ") end |
.tab ⇒ Wordprocessingml::Run
Factory: creates a Run with a tab character
154 155 156 157 158 |
# File 'lib/uniword/builder.rb', line 154 def self.tab run = Wordprocessingml::Run.new run.tab = Wordprocessingml::Tab.new run end |
.tab_stop(position:, alignment: :left, leader: nil) ⇒ Properties::TabStop
Factory: creates a TabStop
104 105 106 107 108 109 110 |
# File 'lib/uniword/builder.rb', line 104 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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/uniword/builder.rb', line 57 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
195 196 197 |
# File 'lib/uniword/builder.rb', line 195 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
179 180 181 |
# File 'lib/uniword/builder.rb', line 179 def self.total_pages_field build_field_paragraph(" NUMPAGES ") end |