Sha256: a4250a27909312775db8a95dc863c2a3fab749c800772f561725dc35e6b3bccd

Contents?: true

Size: 1.15 KB

Versions: 14

Compression:

Stored size: 1.15 KB

Contents

class Avo::SvgFinder
  def self.find_asset(filename)
    new(filename)
  end

  def initialize(filename)
    @filename = filename
  end

  # Use the default static finder logic. If that doesn't find anything, search according to our pattern:
  def pathname
    found_asset = default_strategy

    # Use the found asset
    return found_asset if found_asset.present?

    paths = [
      Rails.root.join("app", "assets", "svgs", @filename).to_s,
      Rails.root.join(@filename).to_s,
      Avo::Engine.root.join("app", "assets", "svgs", @filename).to_s,
      Avo::Engine.root.join("app", "assets", "svgs", "heroicons", "outline", @filename).to_s,
      Avo::Engine.root.join(@filename).to_s,
    ]

    path = paths.find do |path|
      File.exist? path
    end

    path
  end

  def default_strategy
    if ::Rails.application.config.assets.compile
      asset = ::Rails.application.assets[@filename]
      Pathname.new(asset.filename) if asset.present?
    else
      manifest = ::Rails.application.assets_manifest
      asset_path = manifest.assets[@filename]
      unless asset_path.nil?
        ::Rails.root.join(manifest.directory, asset_path)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
avo-2.14.3.pre.4.tosqlfix lib/avo/svg_finder.rb
avo-2.14.3.pre.3.jsbundling lib/avo/svg_finder.rb
avo-2.14.3.pre.2.tailwindcss lib/avo/svg_finder.rb
avo-2.14.3.pre.1.branding lib/avo/svg_finder.rb
avo-2.14.2 lib/avo/svg_finder.rb
avo-2.14.2.pre.1 lib/avo/svg_finder.rb
avo-2.14.1 lib/avo/svg_finder.rb
avo-2.14.1.pre.1 lib/avo/svg_finder.rb
avo-2.14.0 lib/avo/svg_finder.rb
avo-2.13.6.pre.2 lib/avo/svg_finder.rb
avo-2.13.6.pre.1 lib/avo/svg_finder.rb
avo-2.13.5.pre.2 lib/avo/svg_finder.rb
avo-2.13.5.pre.1 lib/avo/svg_finder.rb
avo-2.13.4.pre.1 lib/avo/svg_finder.rb