Class: Metanorma::Html::Theme
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Metanorma::Html::Theme
- Defined in:
- lib/metanorma/html/theme.rb
Constant Summary collapse
- THEMES_DIR =
File.join(File.dirname(__FILE__), "..", "..", "..", "data", "themes")
- TEMPLATES_ROOT =
File.join(File.dirname(__FILE__), "templates")
Instance Attribute Summary collapse
-
#theme_dir ⇒ Object
--- Non-YAML state (set programmatically) ---.
Class Method Summary collapse
Instance Method Summary collapse
- #logos ⇒ Object
- #resolve_asset(filename) ⇒ Object
- #resolve_template(template_name) ⇒ Object
- #theme_assets_dir ⇒ Object
- #theme_css_path ⇒ Object
- #theme_templates_dir ⇒ Object
- #to_css ⇒ Object
- #to_css_extras ⇒ Object
- #to_css_root ⇒ Object
Instance Attribute Details
#theme_dir ⇒ Object
--- Non-YAML state (set programmatically) ---
121 122 123 |
# File 'lib/metanorma/html/theme.rb', line 121 def theme_dir @theme_dir end |
Class Method Details
.from_directory(path, flavor) ⇒ Object
140 141 142 143 144 |
# File 'lib/metanorma/html/theme.rb', line 140 def self.from_directory(path, flavor) theme = from_yaml(File.read(path)) theme.theme_dir = File.join(THEMES_DIR, flavor.to_s) theme end |
.from_file(path) ⇒ Object
136 137 138 |
# File 'lib/metanorma/html/theme.rb', line 136 def self.from_file(path) from_yaml(File.read(path)) end |
.load(flavor) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/metanorma/html/theme.rb', line 123 def self.load(flavor) dir_theme = File.join(THEMES_DIR, flavor.to_s, "theme.yaml") flat_theme = File.join(THEMES_DIR, "#{flavor}.yaml") if File.exist?(dir_theme) from_directory(dir_theme, flavor) elsif File.exist?(flat_theme) from_file(flat_theme) else new end end |
Instance Method Details
#logos ⇒ Object
146 147 148 |
# File 'lib/metanorma/html/theme.rb', line 146 def logos logos_light end |
#resolve_asset(filename) ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/metanorma/html/theme.rb', line 179 def resolve_asset(filename) if theme_assets_dir flavor_path = File.join(theme_assets_dir, filename) return flavor_path if File.exist?(flavor_path) end nil end |
#resolve_template(template_name) ⇒ Object
171 172 173 174 175 176 177 |
# File 'lib/metanorma/html/theme.rb', line 171 def resolve_template(template_name) if theme_templates_dir flavor_path = File.join(theme_templates_dir, template_name) return flavor_path if File.exist?(flavor_path) end File.join(TEMPLATES_ROOT, template_name) end |
#theme_assets_dir ⇒ Object
157 158 159 160 161 162 |
# File 'lib/metanorma/html/theme.rb', line 157 def theme_assets_dir return nil unless theme_dir dir = File.join(theme_dir, "assets") File.directory?(dir) ? dir : nil end |
#theme_css_path ⇒ Object
164 165 166 167 168 169 |
# File 'lib/metanorma/html/theme.rb', line 164 def theme_css_path return nil unless theme_dir path = File.join(theme_dir, "custom.css") File.exist?(path) ? path : nil end |
#theme_templates_dir ⇒ Object
150 151 152 153 154 155 |
# File 'lib/metanorma/html/theme.rb', line 150 def theme_templates_dir return nil unless theme_dir dir = File.join(theme_dir, "templates") File.directory?(dir) ? dir : nil end |
#to_css ⇒ Object
244 245 246 |
# File 'lib/metanorma/html/theme.rb', line 244 def to_css to_css_root + to_css_extras end |
#to_css_extras ⇒ Object
236 237 238 239 240 241 242 |
# File 'lib/metanorma/html/theme.rb', line 236 def to_css_extras css = "" css += ".title-section::before { content: \"\"; position: absolute; inset: 0; pointer-events: none; #{cover_before_bg} }\n" if cover_before_bg css += ".title-section::after { #{cover_after_bg} }\n" if cover_after_bg css += extra_css.to_s if extra_css css end |
#to_css_root ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/metanorma/html/theme.rb', line 187 def to_css_root root = <<~CSS :root { --mn-primary: #{primary}; --mn-accent: #{accent}; --mn-gradient: #{gradient}; --mn-primary-light: #{primary_light}; --mn-accent-light: #{accent_light}; --mn-primary-dark: #{primary_dark}; --color-text: #{text_color}; --color-text-light: #{text_light}; --color-text-muted: #{text_muted}; --color-bg: #{bg}; --color-bg-light: #{bg_light}; --color-border: #{border}; --color-sidebar-bg: #{}; --font-body: #{font_body}; --font-sans: #{font_sans}; --font-mono: #{font_mono}; --content-max-width: #{content_max_width}; --sidebar-width: #{}; --header-height: #{header_height}; --radius-sm: #{radius_sm}; --radius-md: #{radius_md}; --shadow-sm: #{shadow_sm}; --shadow-md: #{shadow_md}; --note-bg: #{note_bg}; --note-border: #{note_border}; --note-color: #{note_color}; --example-bg: #{example_bg}; --example-border: #{example_border}; --example-color: #{example_color}; --admonition-bg: #{admonition_bg}; --admonition-border: #{admonition_border}; --admonition-color: #{admonition_color}; CSS root += " --mn-accent-deep: #{accent_deep};\n" if accent_deep root += " --mn-warm: #{warm};\n" if warm root += " --mn-warm-light: #{warm_light};\n" if warm_light root += " --mn-header-bg: #{header_background};\n" if header_background root += " --mn-cover-bg: #{cover_background};\n" if cover_background root += " --mn-progress-color: #{};\n" if root += " --mn-footer-border: #{};\n" if root += " --mn-cover-separator: #{cover_separator_color};\n" if cover_separator_color root += " }\n" root += generate_dark_mode_block if dark_bg root end |