Class: Bridgetown::Tags::BlockRenderTag

Inherits:
Liquid::Block
  • Object
show all
Defined in:
bridgetown-core/lib/bridgetown-core/tags/render_content.rb

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'bridgetown-core/lib/bridgetown-core/tags/render_content.rb', line 7

def render(context)
  context.stack({}) do
    # unindent the incoming text
    content = Bridgetown::Utils.reindent_for_markdown(super)

    regions = gather_content_regions(context)

    site = context.registers[:site]
    converter = site.find_converter_instance(Bridgetown::Converters::Markdown)
    markdownified_content = converter.convert(content)
    context["processed_component_content"] = markdownified_content

    render_params = [@markup, "content: processed_component_content"]
    unless regions.empty?
      regions.each do |region_name, region_content|
        region_name = region_name.sub("content_with_region_", "")

        if region_name.end_with? ":markdown"
          region_name.sub!(%r!:markdown$!, "")
          context[region_name] = converter.convert(
            Bridgetown::Utils.reindent_for_markdown(region_content)
          )
        else
          context[region_name] = region_content
        end
        render_params.push "#{region_name}: #{region_name}"
      end
    end

    Liquid::Render.parse("render", render_params.join(","), nil, @parse_context)
      .render_tag(context, +"")
  end
end