Sha256: 27ebff35af66a1a7746badc0480cc5953f84c6d0cf9a2fbf50310a4bc524c78a

Contents?: true

Size: 1.44 KB

Versions: 28

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Bridgetown
  class Plugin
    extend ActiveSupport::DescendantsTracker

    PRIORITIES = {
      low: -10,
      highest: 100,
      lowest: -100,
      normal: 0,
      high: 10,
    }.freeze

    SourceManifest = Struct.new(:origin, :components, :content, :layouts, keyword_init: true)

    # Get or set the priority of this plugin. When called without an
    # argument it returns the priority. When an argument is given, it will
    # set the priority.
    #
    # priority - The Symbol priority (default: nil). Valid options are:
    #            :lowest, :low, :normal, :high, :highest
    #
    # Returns the Symbol priority.
    def self.priority(priority = nil)
      @priority ||= nil
      @priority = priority if priority && PRIORITIES.key?(priority)
      @priority || :normal
    end

    # Spaceship is priority [higher -> lower]
    #
    # other - The class to be compared.
    #
    # Returns -1, 0, 1.
    def self.<=>(other)
      PRIORITIES[other.priority] <=> PRIORITIES[priority]
    end

    # Spaceship is priority [higher -> lower]
    #
    # other - The class to be compared.
    #
    # Returns -1, 0, 1.
    def <=>(other)
      self.class <=> other.class
    end

    # Initialize a new plugin. This should be overridden by the subclass.
    #
    # config - The Hash of configuration options.
    #
    # Returns a new instance.
    def initialize(config = {})
      # no-op for default
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
bridgetown-core-1.0.0 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.beta3 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.beta2 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.beta1 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha11 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha10 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha9 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha8 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha7 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha6 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha5 lib/bridgetown-core/plugin.rb
bridgetown-core-0.21.5 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha4 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha3 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha2 lib/bridgetown-core/plugin.rb
bridgetown-core-1.0.0.alpha1 lib/bridgetown-core/plugin.rb
bridgetown-core-0.21.4 lib/bridgetown-core/plugin.rb
bridgetown-core-0.21.3 lib/bridgetown-core/plugin.rb
bridgetown-core-0.21.2 lib/bridgetown-core/plugin.rb
bridgetown-core-0.21.1 lib/bridgetown-core/plugin.rb