Sha256: 7772fa530470b86c2f86f0cf0c704388f21f7b8f99ad77c84cdffbe6817ffcce

Contents?: true

Size: 981 Bytes

Versions: 4

Compression:

Stored size: 981 Bytes

Contents

class Theme
  cattr_accessor :cache_theme_lookup
  @@cache_theme_lookup = false

  attr_accessor :name, :path, :description_html

  def initialize(name, path=nil)
    @name = name
    @path = path ||= Theme.path_to_theme(name)
  end
 
  def description
    File.read("#{path}/about.markdown") rescue "### #{name}"
  end
  
  def self.themes_root
    RAILS_ROOT + "/themes"
  end
  
  def self.path_to_theme(theme)
    "#{themes_root}/#{theme}"
  end
  
  def self.theme_from_path(path)
    name = path.scan(/[-\w]+$/i).flatten.first
    self.new(name, path)
  end

  def self.find_all
    installed_themes.inject([]) do |array, path|
      array << theme_from_path(path)
    end
  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

4 entries across 4 versions & 1 rubygems

Version Path
theme_generator-1.2.0 templates/theme.rb
theme_generator-1.2.1 templates/theme.rb
theme_generator-1.2.2 templates/theme.rb
theme_generator-1.3.0 templates/theme.rb