Class: Avo::SvgFinder
- Inherits:
-
Object
- Object
- Avo::SvgFinder
- Defined in:
- lib/avo/svg_finder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #default_strategy ⇒ Object
-
#initialize(filename) ⇒ SvgFinder
constructor
A new instance of SvgFinder.
-
#pathname ⇒ Object
Use the default static finder logic.
Constructor Details
#initialize(filename) ⇒ SvgFinder
Returns a new instance of SvgFinder.
6 7 8 |
# File 'lib/avo/svg_finder.rb', line 6 def initialize(filename) @filename = filename end |
Class Method Details
.find_asset(filename) ⇒ Object
2 3 4 |
# File 'lib/avo/svg_finder.rb', line 2 def self.find_asset(filename) new(filename) end |
Instance Method Details
#default_strategy ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/avo/svg_finder.rb', line 32 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 |
#pathname ⇒ Object
Use the default static finder logic. If that doesn't find anything, search according to our pattern:
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/avo/svg_finder.rb', line 11 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 |