Module: ParsingHelper
- Defined in:
- app/helpers/parsing_helper.rb
Instance Method Summary collapse
- #parse_figure_links(post, string) ⇒ Object
-
#parse_post_links(string) ⇒ String
Parse fragments like [post 123](link text).
-
#prepare_comment_text(comment) ⇒ String
Prepare comment text for views.
-
#prepare_post_text(post) ⇒ String
Prepare post text for views.
Instance Method Details
#parse_figure_links(post, string) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/parsing_helper.rb', line 39 def parse_figure_links(post, string) pattern = Figure::LINK_PATTERN string.gsub pattern do |chunk| match = pattern.match chunk figure = post.figures.find_by(slug: match[:id]) if figure.is_a? Figure image = image_tag(figure.image.big.url, alt: figure.text_for_alt) caption = figure.caption.blank? ? '' : "<figcaption>#{figure.caption}</figcaption>" "<figure>#{image}#{caption}</figure>\n" else '<figure><span class="not-found">figure ' + match[:id] + "</span></figure>\n" end end end |
#parse_post_links(string) ⇒ String
Parse fragments like [post 123](link text)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/parsing_helper.rb', line 24 def parse_post_links(string) pattern = Post::LINK_PATTERN string.gsub pattern do |chunk| match = pattern.match chunk post = Post.visible.find_by id: match[:id] if post.is_a? Post link_text = match[:text].blank? ? post.title : match[:text] link_tag = link_to(link_text, post, title: post.title) "<cite>#{link_tag}</cite>" else '<span class="not-found">post ' + match[:id] + '</span>' end end end |
#prepare_comment_text(comment) ⇒ String
Prepare comment text for views
15 16 17 18 |
# File 'app/helpers/parsing_helper.rb', line 15 def prepare_comment_text(comment) simple_format comment.body # raw comment.body.split("\n").map(&:squish).reject(&:blank?).map { |s| parse_common_string s }.join end |
#prepare_post_text(post) ⇒ String
Prepare post text for views
6 7 8 9 |
# File 'app/helpers/parsing_helper.rb', line 6 def prepare_post_text(post) entry = post.entry raw(entry.nil? ? post.body : entry.body) end |