Sha256: d5d49538f8b90cb88ca2809d0d57016e1b9dfb78d8f4d3126d40f3cc936b6a30

Contents?: true

Size: 1.31 KB

Versions: 37

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Alchemy
  class ContentEditor < SimpleDelegator
    alias_method :content, :__getobj__

    def to_partial_path
      "alchemy/essences/#{essence_partial_name}_editor"
    end

    def css_classes
      [
        "content_editor",
        essence_partial_name,
      ].compact
    end

    def data_attributes
      {
        content_id: id,
        content_name: name,
      }
    end

    # Returns a string to be passed to Rails form field tags to ensure we have same params layout everywhere.
    #
    # === Example:
    #
    #   <%= text_field_tag content_editor.form_field_name, content_editor.ingredient %>
    #
    # === Options:
    #
    # You can pass an Essence column_name. Default is 'ingredient'
    #
    # ==== Example:
    #
    #   <%= text_field_tag content_editor.form_field_name(:link), content_editor.ingredient %>
    #
    def form_field_name(essence_column = "ingredient")
      "contents[#{id}][#{essence_column}]"
    end

    def form_field_id(essence_column = "ingredient")
      "contents_#{id}_#{essence_column}"
    end

    # Fixes Rails partial renderer calling to_model on the object
    # which reveals the delegated content instead of this decorator.
    def respond_to?(method_name)
      return false if method_name == :to_model

      super
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
alchemy_cms-5.1.10 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.0.10 app/decorators/alchemy/content_editor.rb
alchemy_cms-4.6.7 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.1.9 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.0.9 app/decorators/alchemy/content_editor.rb
alchemy_cms-4.6.6 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.1.8 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.0.8 app/decorators/alchemy/content_editor.rb
alchemy_cms-4.6.5 app/decorators/alchemy/content_editor.rb
alchemy_cms-4.6.4 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.0.7 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.1.7 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.1.6 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.0.6 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.1.5 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.0.5 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.1.4 app/decorators/alchemy/content_editor.rb
alchemy_cms-4.6.3 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.0.4 app/decorators/alchemy/content_editor.rb
alchemy_cms-5.1.3 app/decorators/alchemy/content_editor.rb