Welcome to mirror list, hosted at ThFree Co, Russian Federation.

introduced_in.rb « filters « lib - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3f81b0e4e8984fb1014ac7e0e96153e91d1a4864 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

# Adapted from the admonition code on http://nanoc.ws/
class IntroducedInFilter < Nanoc::Filter
  identifier :introduced_in

  def run(content, _params = {})
    # `#dup` is necessary because `.fragment` modifies the incoming string. Ew!
    # See https://github.com/sparklemotion/nokogiri/issues/1077
    @incremental_id = 0
    doc = Nokogiri::HTML.fragment(content.dup)
    doc.css('blockquote').each do |blockquote|
      content = blockquote.inner_html
      # Searches for a blockquote with either:
      # - "deprecated <optional text> in"
      # - "introduced <optional text> in"
      # - "moved <optional text> to"
      # - "recommended <optional text> in"
      # - "removed <optional text> in"
      # - "renamed <optional text> in"
      # - "changed <optional text> in"
      # - "enabled <optional text> in"
      # ...followed by "GitLab"
      # OR a feature detail (Tier, Offering, or Status).
      next unless content.match?(%r{(<a href="[^"]+">)?(
        introduced|
        enabled|
        (re)?moved|
        changed|
        deprecated|
        renamed|
        recommended
        )(</a>)?(.*)? (in|to).*GitLab}xmi) ||
        content.include?("Tier:") ||
        content.include?("Offering:") ||
        content.include?("Status:")

      new_content = generate(content)
      blockquote.replace(new_content)
    end
    doc.to_s
  end

  def generate(content)
    @incremental_id += 1
    <<~HTML
    <div class="introduced-in gl-mb-5">
      <div class="gl-mb-3">Feature availability<button class="text-expander" type="button" data-toggle="collapse" data-target="#release_version_notes_#{@incremental_id}" aria-expanded="false" aria-controls="release_version_notes_#{@incremental_id}" aria-label="Version history"></button>
      </div>
      <div class="introduced-in-content collapse" id="release_version_notes_#{@incremental_id}">
        #{content}
      </div>
    </div>
    HTML
  end
end