debian-mirror-gitlab/lib/gitlab/github_import/markdown_text.rb

40 lines
892 B
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
# frozen_string_literal: true
module Gitlab
module GithubImport
class MarkdownText
2021-06-08 01:23:25 +05:30
include Gitlab::EncodingHelper
2018-03-17 18:26:18 +05:30
def self.format(*args)
new(*args).to_s
end
# text - The Markdown text as a String.
# author - An instance of `Gitlab::GithubImport::Representation::User`
# exists - Boolean that indicates the user exists in the GitLab database.
def initialize(text, author, exists = false)
@text = text
@author = author
@exists = exists
end
def to_s
2021-06-08 01:23:25 +05:30
# Gitlab::EncodingHelper#clean remove `null` chars from the string
clean(format)
end
private
attr_reader :text, :author, :exists
def format
if author&.login.present? && !exists
2018-03-17 18:26:18 +05:30
"*Created by: #{author.login}*\n\n#{text}"
2021-06-08 01:23:25 +05:30
else
text
2018-03-17 18:26:18 +05:30
end
end
end
end
end