2015-12-15 14:51:16 +00:00
|
|
|
module Banzai
|
|
|
|
module Filter
|
2015-04-14 22:34:01 +00:00
|
|
|
# HTML filter that replaces snippet references with links. References to
|
2015-04-03 00:46:43 +00:00
|
|
|
# snippets that do not exist are ignored.
|
|
|
|
#
|
2015-04-14 22:34:01 +00:00
|
|
|
# This filter supports cross-project references.
|
2015-11-16 20:56:28 +00:00
|
|
|
class SnippetReferenceFilter < AbstractReferenceFilter
|
2016-05-26 11:16:43 +00:00
|
|
|
self.reference_type = :snippet
|
|
|
|
|
2015-11-16 20:56:28 +00:00
|
|
|
def self.object_class
|
|
|
|
Snippet
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
|
|
|
|
2015-11-16 20:56:28 +00:00
|
|
|
def find_object(project, id)
|
2018-04-12 09:37:01 +00:00
|
|
|
return unless project.is_a?(Project)
|
|
|
|
|
2015-11-16 20:56:28 +00:00
|
|
|
project.snippets.find_by(id: id)
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
|
|
|
|
2015-11-16 20:56:28 +00:00
|
|
|
def url_for_object(snippet, project)
|
2016-03-24 16:00:26 +00:00
|
|
|
h = Gitlab::Routing.url_helpers
|
2017-06-29 17:06:35 +00:00
|
|
|
h.project_snippet_url(project, snippet,
|
2015-04-03 00:46:43 +00:00
|
|
|
only_path: context[:only_path])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|