Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-11-17 12:40:29 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-11-17 12:40:29 +0300
commit5f239093623afcbb0cbc32c385fb2a5733f7eccb (patch)
treeec0c4cd25255dc86e7d6d621b391b0f757f43e2f /app/helpers/gitlab_markdown_helper.rb
parentbfbfa3b5f050405180b2024ff6a790bb71915606 (diff)
Remove code duplication in gitlab_markdown_helper.rb
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/helpers/gitlab_markdown_helper.rb')
-rw-r--r--app/helpers/gitlab_markdown_helper.rb52
1 files changed, 24 insertions, 28 deletions
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb
index 65813482120..a0f6b80e9eb 100644
--- a/app/helpers/gitlab_markdown_helper.rb
+++ b/app/helpers/gitlab_markdown_helper.rb
@@ -46,39 +46,13 @@ module GitlabMarkdownHelper
end
def markdown(text, context = {})
- return "" unless text.present?
-
- context.reverse_merge!(
- path: @path,
- pipeline: :default,
- project: @project,
- project_wiki: @project_wiki,
- ref: @ref
- )
-
- user = current_user if defined?(current_user)
-
- html = Gitlab::Markdown.render(text, context)
- Gitlab::Markdown.post_process(html, pipeline: context[:pipeline], project: @project, user: user)
+ process_markdown(text, options)
end
# TODO (rspeicher): Remove all usages of this helper and just call `markdown`
# with a custom pipeline depending on the content being rendered
def gfm(text, options = {})
- return "" unless text.present?
-
- options.reverse_merge!(
- path: @path,
- pipeline: :default,
- project: @project,
- project_wiki: @project_wiki,
- ref: @ref
- )
-
- user = current_user if defined?(current_user)
-
- html = Gitlab::Markdown.gfm(text, options)
- Gitlab::Markdown.post_process(html, pipeline: options[:pipeline], project: @project, user: user)
+ process_markdown(text, options, :gfm)
end
def asciidoc(text)
@@ -204,4 +178,26 @@ module GitlabMarkdownHelper
''
end
end
+
+ def process_markdown(text, options, method = :markdown)
+ return "" unless text.present?
+
+ options.reverse_merge!(
+ path: @path,
+ pipeline: :default,
+ project: @project,
+ project_wiki: @project_wiki,
+ ref: @ref
+ )
+
+ user = current_user if defined?(current_user)
+
+ html = if method == :gfm
+ Gitlab::Markdown.gfm(text, options)
+ else
+ Gitlab::Markdown.render(text, options)
+ end
+
+ Gitlab::Markdown.post_process(html, pipeline: options[:pipeline], project: @project, user: user)
+ end
end