2019-06-05 00:59:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module MarkdownCache
|
|
|
|
# Knows about the relationship between markdown and html field names, and
|
|
|
|
# stores the rendering contexts for the latter
|
|
|
|
class FieldData
|
|
|
|
def initialize
|
|
|
|
@data = {}
|
|
|
|
end
|
|
|
|
|
2021-06-07 11:09:56 -04:00
|
|
|
delegate :[], :[]=, :key?, to: :@data
|
2019-06-05 00:59:48 -04:00
|
|
|
|
|
|
|
def markdown_fields
|
|
|
|
@data.keys
|
|
|
|
end
|
|
|
|
|
|
|
|
def html_field(markdown_field)
|
|
|
|
"#{markdown_field}_html"
|
|
|
|
end
|
|
|
|
|
|
|
|
def html_fields
|
|
|
|
@html_fields ||= markdown_fields.map { |field| html_field(field) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def html_fields_whitelisted
|
|
|
|
markdown_fields.each_with_object([]) do |field, fields|
|
|
|
|
if @data[field].fetch(:whitelisted, false)
|
|
|
|
fields << html_field(field)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|