Sha256: 57f003440200f949c86a1d078f7bc2ea4d77c85172c27b5d6b3c5531dd4faf8a

Contents?: true

Size: 751 Bytes

Versions: 7

Compression:

Stored size: 751 Bytes

Contents

require_relative './asset_hyperlink_renderer'

module RichTextRenderer
  # Asset block renderer
  class AssetBlockRenderer < AssetHyperlinkRenderer
    # IMG HTML Tag
    IMAGE_HTML = ->(url, text) { "<img src=\"#{url}\" alt=\"#{text}\" />" }

    protected

    def render_asset(asset, node = nil)
      if asset.file.respond_to?(:content_type) && asset.file.content_type.include?('image')
        return render!(IMAGE_HTML, asset.url, asset.title)
      end

      super
    end

    def render_hash(asset, node = nil)
      if asset.fetch('fields', {}).fetch('file', {}).fetch('contentType', '').include?('image')
        return render!(IMAGE_HTML, asset['fields']['file']['url'], asset['fields']['title'])
      end

      super
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rich_text_renderer-0.3.2 lib/rich_text_renderer/block_renderers/asset_block_renderer.rb
rich_text_renderer-0.3.1 lib/rich_text_renderer/block_renderers/asset_block_renderer.rb
rich_text_renderer-0.3.0 lib/rich_text_renderer/block_renderers/asset_block_renderer.rb
rich_text_renderer-0.2.3 lib/rich_text_renderer/block_renderers/asset_block_renderer.rb
rich_text_renderer-0.2.2 lib/rich_text_renderer/block_renderers/asset_block_renderer.rb
rich_text_renderer-0.2.1 lib/rich_text_renderer/block_renderers/asset_block_renderer.rb
rich_text_renderer-0.2.0 lib/rich_text_renderer/block_renderers/asset_block_renderer.rb