Sha256: ff5adcddee3dc920a3282c194a05ac043fed92eb144b88a7471b2db636924037

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Bridgetown
  module Tags
    class BlockComponentTag < Liquid::Block
      def initialize(tag_name, markup, tokens)
        super

        filename, @extra_params = markup.strip.split(" ", 2)
        @component_path = "_components/#{filename.strip}.html"

        @tag_name = tag_name
      end

      def render(context)
        markdown_content = super

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

        context.stack do
          context["componentcontent"] = markdownified_content
          include_params = "#{@component_path} content=componentcontent"
          include_params = "#{include_params} #{@extra_params}" if @extra_params
          include_tag = IncludeTag.parse("include", include_params, [], @parse_context)
          include_tag.render(context)
        end
      end
    end
  end
end

Liquid::Template.register_tag("component", Bridgetown::Tags::BlockComponentTag)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bridgetown-core-0.9.0 lib/bridgetown-core/tags/component.rb
bridgetown-core-0.8.1 lib/bridgetown-core/tags/component.rb
bridgetown-core-0.8.0 lib/bridgetown-core/tags/component.rb
bridgetown-core-0.7.2 lib/bridgetown-core/tags/component.rb
bridgetown-core-0.7.1 lib/bridgetown-core/tags/component.rb