Sha256: f7b2ecc12345923e2b9b6281552cc5017fd4b481441dd85d6b23fce2bfbb4d20
Contents?: true
Size: 1.32 KB
Versions: 5
Compression:
Stored size: 1.32 KB
Contents
class Theme cattr_accessor :cache_theme_lookup @@cache_theme_lookup = false attr_accessor :name, :title, :description, :preview_image def initialize(name) @name = name @title = name.underscore.humanize.titleize @description_html = nil end def description if @description_html.nil? @description_html = RedCloth.new(File.read( File.join(Theme.path_to_theme(name), "about.markdown") )).to_html(:markdown, :textile) rescue "#{title}" end @description_html end def has_preview? File.exists?( File.join( Theme.path_to_theme(name), 'images', 'preview.png' ) ) rescue false end def preview_image 'preview.png' end def self.find_all installed_themes.inject([]) do |array, path| array << theme_from_path(path) end end private def self.themes_root File.join(Rails.root, "themes") end def self.path_to_theme(theme) File.join(themes_root, theme) end def self.theme_from_path(path) name = path.scan(/[-\w]+$/i).flatten.first self.new(name) end def self.installed_themes cache_theme_lookup ? @theme_cache ||= search_theme_directory : search_theme_directory end def self.search_theme_directory Dir.glob("#{themes_root}/[-_a-zA-Z0-9]*").collect do |file| file if File.directory?(file) end.compact end end
Version data entries
5 entries across 5 versions & 1 rubygems