summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorTom Black <[email protected]>2019-04-02 01:49:44 -0500
committerTom Black <[email protected]>2019-04-06 21:36:59 -0500
commit385ab540946ae27101167f9fea9eafc422fd36f7 (patch)
tree565afff6e92fd23a5a5ba92bfd1052eaf2a08ac8 /lib
parent7d1a4de254bd4404affd7ddcafa4ef82f3d32ded (diff)
downloadruby2d-385ab540946ae27101167f9fea9eafc422fd36f7.tar.gz
ruby2d-385ab540946ae27101167f9fea9eafc422fd36f7.zip
Bundle dependencies with the gem
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby2d.rb8
-rw-r--r--lib/ruby2d/font.rb39
2 files changed, 33 insertions, 14 deletions
diff --git a/lib/ruby2d.rb b/lib/ruby2d.rb
index 305f065..c03560d 100644
--- a/lib/ruby2d.rb
+++ b/lib/ruby2d.rb
@@ -21,13 +21,7 @@ unless RUBY_ENGINE == 'mruby'
require 'ruby2d/music'
if RUBY_PLATFORM =~ /mingw/
- # When using the Windows CI AppVeyor
- if ENV['APPVEYOR']
- s2d_dll_path = 'C:\msys64\usr\local\bin'
- # When in a standard MinGW shell
- else
- s2d_dll_path = '~/../../usr/local/bin'
- end
+ s2d_dll_path = Gem::Specification.find_by_name('ruby2d').gem_dir + '/assets/mingw/bin'
RubyInstaller::Runtime.add_dll_directory(File.expand_path(s2d_dll_path))
end
diff --git a/lib/ruby2d/font.rb b/lib/ruby2d/font.rb
index ace9b2e..08f6b17 100644
--- a/lib/ruby2d/font.rb
+++ b/lib/ruby2d/font.rb
@@ -17,7 +17,14 @@ module Ruby2D
# Get all fonts with full file paths
def all_paths
- fonts = `find #{directory} -name *.ttf`.split("\n")
+ # MRuby does not have `Dir` defined
+ if RUBY_ENGINE == 'mruby'
+ fonts = `find #{directory} -name *.ttf`.split("\n")
+ # If MRI and/or non-Bash shell (like cmd.exe)
+ else
+ fonts = Dir["#{directory}/**/*.ttf"]
+ end
+
fonts = fonts.reject do |f|
f.downcase.include?('bold') ||
f.downcase.include?('italic') ||
@@ -25,6 +32,7 @@ module Ruby2D
f.downcase.include?('narrow') ||
f.downcase.include?('black')
end
+
fonts.sort_by { |f| f.downcase.chomp '.ttf' }
end
@@ -39,12 +47,29 @@ module Ruby2D
# Get the fonts directory for the current platform
def directory
- if `uname`.include? 'Darwin' # macOS
- '/Library/Fonts'
- elsif `uname`.include? 'Linux'
- '/usr/share/fonts'
- elsif `uname`.include? 'MINGW'
- 'C:/Windows/Fonts'
+ macos_font_path = '/Library/Fonts'
+ linux_font_path = '/usr/share/fonts'
+ windows_font_path = 'C:/Windows/Fonts'
+
+ # If MRI and/or non-Bash shell (like cmd.exe)
+ if Object.const_defined? :RUBY_PLATFORM
+ case RUBY_PLATFORM
+ when /darwin/ # macOS
+ macos_font_path
+ when /linux/
+ linux_font_path
+ when /mingw/
+ windows_font_path
+ end
+ # If MRuby
+ else
+ if `uname`.include? 'Darwin' # macOS
+ macos_font_path
+ elsif `uname`.include? 'Linux'
+ linux_font_path
+ elsif `uname`.include? 'MINGW'
+ windows_font_path
+ end
end
end