mirror of
https://github.com/Neetpone/foalfetch.git
synced 2025-02-08 18:06:43 +01:00
35 lines
879 B
Ruby
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
|