Skip to content

Commit 5189f76

Browse files
salzigJoschkaSchulz
authored andcommitted
refa: extract markdown helper into module
1 parent 9b3d52b commit 5189f76

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

app/helpers/application_helper.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ def icon(type)
7070
tag.link rel: type, href: path
7171
end
7272

73-
def markdown(content)
74-
return nil unless content
75-
76-
content = markdown_parser.render(content).html_safe
77-
tag.div(content, class: :markdown)
78-
end
79-
8073
def fa_icon_map
8174
@fa_icon_map ||= ActiveSupport::HashWithIndifferentAccess.new { |_hash, key| key }.merge(
8275
'events' => 'calendar',
@@ -124,12 +117,4 @@ def asset_file_exists?(logical_path)
124117
Rails.root.join('public/images', logical_path)
125118
].any?(&:exist?)
126119
end
127-
128-
def markdown_parser
129-
@markdown_parser ||= Redcarpet::Markdown.new markdown_renderer, autolink: true, space_after_headers: true
130-
end
131-
132-
def markdown_renderer
133-
@markdown_renderer ||= Redcarpet::Render::Safe.new(no_styles: true, filter_html: true, link_attributes: { rel: 'nofollow noopener noreferrer ugc' })
134-
end
135120
end

app/helpers/markdown_helper.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
module MarkdownHelper
4+
def markdown(content)
5+
return nil unless content
6+
7+
content = markdown_parser.render(content).html_safe # rubocop:disable Rails/OutputSafety
8+
tag.div(content, class: :markdown)
9+
end
10+
11+
private
12+
13+
def markdown_parser
14+
@markdown_parser ||= Redcarpet::Markdown.new markdown_renderer, autolink: true, space_after_headers: true
15+
end
16+
17+
def markdown_renderer
18+
@markdown_renderer ||= Redcarpet::Render::Safe.new(no_styles: true, filter_html: true, link_attributes: { rel: 'nofollow noopener noreferrer ugc' })
19+
end
20+
end

0 commit comments

Comments
 (0)