class Qiita::Markdown::Filters::GroupMention::MentionableNode
Constants
- GROUP_IDENTIFIER_PATTERN
- IGNORED_ANCESTOR_ELEMENT_NAMES
Public Class Methods
Source
# File lib/qiita/markdown/filters/group_mention.rb, line 45 def initialize(node, group_mention_url_generator) @group_mention_url_generator = group_mention_url_generator @node = node end
@param node [Nokogiri::XML::Node] @param group_mention_url_generator [Proc]
Public Instance Methods
Source
# File lib/qiita/markdown/filters/group_mention.rb, line 51 def groups @groups ||= [] end
@return [Array<Hash>]
Source
# File lib/qiita/markdown/filters/group_mention.rb, line 56 def ignorable? !has_at_mark? || has_any_ignored_ancestor? || !replaced? end
@return [false, true]
Source
# File lib/qiita/markdown/filters/group_mention.rb, line 61 def replaced_html @replaced_html ||= html.gsub(GROUP_IDENTIFIER_PATTERN) do |string| team_url_name = ::Regexp.last_match(1) group_url_name = ::Regexp.last_match(2) group = { group_url_name: group_url_name, team_url_name: team_url_name } groups << group string.sub( "@#{team_url_name}/#{group_url_name}", %(<a href="#{@group_mention_url_generator.call(group)}">) + %(@#{team_url_name}/#{group_url_name}</a>), ) end end
@return [String]
Private Instance Methods
Source
# File lib/qiita/markdown/filters/group_mention.rb, line 78 def has_any_ignored_ancestor? @node.ancestors.any? do |node| IGNORED_ANCESTOR_ELEMENT_NAMES.include?(node.name.downcase) end end
@return [false, true]
Source
# File lib/qiita/markdown/filters/group_mention.rb, line 85 def has_at_mark? html.include?("@") end
@return [false, true]
Source
# File lib/qiita/markdown/filters/group_mention.rb, line 90 def html @html ||= @node.to_html end
@return [String]
Source
# File lib/qiita/markdown/filters/group_mention.rb, line 95 def replaced? html != replaced_html end
@return [false, true]