Sha256: 3c782eb1acc60a85e8fd2508a9a48c0a755497dd637343fe04526bc0bcd9c3fe

Contents?: true

Size: 1003 Bytes

Versions: 12

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

module Alchemy
  module Ingredients
    # A text headline
    #
    class Headline < Alchemy::Ingredient
      include DomIds

      store_accessor :data,
        :dom_id,
        :level,
        :size

      allow_settings %i[
        anchor
        levels
        sizes
      ]

      before_create :set_level_and_size

      def preview_text(maxlength = 30)
        "H#{level}: #{value}"[0..maxlength - 1]
      end

      def level_options
        levels.map { |level| ["H#{level}", level] }
      end

      def size_options
        sizes.map do |size|
          case size
          when Array
            size
          else
            [".h#{size}", size]
          end
        end
      end

      private

      def levels
        settings.fetch(:levels, (1..6))
      end

      def sizes
        settings.fetch(:sizes, [])
      end

      def set_level_and_size
        self.level ||= levels.first
        self.size ||= sizes.first
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.3.3 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.3.2 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.2.7 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.3.1 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.3.0 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.2.6 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.2.5 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.2.4 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.2.3 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.2.2 app/models/alchemy/ingredients/headline.rb
alchemy_cms-7.2.1 app/models/alchemy/ingredients/headline.rb