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