aboutsummaryrefslogtreecommitdiffstats
path: root/core/skin.rb
diff options
context:
space:
mode:
authorToshiaki Asai <toshi.alternative@gmail.com>2014-10-23 00:38:44 +0900
committerToshiaki Asai <toshi.alternative@gmail.com>2014-10-23 00:38:44 +0900
commitd902ca9f13da644841849d543ab4f229cab32d20 (patch)
tree041d37decd3fdf41f3e7381ebd017a1b9d2926cf /core/skin.rb
parent4376a0f9ef799d0b384568c764cc20fb68eb1a48 (diff)
downloadmikutter-d902ca9f13da644841849d543ab4f229cab32d20.tar.gz
サードパーティスキン refs #722
Diffstat (limited to 'core/skin.rb')
-rw-r--r--core/skin.rb39
1 files changed, 33 insertions, 6 deletions
diff --git a/core/skin.rb b/core/skin.rb
index e352029c..4686fd7b 100644
--- a/core/skin.rb
+++ b/core/skin.rb
@@ -1,15 +1,42 @@
# -*- coding: utf-8 -*-
+miquire :core, "userconfig"
+
class Skin
+ SKIN_ROOT = File.join(CHIConfig::CONFROOT, "skin")
+ USER_SKIN = if :vanilla == UserConfig[:skin_dir]
+ nil
+ else
+ UserConfig[:skin_dir] end
+
+ def self.default_dir
+ File.join(*[File.dirname(__FILE__), "skin", "data"].flatten)
+ end
- def self.get(filename)
- fn = File.join(*[path, filename].flatten)
- return Skin.get('notfound.png') if 'notfound.png' != filename and not FileTest.exist?(fn)
- fn
+ def self.default_image
+ File.join(default_dir, "notfound.png")
end
- def self.path
- [File.dirname(__FILE__), "skin", "data"]
+ def self.user_dir
+ if USER_SKIN
+ p [SKIN_ROOT, USER_SKIN]
+ File.join(SKIN_ROOT, USER_SKIN)
+ else
+ nil
+ end
end
+ def self.get(filename, default = default_image)
+ valid_path = [ user_dir, default_dir ].compact.map { |_|
+ File.join(_, filename)
+ }.select { |_|
+ FileTest.exist?(_)
+ }.first
+
+ if valid_path
+ valid_path
+ else
+ default
+ end
+ end
end