summaryrefslogtreecommitdiff
path: root/lib/banzai/object_renderer.rb
diff options
context:
space:
mode:
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