Sha256: 4b35aa7cb25271bb2392d17f398bce7a1f30dc4ad5748527a515fe35590ab85a

Contents?: true

Size: 932 Bytes

Versions: 6

Compression:

Stored size: 932 Bytes

Contents

# frozen_string_literal: true

module Bridgetown
  module Localizable
    def all_locales
      result_set = case self
                   when Bridgetown::Resource::Base
                     collection.resources
                   when Bridgetown::GeneratedPage
                     site.generated_pages
                   else
                     []
                   end

      matching_resources = result_set.select do |item|
        matches_resource?(item)
      end

      matching_resources.sort_by do |item|
        site.config.available_locales.index item.data.locale
      end
    end

    def matches_resource?(item)
      if item.relative_path.is_a?(String)
        item.localeless_path == localeless_path
      else
        item.relative_path.parent == relative_path.parent
      end && item.data.slug == data.slug
    end

    def localeless_path
      relative_path.gsub(%r{\A#{data.locale}/}, "")
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bridgetown-core-2.0.0.beta3 lib/bridgetown-core/concerns/localizable.rb
bridgetown-core-2.0.0.beta2 lib/bridgetown-core/concerns/localizable.rb
bridgetown-core-2.0.0.beta1 lib/bridgetown-core/concerns/localizable.rb
bridgetown-core-1.3.4 lib/bridgetown-core/concerns/localizable.rb
bridgetown-core-1.3.3 lib/bridgetown-core/concerns/localizable.rb
bridgetown-core-1.3.2 lib/bridgetown-core/concerns/localizable.rb