Class: Uniword::Builder::ThemeBuilder
- Inherits:
-
Object
- Object
- Uniword::Builder::ThemeBuilder
- Defined in:
- lib/uniword/builder/theme_builder.rb
Overview
Builds and applies themes to documents.
Themes control the overall look of a document through color schemes, font schemes, and format schemes.
Instance Method Summary collapse
-
#apply(name) ⇒ self
Apply a named bundled theme.
-
#apply_file(path, variant: nil) ⇒ self
Apply a theme from a .thmx file.
-
#available ⇒ Array<String>
List available bundled themes.
-
#color(slot) ⇒ String?
Get a theme color value.
-
#colors(**overrides) ⇒ self
Override theme colors.
-
#fonts(major: nil, minor: nil) ⇒ self
Override theme fonts.
-
#initialize(document) ⇒ ThemeBuilder
constructor
A new instance of ThemeBuilder.
Constructor Details
#initialize(document) ⇒ ThemeBuilder
Returns a new instance of ThemeBuilder.
19 20 21 |
# File 'lib/uniword/builder/theme_builder.rb', line 19 def initialize(document) @document = document end |
Instance Method Details
#apply(name) ⇒ self
Apply a named bundled theme
Bundled themes are YAML files in data/themes/. Available themes: Themes::Theme.available_themes
30 31 32 33 34 35 |
# File 'lib/uniword/builder/theme_builder.rb', line 30 def apply(name) friendly = Themes::Theme.load(name) @document.model.theme = Themes::ThemeTransformation.new.to_word(friendly) self end |
#apply_file(path, variant: nil) ⇒ self
Apply a theme from a .thmx file
42 43 44 45 46 |
# File 'lib/uniword/builder/theme_builder.rb', line 42 def apply_file(path, variant: nil) @document.model.theme = Drawingml::Theme.from_thmx(path, variant: variant) self end |
#available ⇒ Array<String>
List available bundled themes
93 94 95 |
# File 'lib/uniword/builder/theme_builder.rb', line 93 def available Themes::Theme.available_themes end |
#color(slot) ⇒ String?
Get a theme color value
86 87 88 |
# File 'lib/uniword/builder/theme_builder.rb', line 86 def color(slot) @document.model.theme&.color(slot.to_sym) end |
#colors(**overrides) ⇒ self
Override theme colors
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/uniword/builder/theme_builder.rb', line 52 def colors(**overrides) theme = @document.model.theme return self unless theme scheme = theme.theme_elements&.clr_scheme return self unless scheme overrides.each do |slot, color| scheme[slot.to_sym] = color end self end |
#fonts(major: nil, minor: nil) ⇒ self
Override theme fonts
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/uniword/builder/theme_builder.rb', line 70 def fonts(major: nil, minor: nil) theme = @document.model.theme return self unless theme fs = theme.theme_elements&.font_scheme return self unless fs fs.major_font = major if major fs.minor_font = minor if minor self end |