Sha256: 6548b018b21b53f1cfa2b4f0003bbdc2b4324d6dc89ad243d4bc734622b4144e

Contents?: true

Size: 791 Bytes

Versions: 5

Compression:

Stored size: 791 Bytes

Contents

# frozen_string_literal: true

require 'forwardable'

module Bemer
  class Tag
    extend Forwardable

    def initialize(block = '', element = nil, **options, &content)
      @bem_cascade = options[:bem_cascade]
      @tag_builder = TagBuilder.new(block, element, options, &content)
      @renderer    = Renderer.new
    end

    def render
      tag_builder.content = capture_content

      renderer.render(tag_builder)
    end

    protected

    attr_reader :bem_cascade, :renderer, :tag_builder

    def_delegators :tag_builder, :block, :block?, :content

    def capture_content
      return content unless content.respond_to?(:call)

      builder = Builders::Tag::Element.new(block, bem_cascade) if block?

      content.binding.receiver.capture(builder, &content)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bemer-0.5.0 lib/bemer/tag.rb
bemer-0.4.0 lib/bemer/tag.rb
bemer-0.3.0 lib/bemer/tag.rb
bemer-0.2.0 lib/bemer/tag.rb
bemer-0.1.0 lib/bemer/tag.rb