Load config from file

This commit is contained in:
Alex Kotov 2024-02-24 09:34:05 +04:00
parent 8a6d2ca90e
commit 90dae92c30
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
7 changed files with 61 additions and 25 deletions

6
config/gemini.yml Normal file
View file

@ -0,0 +1,6 @@
---
format: gemtext
base_url: 'gemini://causa-arcana.com'
current_path: '/xx/blog/xxxx/xx/xx/xxxxx.xxx'
relative_urls: true

15
config/http.yml Normal file
View file

@ -0,0 +1,15 @@
---
format: html
base_url: 'https://causa-arcana.com'
current_path: '/xx/blog/xxxx/xx/xx/xxxxx.xxx'
relative_urls: true
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'

15
config/rss.yml Normal file
View file

@ -0,0 +1,15 @@
---
format: html
base_url: 'https://causa-arcana.com'
current_path: '/xx/blog/xxxx/xx/xx/xxxxx.xxx'
relative_urls: false
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'

2
config/word_count.yml Normal file
View file

@ -0,0 +1,2 @@
---
format: word_count

View file

@ -8,35 +8,16 @@ require 'bundler/setup'
require 'repubmark'
format = String(ARGV[0]).to_sym
unless Repubmark::FORMATS.include? format
raise "Invalid format: #{format.inspect}"
end
template = $stdin.read.freeze
config = Repubmark::Config.new(
base_url: 'https://causa-arcana.com',
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',
current_path: '/xx/blog/xxxx/xx/xx/xxx.xxx',
relative_urls: false,
)
config = Repubmark::Config.load_file String ARGV[0]
$article = Repubmark::Elems::Article.new config
template = $stdin.read.freeze
context = BasicObject.new
def context.article = $article
context.instance_eval template, __FILE__, __LINE__
output =
case format
case config.format
when :word_count then $article.word_count
when :html then $article.to_html
when :gemtext then $article.to_gemtext

View file

@ -5,6 +5,7 @@ require 'forwardable'
require 'open3'
require 'pathname'
require 'uri'
require 'yaml'
require_relative 'repubmark/config'
require_relative 'repubmark/highlight'
@ -56,5 +57,5 @@ require_relative 'repubmark/elems/text'
require_relative 'repubmark/elems/link'
module Repubmark
FORMATS = %i[gemtext html].freeze
FORMATS = %i[gemtext html word_count].freeze
end

View file

@ -18,8 +18,15 @@ module Repubmark
relative_urls
].freeze
def initialize(**kwargs)
raise unless (kwargs.keys.sort - OPTIONAL_KEYS).empty?
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
@ -27,5 +34,14 @@ module Repubmark
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