Module: Drakkon::Fonts::Index
- Defined in:
- lib/drakkon/lib/fonts/fonts.rb
Overview
General Font Index Helper
Class Method Summary collapse
- .build_index ⇒ Object
-
.check(dir = nil) ⇒ Object
Recursively Go through.
- .context ⇒ Object
- .digest ⇒ Object
- .fonts_directory ⇒ Object
- .index ⇒ Object
- .process(file = nil) ⇒ Object
- .result ⇒ Object
- .run!(force: false, dir: nil) ⇒ Object
Class Method Details
.build_index ⇒ Object
44 45 46 |
# File 'lib/drakkon/lib/fonts/fonts.rb', line 44 def self.build_index check fonts_directory end |
.check(dir = nil) ⇒ Object
Recursively Go through
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/drakkon/lib/fonts/fonts.rb', line 61 def self.check(dir = nil) LogBot.info('Font Index', "Check: #{dir}") # Collect Fonts list = Dir["#{dir}/*"] # Ignore Empties return if list.empty? # Do other things Dir["#{dir}/*"].each do |file| next if File.directory?(file) process(file) end :done end |
.context ⇒ Object
11 12 13 14 15 |
# File 'lib/drakkon/lib/fonts/fonts.rb', line 11 def self.context @context ||= Dir.pwd @context end |
.digest ⇒ Object
17 18 19 20 |
# File 'lib/drakkon/lib/fonts/fonts.rb', line 17 def self.digest list = Dir["#{fonts_directory}/**/*"].select { |file| File.file?(file) } Digest::MD5.hexdigest(list.map { |x| Digest::MD5.file(x).hexdigest }.join) end |
.fonts_directory ⇒ Object
22 23 24 |
# File 'lib/drakkon/lib/fonts/fonts.rb', line 22 def self.fonts_directory "#{context}/fonts" end |
.index ⇒ Object
5 6 7 8 9 |
# File 'lib/drakkon/lib/fonts/fonts.rb', line 5 def self.index @index ||= {} @index end |
.process(file = nil) ⇒ Object
80 81 82 83 |
# File 'lib/drakkon/lib/fonts/fonts.rb', line 80 def self.process(file = nil) name = File.basename(file, File.extname(file)) index[name] = file.gsub(fonts_directory, '')[1..] end |
.result ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/drakkon/lib/fonts/fonts.rb', line 48 def self.result <<~RB module Drakkon module Fonts def self.index #{index.inspect} end end end RB end |
.run!(force: false, dir: nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/drakkon/lib/fonts/fonts.rb', line 26 def self.run!(force: false, dir: nil) @context = dir || Dir.pwd # Create Directory if sprites directory is missing FileUtils.mkdir_p(fonts_directory) if Settings.config[:font_digest] == digest && File.exist?("#{context}/app/drakkon/font_index.rb") LogBot.info('Fonts Index', 'Nothing New') return unless force end build_index Settings.update(:font_digest, digest) File.write("#{context}/app/drakkon/font_index.rb", result) end |