Class: Lutaml::Xsd::Spa::HtmlDocumentBuilder
- Inherits:
-
Object
- Object
- Lutaml::Xsd::Spa::HtmlDocumentBuilder
- Defined in:
- lib/lutaml/xsd/spa/html_document_builder.rb
Overview
HTML document builder (Builder Pattern)
Provides a fluent interface for building complete HTML documents with proper structure, meta tags, styles, and scripts. This builder separates the construction of a complex HTML document from its representation.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#body_attribute(name, value) ⇒ self
Add body attribute.
-
#body_class(class_name) ⇒ self
Add body class.
-
#body_content(content) ⇒ self
Set body content.
-
#build ⇒ String
Build complete HTML document.
-
#charset(charset = "UTF-8") ⇒ self
Add charset meta tag.
-
#external_script(src, options = {}) ⇒ self
Add external script.
-
#external_stylesheet(href) ⇒ self
Add external stylesheet link.
-
#head_content(content) ⇒ self
Add content to head section.
-
#initialize(options = {}) ⇒ HtmlDocumentBuilder
constructor
Initialize HTML document builder.
-
#inline_script(js, options = {}) ⇒ self
Add inline script content.
-
#inline_style(css) ⇒ self
Add inline style content.
-
#language(value) ⇒ self
Set document language.
-
#meta_tag(name, content) ⇒ self
Add meta tag.
-
#reset ⇒ self
Reset builder to initial state.
-
#theme(theme) ⇒ self
Set theme (adds data-theme attribute to body).
-
#title(value) ⇒ self
Set document title.
-
#viewport(content = "width=device-width, initial-scale=1.0") ⇒ self
Add viewport meta tag.
Constructor Details
#initialize(options = {}) ⇒ HtmlDocumentBuilder
Initialize HTML document builder
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 36 def initialize( = {}) @options = .merge() @meta_tags = [] @stylesheets = [] @inline_styles = [] @scripts = [] @inline_scripts = [] @body_classes = [] @body_attributes = {} @head_content = [] @body_content = "" end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
31 32 33 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 31 def @options end |
Instance Method Details
#body_attribute(name, value) ⇒ self
Add body attribute
147 148 149 150 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 147 def body_attribute(name, value) @body_attributes[name] = value self end |
#body_class(class_name) ⇒ self
Add body class
137 138 139 140 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 137 def body_class(class_name) @body_classes << class_name self end |
#body_content(content) ⇒ self
Set body content
165 166 167 168 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 165 def body_content(content) @body_content = content self end |
#build ⇒ String
Build complete HTML document
182 183 184 185 186 187 188 189 190 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 182 def build parts = [] parts << doctype parts << html_open_tag parts << build_head parts << build_body parts << html_close_tag parts.join("\n") end |
#charset(charset = "UTF-8") ⇒ self
Add charset meta tag
81 82 83 84 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 81 def charset(charset = "UTF-8") @options[:charset] = charset self end |
#external_script(src, options = {}) ⇒ self
Add external script
118 119 120 121 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 118 def external_script(src, = {}) @scripts << { src: src, options: } self end |
#external_stylesheet(href) ⇒ self
Add external stylesheet link
99 100 101 102 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 99 def external_stylesheet(href) @stylesheets << href self end |
#head_content(content) ⇒ self
Add content to head section
156 157 158 159 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 156 def head_content(content) @head_content << content self end |
#inline_script(js, options = {}) ⇒ self
Add inline script content
128 129 130 131 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 128 def inline_script(js, = {}) @inline_scripts << { content: js, options: } self end |
#inline_style(css) ⇒ self
Add inline style content
108 109 110 111 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 108 def inline_style(css) @inline_styles << css self end |
#language(value) ⇒ self
Set document language
62 63 64 65 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 62 def language(value) @options[:lang] = value self end |
#meta_tag(name, content) ⇒ self
Add meta tag
72 73 74 75 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 72 def (name, content) @meta_tags << { name: name, content: content } self end |
#reset ⇒ self
Reset builder to initial state
195 196 197 198 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 195 def reset initialize(@options.slice(:lang, :charset, :viewport)) self end |
#theme(theme) ⇒ self
Set theme (adds data-theme attribute to body)
174 175 176 177 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 174 def theme(theme) body_attribute("data-theme", theme) self end |
#title(value) ⇒ self
Set document title
53 54 55 56 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 53 def title(value) @options[:title] = value self end |
#viewport(content = "width=device-width, initial-scale=1.0") ⇒ self
Add viewport meta tag
90 91 92 93 |
# File 'lib/lutaml/xsd/spa/html_document_builder.rb', line 90 def (content = "width=device-width, initial-scale=1.0") @options[:viewport] = content self end |