-
-
Save zernie/0888f1694340b9a86a9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArticlePresenter | |
DEFAULT_OFFSET = 100 | |
READ_MORE_REGEX = /<!--more-->/ | |
def content(should_truncate) | |
content = article.content.clone | |
index = content.index(READ_MORE_REGEX) || DEFAULT_OFFSET | |
if should_truncate | |
content = content.truncate(index) | |
button = read_more_button(article) | |
else | |
content.sub! READ_MORE_REGEX, '' | |
end | |
html = MarkdownService.instance.render(content) + button.presence | |
content_tag :div, html, class: 'ui justified text container' | |
end | |
private | |
def read_more_button(article) | |
link_to 'Read more', article, class: 'ui green basic button' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment