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
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-12-15 17:51:16 +0300
committerDouwe Maan <douwe@gitlab.com>2015-12-15 17:51:16 +0300
commit7781bda9bd82997f4a03de4cf911b1156ceb2cde (patch)
treea632a12b295694232205e2190f784f9bb79235ee /app
parent9451db3819ae45734c4343e55a74d347cdacf70d (diff)
Move Markdown/reference logic from Gitlab::Markdown to Banzai
Diffstat (limited to 'app')
-rw-r--r--app/helpers/gitlab_markdown_helper.rb6
-rw-r--r--app/helpers/issues_helper.rb2
-rw-r--r--app/helpers/labels_helper.rb2
-rw-r--r--app/models/concerns/mentionable.rb16
-rw-r--r--app/models/concerns/participable.rb29
-rw-r--r--app/models/issue.rb2
-rw-r--r--app/models/note.rb4
7 files changed, 31 insertions, 30 deletions
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb
index 5004e02ea0b..a0cf3dc0843 100644
--- a/app/helpers/gitlab_markdown_helper.rb
+++ b/app/helpers/gitlab_markdown_helper.rb
@@ -20,7 +20,7 @@ module GitlabMarkdownHelper
end
user = current_user if defined?(current_user)
- gfm_body = Gitlab::Markdown.render(escaped_body, project: @project, current_user: user, pipeline: :single_line)
+ gfm_body = Banzai.render(escaped_body, project: @project, current_user: user, pipeline: :single_line)
fragment = Nokogiri::HTML::DocumentFragment.parse(gfm_body)
if fragment.children.size == 1 && fragment.children[0].name == 'a'
@@ -50,7 +50,7 @@ module GitlabMarkdownHelper
context[:project] ||= @project
- html = Gitlab::Markdown.render(text, context)
+ html = Banzai.render(text, context)
context.merge!(
current_user: (current_user if defined?(current_user)),
@@ -61,7 +61,7 @@ module GitlabMarkdownHelper
ref: @ref
)
- Gitlab::Markdown.post_process(html, context)
+ Banzai.post_process(html, context)
end
def asciidoc(text)
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index e66b9c628c7..21149a15b69 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -121,6 +121,6 @@ module IssuesHelper
end
end
- # Required for Gitlab::Markdown::IssueReferenceFilter
+ # Required for Banzai::IssueReferenceFilter
module_function :url_for_issue
end
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb
index 795fb439f25..97e8baa179a 100644
--- a/app/helpers/labels_helper.rb
+++ b/app/helpers/labels_helper.rb
@@ -107,6 +107,6 @@ module LabelsHelper
options_from_collection_for_select(grouped_labels, 'name', 'title', params[:label_name])
end
- # Required for Gitlab::Markdown::LabelReferenceFilter
+ # Required for Banzai::LabelReferenceFilter
module_function :render_colored_label, :text_color_for_bg, :escape_once
end
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb
index d2ea9ab7313..d4e3099453d 100644
--- a/app/models/concerns/mentionable.rb
+++ b/app/models/concerns/mentionable.rb
@@ -23,7 +23,7 @@ module Mentionable
included do
if self < Participable
- participant ->(current_user) { mentioned_users(current_user, load_lazy_references: false) }
+ participant ->(current_user) { mentioned_users(current_user) }
end
end
@@ -43,9 +43,9 @@ module Mentionable
self
end
- def all_references(current_user = self.author, text = nil, load_lazy_references: true)
- ext = Gitlab::ReferenceExtractor.new(self.project, current_user, load_lazy_references: load_lazy_references)
-
+ def all_references(current_user = self.author, text = nil)
+ ext = Gitlab::ReferenceExtractor.new(self.project, current_user)
+
if text
ext.analyze(text)
else
@@ -59,13 +59,13 @@ module Mentionable
ext
end
- def mentioned_users(current_user = nil, load_lazy_references: true)
- all_references(current_user, load_lazy_references: load_lazy_references).users
+ def mentioned_users(current_user = nil)
+ all_references(current_user).users
end
# Extract GFM references to other Mentionables from this Mentionable. Always excludes its #local_reference.
- def referenced_mentionables(current_user = self.author, text = nil, load_lazy_references: true)
- refs = all_references(current_user, text, load_lazy_references: load_lazy_references)
+ def referenced_mentionables(current_user = self.author, text = nil)
+ refs = all_references(current_user, text)
refs = (refs.issues + refs.merge_requests + refs.commits)
# We're using this method instead of Array diffing because that requires
diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb
index 85367f89f4f..808d80b0530 100644
--- a/app/models/concerns/participable.rb
+++ b/app/models/concerns/participable.rb
@@ -38,20 +38,21 @@ module Participable
# Be aware that this method makes a lot of sql queries.
# Save result into variable if you are going to reuse it inside same request
def participants(current_user = self.author, load_lazy_references: true)
- participants = self.class.participant_attrs.flat_map do |attr|
- value =
- if attr.respond_to?(:call)
- instance_exec(current_user, &attr)
- else
- send(attr)
- end
+ participants =
+ Gitlab::ReferenceExtractor.lazily do
+ self.class.participant_attrs.flat_map do |attr|
+ value =
+ if attr.respond_to?(:call)
+ instance_exec(current_user, &attr)
+ else
+ send(attr)
+ end
- participants_for(value, current_user)
- end.compact.uniq
-
- if load_lazy_references
- participants = Gitlab::Markdown::ReferenceFilter::LazyReference.load(participants).uniq
+ participants_for(value, current_user)
+ end.compact.uniq
+ end
+ unless Gitlab::ReferenceExtractor.lazy?
participants.select! do |user|
user.can?(:read_project, project)
end
@@ -64,12 +65,12 @@ module Participable
def participants_for(value, current_user = nil)
case value
- when User, Gitlab::Markdown::ReferenceFilter::LazyReference
+ when User, Banzai::LazyReference
[value]
when Enumerable, ActiveRecord::Relation
value.flat_map { |v| participants_for(v, current_user) }
when Participable
- value.participants(current_user, load_lazy_references: false)
+ value.participants(current_user)
end
end
end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index e04035b3af8..9f4f4923e58 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -88,7 +88,7 @@ class Issue < ActiveRecord::Base
note.all_references(load_lazy_references: false).merge_requests
end.uniq
- Gitlab::Markdown::ReferenceFilter::LazyReference.load(references).uniq.sort_by(&:iid)
+ Banzai::LazyReference.load(references).uniq.sort_by(&:iid)
end
# Reset issue events cache
diff --git a/app/models/note.rb b/app/models/note.rb
index 04053ccc61e..ea69ef65fcb 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -373,11 +373,11 @@ class Note < ActiveRecord::Base
end
def contains_emoji_only?
- note =~ /\A#{Gitlab::Markdown::EmojiFilter.emoji_pattern}\s?\Z/
+ note =~ /\A#{Banzai::EmojiFilter.emoji_pattern}\s?\Z/
end
def award_emoji_name
- original_name = note.match(Gitlab::Markdown::EmojiFilter.emoji_pattern)[1]
+ original_name = note.match(Banzai::EmojiFilter.emoji_pattern)[1]
AwardEmoji.normilize_emoji_name(original_name)
end
end