Sha256: 86ec1e27d9a8e37aaa5d50bbfb36d9497f8ba98baf54c1aa32467e4054ba18da

Contents?: true

Size: 870 Bytes

Versions: 9

Compression:

Stored size: 870 Bytes

Contents

module AtomicCms
  module HasComponents
    extend ActiveSupport::Concern

    included do
      extend ClassMethods
    end

    module ClassMethods
      def component_attr(name)
        define_method("set_default_#{name}") do
          write_attribute(name, ArrayComponent.new.to_yaml) unless send(name)
        end

        after_initialize "set_default_#{name}"

        define_method("#{name}_object") do
          AtomicAssets::Component.from_yaml(send(name))
        end

        define_method("#{name}_object=") do |params|
          object = AtomicAssets::Component.from_hash(params)
          write_attribute(name, object.to_yaml)
        end

        define_method("#{name}_render") do
          send("#{name}_object").render
        end

        define_method("#{name}_edit") do
          send("#{name}_object").edit
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
atomic_cms-0.4.0 lib/atomic_cms/has_components.rb
atomic_cms-0.3.3 lib/atomic_cms/has_components.rb
atomic_cms-0.3.2 lib/atomic_cms/has_components.rb
atomic_cms-0.3.1 lib/atomic_cms/has_components.rb
atomic_cms-0.3.0 lib/atomic_cms/has_components.rb
atomic_cms-0.2.5 lib/atomic_cms/has_components.rb
atomic_cms-0.2.3 lib/atomic_cms/has_components.rb
atomic_cms-0.2.2 lib/atomic_cms/has_components.rb
atomic_cms-0.2.1 lib/atomic_cms/has_components.rb