Class: OSX::NSImage

Inherits:
Object show all
Defined in:
lib/rucola/rucola_support/core_ext/objc/nsimage.rb

Class Method Summary collapse

Class Method Details

.imageNamed(name) ⇒ Object

This implementation adds app/assets to the search domain. So if for instance you have an image app/assets/some_img.png, you can then use OSX::NSImage.imageNamed(‘some_img’) and it will be found.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rucola/rucola_support/core_ext/objc/nsimage.rb', line 6

def imageNamed(name)
  if @assets_files.nil?
    @assets_files = {}
    Dir.glob("#{Rucola::RCApp.assets_path}/*.*").each do |file|
      basename = File.basename(file).gsub(/\..*/, '')
      @assets_files[basename] = file
    end
  end

  if image_file = (@assets_files[name.to_s] || @assets_files[name.to_s.gsub(/\..*/, '')])
    alloc.initWithContentsOfFile image_file
  else
    super_imageNamed(name)
  end
end