Improve config for CSS classes

This commit is contained in:
Alex Kotov 2024-10-18 20:22:37 +04:00
parent d554af13bf
commit c6f7ab5fbf
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
6 changed files with 60 additions and 26 deletions

View file

@ -68,6 +68,6 @@ namespace :yard do
coverage = m[1].to_f.round(2)
puts "Documentation coverage: #{coverage}%"
raise 'Not fully documented!' if coverage < 38.32
raise 'Not fully documented!' if coverage < 38
end
end

View file

@ -29,14 +29,14 @@ paths: &paths
images_prefix: '/assets/images'
css_classes: &css_classes
css_class_annotation: 'nice-annotation'
css_class_blockquote_figure: 'nice-blockquote'
css_class_figure_self: 'nice-figure'
css_class_figure_wrap: 'd-flex justify-content-center'
css_class_figures_left: 'col-xl-6'
css_class_figures_right: 'col-xl-6'
css_class_figures_wrap: 'row'
css_class_iframe_wrap: 'ratio ratio-16x9'
annotation: 'nice-annotation'
blockquote_figure: 'nice-blockquote'
figure_self: 'nice-figure'
figure_wrap: 'd-flex justify-content-center'
figures_left: 'col-xl-6'
figures_right: 'col-xl-6'
figures_wrap: 'row'
iframe_wrap: 'ratio ratio-16x9'
############
# Profiles #
@ -58,14 +58,14 @@ gemini:
http:
<<: *paths
<<: *css_classes
format: html
relative_urls: true
chapter_anchor_prefix: 'chapter'
css_classes: *css_classes
rss:
<<: *paths
<<: *css_classes
format: html
relative_urls: false
base_url: 'https://example.com'
css_classes: *css_classes

View file

@ -10,10 +10,12 @@ require 'yaml'
require 'addressable'
require_relative 'repubmark/config'
require_relative 'repubmark/highlight'
require_relative 'repubmark/titled_ref'
require_relative 'repubmark/config'
require_relative 'repubmark/config/css_classes'
require_relative 'repubmark/elems/base'
# Top-level element

View file

@ -5,16 +5,7 @@ module Repubmark
OPTIONAL_KEYS = %i[
base_url
chapter_anchor_prefix
css_class_annotation
css_class_blockquote_figure
css_class_blockquote_blockquote
css_class_blockquote_figcaption
css_class_figure_self
css_class_figure_wrap
css_class_figures_left
css_class_figures_right
css_class_figures_wrap
css_class_iframe_wrap
css_classes
current_path
images_prefix
relative_urls
@ -41,6 +32,10 @@ module Repubmark
OPTIONAL_KEYS.include?(key) ? @kwargs[key] : @kwargs.fetch(key)
end
def css_classes
@css_classes ||= CSSClasses.new(**(self[:css_classes] || {}))
end
private
def format=(format)

View file

@ -0,0 +1,37 @@
# frozen_string_literal: true
module Repubmark
class Config
class CSSClasses
KEYS = %i[
annotation
blockquote_figure
blockquote_blockquote
blockquote_figcaption
figure_self
figure_wrap
figures_left
figures_right
figures_wrap
iframe_wrap
].freeze
def initialize(**kwargs)
@kwargs =
kwargs
.transform_keys!(&:to_sym)
.transform_values! { |val| String(val).strip.freeze }
.freeze
.each_key { |key| raise 'Invalid key' unless KEYS.include? key }
end
def [](*keys)
keys
.each { |key| raise 'Invalid key' unless KEYS.include? key }
.filter_map { |key| @kwargs[key] }
.join(' ')
.freeze
end
end
end
end

View file

@ -90,11 +90,11 @@ module Repubmark
.freeze
end
def html_class(key)
if (value = config[:"css_class_#{key}"])
%( class="#{value}").freeze
else
def html_class(*keys)
if (value = config.css_classes[*keys]).empty?
''
else
%( class="#{value}").freeze
end
end