foalfetch/app/lib/story_renderer.rb

37 lines
924 B
Ruby
Raw Normal View History

2024-07-30 15:53:39 +02:00
# frozen_string_literal: true
require 'redcarpet/render_strip'
class StoryRenderer
def initialize(story)
@story = story
end
def txt
2024-07-30 15:53:39 +02:00
markdown = Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
separator = '//-------------------------------------------------------//'
# Title and author
text = "#{separator}\n".dup
text += "#{@story.title.center(separator.length, ' ')}\n"
text += "#{"-by #{@story.author.name}-".center(separator.length, ' ')}\n"
text += "#{separator}\n"
# Chapters
@story.chapters.each do |chapter|
text += "#{separator}\n"
text += "#{chapter.title.center(separator.length, ' ')}\n"
text += "#{separator}\n"
text += "#{markdown.render chapter.body}\n" # FIXME: My Markdown still has the title at the top for no reason.
end
text
end
def html
end
def epub
Ebook::EpubGenerator.new(@story).generate
2024-07-30 15:53:39 +02:00
end
end