Sha256: aed8a7fce8ad75c7781dee04d5c2b514fab320ff035dc06fea3ff1ee906dc6ec

Contents?: true

Size: 1.09 KB

Versions: 25

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Maglev
  module TagHelper
    def wrapper_tag(options = nil, &block)
      return WrapperTagBuilder.new(view_context, self) if options.nil?

      tag_options = (options || {}).merge(id: dom_id)
      tag_options[:data] = (tag_options[:data] || {}).merge(tag_data)
      content = view_context.capture(&block)
      view_context.tag.public_send(
        tag_options.delete(:html_tag) || :div,
        content,
        **tag_options
      )
    end

    def setting_tag(setting_id, options = {}, &block)
      # setting = settings.public_send(setting_id)
      find_setting(settings, setting_id).tag(view_context, options, &block)
    end

    class WrapperTagBuilder
      attr_reader :view_context, :component

      def initialize(view_context, component)
        @view_context = view_context
        @component = component
      end

      def method_missing(name, options = nil, &block)
        component.wrapper_tag(
          (options || {}).merge(html_tag: name),
          &block
        )
      end

      def respond_to_missing?
        true
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
maglevcms-1.8.0 app/components/maglev/tag_helper.rb
maglevcms-1.7.3 app/components/maglev/tag_helper.rb
maglevcms-1.7.2 app/components/maglev/tag_helper.rb
maglevcms-1.7.1 app/components/maglev/tag_helper.rb
maglevcms-1.7.0 app/components/maglev/tag_helper.rb
maglevcms-1.6.1 app/components/maglev/tag_helper.rb
maglevcms-1.6.0 app/components/maglev/tag_helper.rb
maglevcms-1.5.1 app/components/maglev/tag_helper.rb
maglevcms-1.4.0 app/components/maglev/tag_helper.rb
maglevcms-1.3.0 app/components/maglev/tag_helper.rb
maglevcms-1.2.2 app/components/maglev/tag_helper.rb
maglevcms-1.2.1 app/components/maglev/tag_helper.rb
maglevcms-1.2.0 app/components/maglev/tag_helper.rb
maglevcms-1.1.7 app/components/maglev/tag_helper.rb
maglevcms-1.1.6 app/components/maglev/tag_helper.rb
maglevcms-1.1.5 app/components/maglev/tag_helper.rb
maglevcms-1.1.4 app/components/maglev/tag_helper.rb
maglevcms-1.1.3 app/components/maglev/tag_helper.rb
maglevcms-1.1.2 app/components/maglev/tag_helper.rb
maglevcms-1.1.1 app/components/maglev/tag_helper.rb