Class: Uniword::Builder::SdtBuilder
- Inherits:
-
BaseBuilder
- Object
- BaseBuilder
- Uniword::Builder::SdtBuilder
- Defined in:
- lib/uniword/builder/sdt_builder.rb
Overview
Builds Structured Document Tags (content controls).
Supports text controls, date pickers, dropdown lists, bibliography placeholders, and document part references.
Instance Attribute Summary
Attributes inherited from BaseBuilder
Class Method Summary collapse
-
.bibliography ⇒ SdtBuilder
Create a bibliography placeholder.
-
.date(tag: nil, format: "M/d/yyyy", locale: "en-US", calendar: "gregorian") ⇒ SdtBuilder
Create a date picker content control.
- .default_model_class ⇒ Object
-
.doc_part(gallery:, unique: true) ⇒ SdtBuilder
Create a document part content control (e.g., Table of Contents).
-
.text(tag: nil, alias_name: nil, placeholder_text: nil, lock: false) ⇒ SdtBuilder
Create a plain text content control.
Instance Method Summary collapse
-
#alias(value) ⇒ self
Set the display alias.
- #build ⇒ Object
-
#id(value = nil) ⇒ self
Set the SDT identifier.
-
#initialize(model = nil) ⇒ SdtBuilder
constructor
A new instance of SdtBuilder.
-
#lock(_value = true) ⇒ self
Set the lock / content cannot be edited.
- #properties ⇒ Object
-
#showing_placeholder(_value = true) ⇒ self
Set placeholder text showing the placeholder header.
-
#tag(value) ⇒ self
Set the developer tag.
Methods inherited from BaseBuilder
Constructor Details
#initialize(model = nil) ⇒ SdtBuilder
Returns a new instance of SdtBuilder.
26 27 28 29 |
# File 'lib/uniword/builder/sdt_builder.rb', line 26 def initialize(model = nil) super @sdt_id_counter = 0 end |
Class Method Details
.bibliography ⇒ SdtBuilder
Create a bibliography placeholder
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/uniword/builder/sdt_builder.rb', line 148 def self.bibliography sdt = new sdt.properties.bibliography = Wordprocessingml::StructuredDocumentTag::Bibliography.new dpo = Wordprocessingml::StructuredDocumentTag::DocPartObj.new dpo.doc_part_gallery = Wordprocessingml::StructuredDocumentTag::DocPartGallery.new( value: "Bibliographies", ) dpo.doc_part_unique = Wordprocessingml::StructuredDocumentTag::DocPartUnique.new sdt.properties.doc_part_obj = dpo sdt end |
.date(tag: nil, format: "M/d/yyyy", locale: "en-US", calendar: "gregorian") ⇒ SdtBuilder
Create a date picker content control
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/uniword/builder/sdt_builder.rb', line 125 def self.date(tag: nil, format: "M/d/yyyy", locale: "en-US", calendar: "gregorian") sdt = new sdt.tag(tag) if tag date = Wordprocessingml::StructuredDocumentTag::Date.new date.date_format = Wordprocessingml::StructuredDocumentTag::DateFormat.new( value: format, ) date.lid = Wordprocessingml::StructuredDocumentTag::Lid.new(value: locale) date.store_mapped_data_as = Wordprocessingml::StructuredDocumentTag::StoreMappedDataAs.new( value: "dateTime", ) date.calendar = Wordprocessingml::StructuredDocumentTag::Calendar.new( value: calendar, ) sdt.properties.date = date sdt end |
.default_model_class ⇒ Object
22 23 24 |
# File 'lib/uniword/builder/sdt_builder.rb', line 22 def self.default_model_class Wordprocessingml::StructuredDocumentTag end |
.doc_part(gallery:, unique: true) ⇒ SdtBuilder
Create a document part content control (e.g., Table of Contents)
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/uniword/builder/sdt_builder.rb', line 167 def self.doc_part(gallery:, unique: true) sdt = new dpo = Wordprocessingml::StructuredDocumentTag::DocPartObj.new dpo.doc_part_gallery = Wordprocessingml::StructuredDocumentTag::DocPartGallery.new( value: gallery, ) dpo.doc_part_unique = Wordprocessingml::StructuredDocumentTag::DocPartUnique.new if unique sdt.properties.doc_part_obj = dpo sdt end |
.text(tag: nil, alias_name: nil, placeholder_text: nil, lock: false) ⇒ SdtBuilder
Create a plain text content control
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/uniword/builder/sdt_builder.rb', line 105 def self.text(tag: nil, alias_name: nil, placeholder_text: nil, lock: false) sdt = new sdt.tag(tag) if tag sdt.alias(alias_name) if alias_name sdt.lock if lock sdt.properties.text = Wordprocessingml::StructuredDocumentTag::Text.new sdt.showing_placeholder if placeholder_text sdt end |
Instance Method Details
#alias(value) ⇒ self
Set the display alias
57 58 59 60 61 62 |
# File 'lib/uniword/builder/sdt_builder.rb', line 57 def alias(value) properties.alias_name = Wordprocessingml::StructuredDocumentTag::Alias.new( value: value, ) self end |
#build ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/uniword/builder/sdt_builder.rb', line 82 def build unless properties.id properties.id = Wordprocessingml::StructuredDocumentTag::Id.new( value: next_id, ) end @model end |
#id(value = nil) ⇒ self
Set the SDT identifier
35 36 37 38 39 40 |
# File 'lib/uniword/builder/sdt_builder.rb', line 35 def id(value = nil) properties.id = Wordprocessingml::StructuredDocumentTag::Id.new( value: value || next_id, ) self end |
#lock(_value = true) ⇒ self
Set the lock / content cannot be edited
68 69 70 71 |
# File 'lib/uniword/builder/sdt_builder.rb', line 68 def lock(_value = true) properties.temporary = Wordprocessingml::StructuredDocumentTag::Temporary.new self end |
#properties ⇒ Object
91 92 93 94 |
# File 'lib/uniword/builder/sdt_builder.rb', line 91 def properties @model.properties ||= Wordprocessingml::StructuredDocumentTagProperties.new @model.properties end |
#showing_placeholder(_value = true) ⇒ self
Set placeholder text showing the placeholder header
77 78 79 80 |
# File 'lib/uniword/builder/sdt_builder.rb', line 77 def showing_placeholder(_value = true) properties.showing_placeholder_header = Wordprocessingml::StructuredDocumentTag::ShowingPlaceholderHeader.new self end |
#tag(value) ⇒ self
Set the developer tag
46 47 48 49 50 51 |
# File 'lib/uniword/builder/sdt_builder.rb', line 46 def tag(value) properties.tag = Wordprocessingml::StructuredDocumentTag::Tag.new( value: value, ) self end |