Improve config for CSS classes
This commit is contained in:
parent
d554af13bf
commit
c6f7ab5fbf
6 changed files with 60 additions and 26 deletions
2
Rakefile
2
Rakefile
|
@ -68,6 +68,6 @@ namespace :yard do
|
||||||
|
|
||||||
coverage = m[1].to_f.round(2)
|
coverage = m[1].to_f.round(2)
|
||||||
puts "Documentation coverage: #{coverage}%"
|
puts "Documentation coverage: #{coverage}%"
|
||||||
raise 'Not fully documented!' if coverage < 38.32
|
raise 'Not fully documented!' if coverage < 38
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,14 +29,14 @@ paths: &paths
|
||||||
images_prefix: '/assets/images'
|
images_prefix: '/assets/images'
|
||||||
|
|
||||||
css_classes: &css_classes
|
css_classes: &css_classes
|
||||||
css_class_annotation: 'nice-annotation'
|
annotation: 'nice-annotation'
|
||||||
css_class_blockquote_figure: 'nice-blockquote'
|
blockquote_figure: 'nice-blockquote'
|
||||||
css_class_figure_self: 'nice-figure'
|
figure_self: 'nice-figure'
|
||||||
css_class_figure_wrap: 'd-flex justify-content-center'
|
figure_wrap: 'd-flex justify-content-center'
|
||||||
css_class_figures_left: 'col-xl-6'
|
figures_left: 'col-xl-6'
|
||||||
css_class_figures_right: 'col-xl-6'
|
figures_right: 'col-xl-6'
|
||||||
css_class_figures_wrap: 'row'
|
figures_wrap: 'row'
|
||||||
css_class_iframe_wrap: 'ratio ratio-16x9'
|
iframe_wrap: 'ratio ratio-16x9'
|
||||||
|
|
||||||
############
|
############
|
||||||
# Profiles #
|
# Profiles #
|
||||||
|
@ -58,14 +58,14 @@ gemini:
|
||||||
|
|
||||||
http:
|
http:
|
||||||
<<: *paths
|
<<: *paths
|
||||||
<<: *css_classes
|
|
||||||
format: html
|
format: html
|
||||||
relative_urls: true
|
relative_urls: true
|
||||||
chapter_anchor_prefix: 'chapter'
|
chapter_anchor_prefix: 'chapter'
|
||||||
|
css_classes: *css_classes
|
||||||
|
|
||||||
rss:
|
rss:
|
||||||
<<: *paths
|
<<: *paths
|
||||||
<<: *css_classes
|
|
||||||
format: html
|
format: html
|
||||||
relative_urls: false
|
relative_urls: false
|
||||||
base_url: 'https://example.com'
|
base_url: 'https://example.com'
|
||||||
|
css_classes: *css_classes
|
||||||
|
|
|
@ -10,10 +10,12 @@ require 'yaml'
|
||||||
|
|
||||||
require 'addressable'
|
require 'addressable'
|
||||||
|
|
||||||
require_relative 'repubmark/config'
|
|
||||||
require_relative 'repubmark/highlight'
|
require_relative 'repubmark/highlight'
|
||||||
require_relative 'repubmark/titled_ref'
|
require_relative 'repubmark/titled_ref'
|
||||||
|
|
||||||
|
require_relative 'repubmark/config'
|
||||||
|
require_relative 'repubmark/config/css_classes'
|
||||||
|
|
||||||
require_relative 'repubmark/elems/base'
|
require_relative 'repubmark/elems/base'
|
||||||
|
|
||||||
# Top-level element
|
# Top-level element
|
||||||
|
|
|
@ -5,16 +5,7 @@ module Repubmark
|
||||||
OPTIONAL_KEYS = %i[
|
OPTIONAL_KEYS = %i[
|
||||||
base_url
|
base_url
|
||||||
chapter_anchor_prefix
|
chapter_anchor_prefix
|
||||||
css_class_annotation
|
css_classes
|
||||||
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
|
|
||||||
current_path
|
current_path
|
||||||
images_prefix
|
images_prefix
|
||||||
relative_urls
|
relative_urls
|
||||||
|
@ -41,6 +32,10 @@ module Repubmark
|
||||||
OPTIONAL_KEYS.include?(key) ? @kwargs[key] : @kwargs.fetch(key)
|
OPTIONAL_KEYS.include?(key) ? @kwargs[key] : @kwargs.fetch(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def css_classes
|
||||||
|
@css_classes ||= CSSClasses.new(**(self[:css_classes] || {}))
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def format=(format)
|
def format=(format)
|
||||||
|
|
37
lib/repubmark/config/css_classes.rb
Normal file
37
lib/repubmark/config/css_classes.rb
Normal 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
|
|
@ -90,11 +90,11 @@ module Repubmark
|
||||||
.freeze
|
.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_class(key)
|
def html_class(*keys)
|
||||||
if (value = config[:"css_class_#{key}"])
|
if (value = config.css_classes[*keys]).empty?
|
||||||
%( class="#{value}").freeze
|
|
||||||
else
|
|
||||||
''
|
''
|
||||||
|
else
|
||||||
|
%( class="#{value}").freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue