Module: Workarea::Api::Storefront::ContentBlocksHelper

Defined in:
app/helpers/workarea/api/storefront/content_blocks_helper.rb

Instance Method Summary collapse

Instance Method Details

#block_data_with_urls(block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/workarea/api/storefront/content_blocks_helper.rb', line 5

def block_data_with_urls(block)
  data = block.data.deep_dup

  block.type.fields.inject(data) do |data, field|
    value = block.data[field.slug.to_s]

    if field.type == :asset && value.present?
      asset =
        begin
          Content::Asset.find(value)
        rescue
          Content::Asset.placeholder
        end

      data["#{field.slug.to_s}_url"] = url_to_content_asset(asset)
    end

    data
  end
end

#render_block_to_string(block) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'app/helpers/workarea/api/storefront/content_blocks_helper.rb', line 26

def render_block_to_string(block)
  Workarea::Storefront::ApplicationController.render(
    template: 'workarea/storefront/content_blocks/show',
    layout: false,
    assigns: {
      block: Workarea::Storefront::ContentBlockViewModel.wrap(block)
    }
  )
end