class Qiita::Markdown::Filters::GroupMention::MentionableNode
Constants
- GROUP_IDENTIFIER_PATTERN
- IGNORED_ANCESTOR_ELEMENT_NAMES
Public Class Methods
new(node, group_mention_url_generator)
click to toggle source
@param node [Nokogiri::XML::Node] @param group_mention_url_generator [Proc]
# 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
Public Instance Methods
groups()
click to toggle source
@return [Array<Hash>]
# File lib/qiita/markdown/filters/group_mention.rb, line 51 def groups @groups ||= [] end
ignorable?()
click to toggle source
@return [false, true]
# File lib/qiita/markdown/filters/group_mention.rb, line 56 def ignorable? !has_at_mark? || has_any_ignored_ancestor? || !replaced? end
replaced_html()
click to toggle source
@return [String]
# 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
Private Instance Methods
has_any_ignored_ancestor?()
click to toggle source
@return [false, true]
# 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
has_at_mark?()
click to toggle source
@return [false, true]
# File lib/qiita/markdown/filters/group_mention.rb, line 85 def has_at_mark? html.include?("@") end
html()
click to toggle source
@return [String]
# File lib/qiita/markdown/filters/group_mention.rb, line 90 def html @html ||= @node.to_html end
replaced?()
click to toggle source
@return [false, true]
# File lib/qiita/markdown/filters/group_mention.rb, line 95 def replaced? html != replaced_html end