49 lines
1.0 KiB
Ruby
49 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Repubmark
|
|
class Config
|
|
OPTIONAL_KEYS = %i[
|
|
base_url
|
|
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
|
|
current_path
|
|
images_prefix
|
|
relative_urls
|
|
].freeze
|
|
|
|
attr_reader :format
|
|
|
|
def self.load_file(filename)
|
|
new(**YAML.safe_load_file(filename).transform_keys(&:to_sym))
|
|
end
|
|
|
|
def initialize(format:, **kwargs)
|
|
self.format = format
|
|
raise unless (kwargs.keys - OPTIONAL_KEYS).empty?
|
|
|
|
@kwargs = kwargs.freeze
|
|
end
|
|
|
|
def [](key)
|
|
OPTIONAL_KEYS.include?(key) ? @kwargs[key] : @kwargs.fetch(key)
|
|
end
|
|
|
|
private
|
|
|
|
def format=(format)
|
|
format = format.to_sym if format.instance_of? String
|
|
raise 'Invalid format' unless FORMATS.include? format
|
|
|
|
@format = format
|
|
end
|
|
end
|
|
end
|