Sha256: ed1f034de1f576375edba4a8bbcc48dbcb9ecf33351027eecbfec4f8d96351c2

Contents?: true

Size: 836 Bytes

Versions: 27

Compression:

Stored size: 836 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)

        # this field is not used to update anything
        @for_presentation_only = true

        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

27 entries across 27 versions & 1 rubygems

Version Path
avo-3.0.1.beta8 lib/avo/fields/heading_field.rb
avo-3.0.1.beta6 lib/avo/fields/heading_field.rb
avo-3.0.1.beta7 lib/avo/fields/heading_field.rb
avo-3.0.1.beta5 lib/avo/fields/heading_field.rb
avo-3.0.1.beta2 lib/avo/fields/heading_field.rb
avo-3.0.1.beta4 lib/avo/fields/heading_field.rb
avo-3.0.1.beta3 lib/avo/fields/heading_field.rb
avo-3.0.0.beta1 lib/avo/fields/heading_field.rb
avo-3.0.1.beta1 lib/avo/fields/heading_field.rb
avo-3.0.0.pre17 lib/avo/fields/heading_field.rb
avo-3.0.0.pre18 lib/avo/fields/heading_field.rb
avo-3.0.0.pre14 lib/avo/fields/heading_field.rb
avo-3.0.0.pre16 lib/avo/fields/heading_field.rb
avo-3.0.0.pre15 lib/avo/fields/heading_field.rb
avo-3.0.0.pre13 lib/avo/fields/heading_field.rb
avo-3.0.0.pre12 lib/avo/fields/heading_field.rb
avo-3.0.0.pre10 lib/avo/fields/heading_field.rb
avo-3.0.0.pre11 lib/avo/fields/heading_field.rb
avo-3.0.0.pre8 lib/avo/fields/heading_field.rb
avo-3.0.0.pre9 lib/avo/fields/heading_field.rb