Class: Banzai::Filter::InlineObservabilityFilter
- Inherits:
-
HTML::Pipeline::Filter
- Object
- HTML::Pipeline::Filter
- Banzai::Filter::InlineObservabilityFilter
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- lib/banzai/filter/inline_observability_filter.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#create_element(url) ⇒ Object
Placeholder element for the frontend to use as an injection point for observability.
-
#element_to_embed(node) ⇒ Object
Creates a new element based on the parameters obtained from the target link.
-
#xpath_search ⇒ Object
Search params for selecting observability links.
Instance Method Details
#call ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/banzai/filter/inline_observability_filter.rb', line 8 def call return doc unless Gitlab::Observability.enabled?(group) doc.xpath(xpath_search).each do |node| next unless element = (node) # We want this to follow any surrounding content. For example, # if a link is inline in a paragraph. node.parent.children.last.add_next_sibling(element) end doc end |
#create_element(url) ⇒ Object
Placeholder element for the frontend to use as an injection point for observability.
24 25 26 27 28 29 30 |
# File 'lib/banzai/filter/inline_observability_filter.rb', line 24 def create_element(url) doc.document.create_element( 'div', class: 'js-render-observability', 'data-frame-url': url ) end |
#element_to_embed(node) ⇒ Object
Creates a new element based on the parameters obtained from the target link
39 40 41 42 43 44 |
# File 'lib/banzai/filter/inline_observability_filter.rb', line 39 def (node) url = node['href'] = (url) create_element() if end |
#xpath_search ⇒ Object
Search params for selecting observability links.
33 34 35 |
# File 'lib/banzai/filter/inline_observability_filter.rb', line 33 def xpath_search "descendant-or-self::a[starts-with(@href, '#{gitlab_domain}/groups/') and contains(@href,'/-/observability/')]" end |