Sha256: d2b4fadf8ef39463e4fc97a5c7bec5c9c9e3d66f7e47aeeb72130a50883f8951

Contents?: true

Size: 745 Bytes

Versions: 95

Compression:

Stored size: 745 Bytes

Contents

require 'securerandom'

module Avo
  module Fields
    class HeadingField < BaseField
      attr_reader :as_html
      attr_reader :empty

      def initialize(content, **args, &block)
        # Mark the field as empty if there's no content passed
        @empty = content.blank?
        # Add dummy content
        content ||= SecureRandom.hex

        args[:updatable] = false

        super(content, **args, &block)

        hide_on :index

        @as_html = args[:as_html].present? ? args[:as_html] : false
      end

      def id
        "heading_#{name.to_s.parameterize.underscore}"
      end

      # Override the value method if the field is empty
      def value
        return nil if empty

        super
      end
    end
  end
end

Version data entries

95 entries across 95 versions & 1 rubygems

Version Path
avo-2.36.2 lib/avo/fields/heading_field.rb
avo-2.36.1 lib/avo/fields/heading_field.rb
avo-2.36.0 lib/avo/fields/heading_field.rb
avo-2.35.0 lib/avo/fields/heading_field.rb
avo-2.34.7.pre.1 lib/avo/fields/heading_field.rb
avo-2.34.6 lib/avo/fields/heading_field.rb
avo-2.34.5 lib/avo/fields/heading_field.rb
avo-2.34.4 lib/avo/fields/heading_field.rb
avo-2.34.4.pre.1 lib/avo/fields/heading_field.rb
avo-2.34.3 lib/avo/fields/heading_field.rb
avo-2.34.2 lib/avo/fields/heading_field.rb
avo-2.34.1 lib/avo/fields/heading_field.rb
avo-2.34.0 lib/avo/fields/heading_field.rb
avo-2.33.3 lib/avo/fields/heading_field.rb
avo-2.33.3.pre.2 lib/avo/fields/heading_field.rb
avo-2.33.3.pre.1 lib/avo/fields/heading_field.rb
avo-2.33.2 lib/avo/fields/heading_field.rb
avo-2.33.1 lib/avo/fields/heading_field.rb
avo-2.33.0 lib/avo/fields/heading_field.rb
avo-2.32.6 lib/avo/fields/heading_field.rb