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

wiki_page.rb « git « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 57b7e7d53ddfc992d237b1e5137658b59dd08418 (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
# frozen_string_literal: true

module Gitlab
  module Git
    class WikiPage
      attr_reader :url_path, :title, :format, :path, :version, :raw_data, :name, :historical, :formatted_data

      class << self
        # Abstracts away Gitlab::GitalyClient::WikiPage
        def from_gitaly_wiki_page(gitaly_page, version)
          new(
            url_path: gitaly_page.url_path,
            title: gitaly_page.title,
            format: gitaly_page.format,
            path: gitaly_page.path,
            raw_data: gitaly_page.raw_data,
            name: gitaly_page.name,
            historical: gitaly_page.historical?,
            version: version
          )
        end
      end

      def initialize(hash)
        @url_path = hash[:url_path]
        @title = hash[:title]
        @format = hash[:format]
        @path = hash[:path]
        @raw_data = hash[:raw_data]
        @name = hash[:name]
        @historical = hash[:historical]
        @version = hash[:version]
      end

      def historical?
        @historical
      end

      def text_data
        return @text_data if defined?(@text_data)

        @text_data = @raw_data && Gitlab::EncodingHelper.encode!(@raw_data.dup)
      end
    end
  end
end