lib/middlemac/private.rb
#--------------------------------------------------------
# Returns a list of assets from the sitemap that match
#  the given path (including file basename), where
# `path` might be any of:
#
# - An absolute path preceded by /, meaning that we
#   will search only in the given directory.
#
# - A relative path including at least one directory,
#   indicating that the asset might be in :locale,
#   :global, or :convention.
#
# - A naked basename, where have to search anywhere in
#   the sitemap, with priority given first to :locale,
#   then :global, :convention, and anywhere else.
#
# @param [String] path Specifies the asset without an
#   extension, which is to be checked.
# @param [String] content_type Specifies the MIME
#   type of the asset. Partial MIME type is supported,
#   such as `image/`.
# @param [Sitemap::Resource] resource Specifies the
#   resource for which the possible assets might apply.
# @return [Array<Sitemap::Resource>] An array of
#   resources that might be the sought-after file.
# @!visibility private
#--------------------------------------------------------
Returns a list of assets from the sitemap that match
the given path (including file basename), where
`path` might be any of.

An absolute path preceded by /, meaning that we
will search only in the given directory.

A relative path including at least one directory,
indicating that the asset might be in :locale,
:global, or :convention.

A naked basename, where have to search anywhere in
the sitemap, with priority given first to :locale,
then :global, :convention, and anywhere else.
Returns a list of assets from the sitemap that match the given path ( including file basename ) where ` path ` might be any of . An absolute path preceded by / meaning that we will search only in the given directory . A relative path including at least one directory indicating that the asset might be in : locale : global or : convention . A naked basename where have to search anywhere in the sitemap with priority given first to : locale then : global : convention and anywhere else .
def possible_assets_for_path(path, content_type, resource)
    pn = Pathname.new(path)
    dir, base = pn.split
    dir = dir.to_s
    base = File.basename(base.to_s, '.*')
    assets = app.config[:assets_dir]
    locale ="Resources/#{resource.hb_locale}.lproj/"
    domain = app.sitemap.resources.select do |r|
      r&.content_type&.start_with?(content_type) &&
          (base == File.basename(r.destination_path, '.*')) &&
          !r.ignored &&
          (r.destination_path.start_with?(assets) || r.destination_path.start_with?(locale))
    end
    if pn.absolute?
      domain = domain.select {|r| r.destination_path.start_with?(dir[1..-1])}
    elsif dir == '.'
      domain = domain.sort_by do |r|
        [r.asset_path_type == :locale ? 0 : 1,
         r.asset_path_type == :global ? 0 : 1,
         r.asset_path_type == :convention ? 0 : 1
        ]
      end
    else
      if content_type.start_with?('/image')
        domain = domain.select {|r| [:locale, :global, :convention].include?(r.asset_path_type) }
      end
    end
    return domain
  end
def possible_assets_for_path ( path , content_type , resource ) pn = Pathname . new ( path ) dir , base = pn . split dir = dir . to_s base = File . basename ( base . to_s , '.*' ) assets = app . config [ :assets_dir ] locale = "Resources/#{resource.hb_locale}.lproj/" domain = app . sitemap . resources . select do | r | r &. content_type &. start_with? ( content_type ) && ( base == File . basename ( r . destination_path , '.*' ) ) && ! r . ignored && ( r . destination_path . start_with? ( assets ) || r . destination_path . start_with? ( locale ) ) end if pn . absolute? domain = domain . select { | r | r . destination_path . start_with? ( dir [ 1 .. - 1 ] ) } elsif dir == '.' domain = domain . sort_by do | r | [ r . asset_path_type == :locale ? 0 : 1 , r . asset_path_type == :global ? 0 : 1 , r . asset_path_type == :convention ? 0 : 1 ] end else if content_type . start_with? ( '/image' ) domain = domain . select { | r | [ :locale , :global , :convention ] . include? ( r . asset_path_type ) } end end return domain end
Returns a list of assets from the sitemap that match
the given path (including file basename), where
`path` might be any of:
Returns a list of assets from the sitemap that match the given path ( including file basename ) where ` path ` might be any of :
# Perform pre-filtering of the entire sitemap, by getting a list of all: # - Assets with the given content type # - Whose basename without extension matches the provided basename without extension # - This isn't an ignored asset. # - That exists in :assets_dir or language.lproj. # Perform additional filtering according to what we're looking for. # If absolute, then only select items that were in the orginal # path given with the asset. # Not absolute, and naked, so it could be anywhere. Filter the list # by search priority, so that the first item is likely to be the one # that we're after: :locale, :global, :convention # Not absolute, but has a leading directory. We want to ensure that we # only return assets for the appropriate asset type in the appropriate # directories. The resource.asset_path_type will be :other_dir if it's # not already in the correct directory type.
An array of resources that might be the sought-after file.
An array of resources that might be the sought - after file .
Array<Sitemap::Resource>
path
<not_specific>
content_type
<not_specific>
resource
<not_specific>
<not_specific>
resource Specifies the resource for which the possible assets might apply.
resource Specifies the resource for which the possible assets might apply .
!visibility
None