foalfetch/app/lib/story_renderer.rb
2024-07-30 09:53:46 -04:00

35 lines
879 B
Ruby

# frozen_string_literal: true
require 'redcarpet/render_strip'
class StoryRenderer
def initialize(story)
@story = story
end
def text
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
end
end