fic_tracker/lib/fic_tracker/renderers.rb

30 lines
695 B
Ruby

# frozen_string_literal: true
module FicTracker::Renderers
autoload :Epub, 'fic_tracker/renderers/epub'
autoload :HTML, 'fic_tracker/renderers/html'
autoload :Markdown, 'fic_tracker/renderers/markdown'
def self.render(type, story, **attrs)
klass = case type
when :Markdown, :markdown, :md
Markdown
when :HTML, :html
HTML
when :Epub, :epub
Epub
end
stringio = nil
unless attrs[:io]
require 'stringio'
attrs[:io] = StringIO.new
stringio = true
end
result = klass.new(story, **attrs).render
return result unless stringio
attrs[:io].string
end
end