Commit e0f9d3a5 authored by Robert Speicher's avatar Robert Speicher

Update ReferenceFilter docs

[ci skip]
parent 72afcbcd
...@@ -11,15 +11,12 @@ module Gitlab ...@@ -11,15 +11,12 @@ module Gitlab
# Context options: # Context options:
# :project (required) - Current project, ignored if reference is cross-project. # :project (required) - Current project, ignored if reference is cross-project.
# :only_path - Generate path-only links. # :only_path - Generate path-only links.
#
# Results:
# :references - A Hash of references that were found and replaced.
class ReferenceFilter < HTML::Pipeline::Filter class ReferenceFilter < HTML::Pipeline::Filter
def self.user_can_reference?(user, node, context) def self.user_can_reference?(user, node, context)
if node.has_attribute?('data-project') if node.has_attribute?('data-project')
project_id = node.attr('data-project').to_i project_id = node.attr('data-project').to_i
return true if project_id == context[:project].id return true if project_id == context[:project].id
project = Project.find(project_id) rescue nil project = Project.find(project_id) rescue nil
Ability.abilities.allowed?(user, :read_project, project) Ability.abilities.allowed?(user, :read_project, project)
else else
...@@ -33,14 +30,16 @@ module Gitlab ...@@ -33,14 +30,16 @@ module Gitlab
# Returns a data attribute String to attach to a reference link # Returns a data attribute String to attach to a reference link
# #
# id - Object ID # attributes - Hash, where the key becomes the data attribute name and the
# type - Object type (default: :project) # value is the data attribute value
# #
# Examples: # Examples:
# #
# data_attribute(project: 1) # => "data-reference-filter=\"SomeReferenceFilter\" data-project=\"1\"" # data_attribute(project: 1, issue: 2)
# data_attribute(user: 2) # => "data-reference-filter=\"SomeReferenceFilter\" data-user=\"2\"" # # => "data-reference-filter=\"Gitlab::Markdown::SomeReferenceFilter\" data-project=\"1\" data-issue=\"2\""
# data_attribute(group: 3) # => "data-reference-filter=\"SomeReferenceFilter\" data-group=\"3\"" #
# data_attribute(project: 3, merge_request: 4)
# # => "data-reference-filter=\"Gitlab::Markdown::SomeReferenceFilter\" data-project=\"3\" data-merge-request=\"4\""
# #
# Returns a String # Returns a String
def data_attribute(attributes = {}) def data_attribute(attributes = {})
...@@ -86,7 +85,7 @@ module Gitlab ...@@ -86,7 +85,7 @@ module Gitlab
# Yields the current node's String contents. The result of the block will # Yields the current node's String contents. The result of the block will
# replace the node's existing content and update the current document. # replace the node's existing content and update the current document.
# #
# Returns the updated Nokogiri::XML::Document object. # Returns the updated Nokogiri::HTML::DocumentFragment object.
def replace_text_nodes_matching(pattern) def replace_text_nodes_matching(pattern)
return doc if project.nil? return doc if project.nil?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment