debian-mirror-gitlab/lib/gitlab/markdown_cache/field_data.rb

36 lines
796 B
Ruby
Raw Normal View History

2019-09-04 21:01:54 +05:30
# 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
delegate :[], :[]=, to: :@data
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