2015-08-27 19:02:49 -04:00
|
|
|
require 'gitlab/markdown'
|
|
|
|
|
2015-04-02 20:46:43 -04:00
|
|
|
module Gitlab
|
|
|
|
module Markdown
|
2015-04-14 18:34:01 -04:00
|
|
|
# Common methods for ReferenceFilters that support an optional cross-project
|
|
|
|
# reference.
|
2015-04-02 20:46:43 -04:00
|
|
|
module CrossProjectReference
|
|
|
|
# Given a cross-project reference string, get the Project record
|
|
|
|
#
|
2015-04-14 16:04:37 -04:00
|
|
|
# Defaults to value of `context[:project]` if:
|
2015-04-14 18:34:01 -04:00
|
|
|
# * No reference is given OR
|
2015-04-16 14:06:05 -04:00
|
|
|
# * Reference given doesn't exist
|
2015-04-02 20:46:43 -04:00
|
|
|
#
|
|
|
|
# ref - String reference.
|
|
|
|
#
|
2015-08-11 01:44:40 -04:00
|
|
|
# Returns a Project, or nil if the reference can't be found
|
2015-04-02 20:46:43 -04:00
|
|
|
def project_from_ref(ref)
|
2015-04-17 06:34:51 -04:00
|
|
|
return context[:project] unless ref
|
|
|
|
|
2015-08-11 01:44:40 -04:00
|
|
|
Project.find_with_namespace(ref)
|
2015-04-14 16:04:37 -04:00
|
|
|
end
|
2015-04-02 20:46:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|