summaryrefslogtreecommitdiff
path: root/lib/banzai/object_renderer.rb
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-07-05 17:21:13 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-07-12 14:35:29 +0200
commit3d2c540db6bb33f1a7be6c1ba375d4f604544862 (patch)
tree5c293bc8889ac8c5cb8fc8a0e49934d72f0c60a2 /lib/banzai/object_renderer.rb
parent3ca9253444710c6a2d5ad4dca345f8d558be4f1a (diff)
downloadgitlab-ce-3d2c540db6bb33f1a7be6c1ba375d4f604544862.tar.gz
Object renderer read_multi rendered entries from Cacheread-multi-rendered-objects
Diffstat (limited to 'lib/banzai/object_renderer.rb')
-rw-r--r--lib/banzai/object_renderer.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/banzai/object_renderer.rb b/lib/banzai/object_renderer.rb
index dc83b87a6c1..9aef807c152 100644
--- a/lib/banzai/object_renderer.rb
+++ b/lib/banzai/object_renderer.rb
@@ -39,9 +39,7 @@ module Banzai
# Renders the attribute of every given object.
def render_objects(objects, attribute)
- objects.map do |object|
- render_attribute(object, attribute)
- end
+ render_attributes(objects, attribute)
end
# Redacts the list of documents.
@@ -64,16 +62,21 @@ module Banzai
context
end
- # Renders the attribute of an object.
+ # Renders the attributes of a set of objects.
#
- # Returns a `Nokogiri::HTML::Document`.
- def render_attribute(object, attribute)
- context = context_for(object, attribute)
+ # Returns an Array of `Nokogiri::HTML::Document`.
+ def render_attributes(objects, attribute)
+ strings_and_contexts = objects.map do |object|
+ context = context_for(object, attribute)
+
+ string = object.__send__(attribute)
- string = object.__send__(attribute)
- html = Banzai.render(string, context)
+ { text: string, context: context }
+ end
- Banzai::Pipeline[:relative_link].to_document(html, context)
+ Banzai.cache_collection_render(strings_and_contexts).each_with_index.map do |html, index|
+ Banzai::Pipeline[:relative_link].to_document(html, strings_and_contexts[index][:context])
+ end
end
def base_context