lib/contentful_middleman/helpers.rb in contentful_middleman-4.0.1 vs lib/contentful_middleman/helpers.rb in contentful_middleman-4.1.0
- old
+ new
@@ -1,7 +1,8 @@
require 'thor/core_ext/hash_with_indifferent_access'
require 'contentful_middleman/tools/preview_proxy'
+require 'rich_text_renderer'
module ContentfulMiddleman
module Helpers
def contentful_instances
ContentfulMiddleman.instances
@@ -44,8 +45,18 @@
tries: tries,
expires_in: expires_in
)
block.call(preview_client)
+ end
+
+ def rich_text(document_field, instance_index = 0)
+ mappings = begin
+ app.extensions[:contentful]["instance_#{instance_index}"].options[:rich_text_mappings] || {}
+ rescue Exception
+ {}
+ end
+
+ RichTextRenderer::Renderer.new(mappings).render(document_field)
end
end
end