gitlab/lib/banzai.rb
nicolasdular a41ff9d025 Fix broadcast message rendering
With the broadcast placeholders we're using
`Banzai#render_and_post_process` instead of `Banzai#render_field` like
before. `render_and_post_process` is using `render` instead of
`render_field` internally, which means that we need to pass in the text
of a broadcast message instead of which field should be rendered.

However another difference of this method is that it is not
automatically using the `BroadcastMessagePipeline` for rendering. We
could overcome this by passing `pipeline: :broadcast_message` in the
context but I've instead added another method
`render_field_and_post_process` which calls `render_field` internally
instead to align with the behaviour that we used before.
2020-03-23 10:07:32 +01:00

35 lines
964 B
Ruby

# frozen_string_literal: true
module Banzai
# if you need to render markdown, then you probably need to post_process as well,
# such as removing references that the current user doesn't have
# permission to make
def self.render_and_post_process(text, context = {})
post_process(render(text, context), context)
end
def self.render_field_and_post_process(object, field, context = {})
post_process(render_field(object, field, context), context)
end
def self.render(text, context = {})
Renderer.render(text, context)
end
def self.render_field(object, field, context = {})
Renderer.render_field(object, field, context)
end
def self.cache_collection_render(texts_and_contexts)
Renderer.cache_collection_render(texts_and_contexts)
end
def self.render_result(text, context = {})
Renderer.render_result(text, context)
end
def self.post_process(html, context)
Renderer.post_process(html, context)
end
end