2022-12-25 22:32:34 +01:00
|
|
|
require "redcarpet"
|
|
|
|
|
2022-11-21 11:10:04 +01:00
|
|
|
module ApplicationHelper
|
2023-01-11 19:52:58 +01:00
|
|
|
|
2023-01-11 20:14:36 +01:00
|
|
|
# different template according to the amount of text
|
|
|
|
def render_story(story)
|
|
|
|
return "" unless story
|
|
|
|
text_length = story.text.length
|
|
|
|
template = "text"
|
2023-01-12 13:34:00 +01:00
|
|
|
template = "half" if text_length < 400
|
|
|
|
template = "pic" if text_length < 200
|
2023-01-11 20:14:36 +01:00
|
|
|
render partial: "stories/#{template}" , locals: {story: story}
|
|
|
|
end
|
|
|
|
|
2023-01-11 19:52:58 +01:00
|
|
|
def prose_classes
|
|
|
|
classes = "prose lg:prose-lg "
|
|
|
|
classes += "prose-headings:text-inherit "
|
|
|
|
{ class: classes }
|
|
|
|
end
|
|
|
|
|
2022-12-25 22:32:34 +01:00
|
|
|
def renderer
|
|
|
|
options = {hard_wrap: true , autolink: true, no_intra_emphasis: true ,
|
|
|
|
safe_links_only: true, no_styles: true ,
|
|
|
|
link_attributes: { target: '_blank' }}
|
|
|
|
html = Redcarpet::Render::HTML.new(options)
|
|
|
|
Redcarpet::Markdown.new(html, options)
|
|
|
|
end
|
|
|
|
|
2022-12-25 13:13:11 +01:00
|
|
|
def markdown(text)
|
2023-01-03 18:38:04 +01:00
|
|
|
return "" if text.blank?
|
2022-12-25 22:32:34 +01:00
|
|
|
text = text.text unless text.is_a?(String)
|
|
|
|
return "" if text.blank?
|
|
|
|
self.renderer.render(text).html_safe
|
2022-12-25 13:13:11 +01:00
|
|
|
end
|
2022-12-25 22:32:34 +01:00
|
|
|
|
2023-01-12 13:34:00 +01:00
|
|
|
def shorten(text , to = 100)
|
|
|
|
return "" if text.blank?
|
|
|
|
"#{text[0..to]} . . . ".html_safe
|
|
|
|
end
|
2022-12-20 23:34:11 +01:00
|
|
|
def main_app
|
|
|
|
Rails.application.routes.url_helpers
|
|
|
|
end
|
2023-01-03 18:38:04 +01:00
|
|
|
|
2023-01-10 21:23:56 +01:00
|
|
|
def button_classes
|
|
|
|
"mr-3 inline-block rounded-lg px-3 py-2 text-md font-medium border border-gray-500"
|
|
|
|
end
|
|
|
|
|
2023-01-12 13:34:00 +01:00
|
|
|
def rows( text )
|
|
|
|
return 5 if text.blank?
|
|
|
|
text = text.text unless text.is_a?(String)
|
|
|
|
return 5 if text.blank?
|
|
|
|
rows = (text.length / 60).to_i
|
|
|
|
return 5 if rows < 5
|
|
|
|
rows
|
|
|
|
end
|
|
|
|
|
2022-11-21 11:10:04 +01:00
|
|
|
end
|