Skip to content

Instantly share code, notes, and snippets.

@zernie
Last active February 7, 2016 13:31
Show Gist options
  • Save zernie/0888f1694340b9a86a9d to your computer and use it in GitHub Desktop.
Save zernie/0888f1694340b9a86a9d to your computer and use it in GitHub Desktop.
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