Project

General

Profile

機能 #722 » skin.rb

Skin魔改造 - Satoshi Okuno, 2014-10-20 00:35

 
1
# -*- coding: utf-8 -*-
2

    
3
miquire :core, "userconfig"
4

    
5
class Skin
6
  SKIN_ROOT = File.join(CHIConfig::CONFROOT, "skin")
7
  USER_SKIN = UserConfig[:skin_dir]
8

    
9
  def self.default_dir
10
    File.join(*[File.dirname(__FILE__), "skin", "data"].flatten)
11
  end
12

    
13
  def self.default_image
14
    File.join(default_dir, "notfound.png")
15
  end
16

    
17
  def self.user_dir
18
    if USER_SKIN
19
      File.join(SKIN_ROOT, USER_SKIN)
20
    else
21
      nil
22
    end
23
  end
24

    
25
  def self.get(filename, default = default_image)
26
    valid_path = [ user_dir, default_dir ].compact.map { |_|
27
      File.join(_, filename)
28
    }.select { |_|
29
      FileTest.exist?(_)
30
    }.first
31

    
32
    if valid_path
33
      valid_path
34
    else
35
      default
36
    end
37
  end
38
end
(1-1/5)