Improve eval, remove globals
This commit is contained in:
parent
1a233ac6aa
commit
d66fc6eda1
|
@ -10,12 +10,12 @@ require 'repubmark'
|
||||||
|
|
||||||
FORMATS = %w[word_count html gemtext].freeze
|
FORMATS = %w[word_count html gemtext].freeze
|
||||||
|
|
||||||
$format = String(ARGV[0]).freeze
|
format = String(ARGV[0]).freeze
|
||||||
raise "Invalid format: #{$format.inspect}" unless FORMATS.include? $format
|
raise "Invalid format: #{format.inspect}" unless FORMATS.include? format
|
||||||
|
|
||||||
$template = $stdin.read.freeze
|
template = $stdin.read.freeze
|
||||||
|
|
||||||
$config = Repubmark::Config.new(
|
config = Repubmark::Config.new(
|
||||||
base_url: 'https://causa-arcana.com',
|
base_url: 'https://causa-arcana.com',
|
||||||
css_class_annotation: 'nice-annotation',
|
css_class_annotation: 'nice-annotation',
|
||||||
css_class_blockquote_figure: 'nice-blockquote',
|
css_class_blockquote_figure: 'nice-blockquote',
|
||||||
|
@ -29,18 +29,17 @@ $config = Repubmark::Config.new(
|
||||||
relative_urls: false,
|
relative_urls: false,
|
||||||
)
|
)
|
||||||
|
|
||||||
$article = Repubmark::Elems::Article.new $config
|
$article = Repubmark::Elems::Article.new config
|
||||||
$article.tap do |article| # rubocop:disable Lint/UnusedBlockArgument
|
|
||||||
eval $template # rubocop:disable Security/Eval
|
|
||||||
end
|
|
||||||
|
|
||||||
case $format
|
context = BasicObject.new
|
||||||
when 'word_count'
|
def context.article = $article
|
||||||
puts $article.word_count
|
context.instance_eval template, __FILE__, __LINE__
|
||||||
when 'html'
|
|
||||||
puts $article.to_html.strip
|
output =
|
||||||
when 'gemtext'
|
case format
|
||||||
puts $article.to_gemtext.strip
|
when 'word_count' then $article.word_count
|
||||||
else
|
when 'html' then $article.to_html
|
||||||
raise 'Unknown blog format'
|
when 'gemtext' then $article.to_gemtext
|
||||||
end
|
end.to_s.strip
|
||||||
|
|
||||||
|
puts output unless output.empty?
|
||||||
|
|
Loading…
Reference in New Issue