Sha256: 3c77bd92821b4d68b2a5c2ac0fc5cbad280161017b0575841c3b001901497113

Contents?: true

Size: 790 Bytes

Versions: 6

Compression:

Stored size: 790 Bytes

Contents

module Spina
  module Partable
    extend ActiveSupport::Concern

    attr_accessor :view_context

    included do

      def part(attributes)
        part = find_part(attributes[:name]) || attributes[:part_type].constantize.new

        # Copy all attributes to part
        %w(name title hint options).each do |attribute|
          part.public_send("#{attribute}=", attributes[attribute.to_sym]) if part.respond_to?(attribute)
        end

        part
      end

      def has_content?(name)
        find_part(name).present?
      end

      def content(name = nil)
        name ? find_part(name)&.content : content_presenter
      end

      private

        def content_presenter
          @content_presenter ||= ContentPresenter.new(view_context, self)
        end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spina-2.12.0 app/models/concerns/spina/partable.rb
spina-2.11.0 app/models/concerns/spina/partable.rb
spina-2.10.0 app/models/concerns/spina/partable.rb
spina-2.9.1 app/models/concerns/spina/partable.rb
spina-2.9.0 app/models/concerns/spina/partable.rb
spina-2.8.1 app/models/concerns/spina/partable.rb