Sha256: 521cce37305a67c9b38d7a2d1527d7dd026e0fc988475b523f79584b11c65c42

Contents?: true

Size: 815 Bytes

Versions: 11

Compression:

Stored size: 815 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

      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 { |size| [".h#{size}", size] }
      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

11 entries across 11 versions & 1 rubygems

Version Path
alchemy_cms-6.1.10 app/models/alchemy/ingredients/headline.rb
alchemy_cms-6.1.9 app/models/alchemy/ingredients/headline.rb
alchemy_cms-6.1.8 app/models/alchemy/ingredients/headline.rb
alchemy_cms-6.1.7 app/models/alchemy/ingredients/headline.rb
alchemy_cms-6.1.6 app/models/alchemy/ingredients/headline.rb
alchemy_cms-6.1.5 app/models/alchemy/ingredients/headline.rb
alchemy_cms-6.1.4 app/models/alchemy/ingredients/headline.rb
alchemy_cms-6.1.3 app/models/alchemy/ingredients/headline.rb
alchemy_cms-6.1.2 app/models/alchemy/ingredients/headline.rb
alchemy_cms-6.1.1 app/models/alchemy/ingredients/headline.rb
alchemy_cms-6.1.0 app/models/alchemy/ingredients/headline.rb