Sha256: 5c69956ecab27bf289ce3425632795fe2eb0f21cc8855d46ceb40f992698697e

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

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 layout(layout='default')
    "../../themes/#{name}/layouts/#{layout}"
  end

  def description
    File.read("#{path}/about.markdown") rescue "### #{name}"
  end
  
  def self.themes_root
    RAILS_ROOT + "/themes"
  end

  # DEPRECATED: There is no 'current' theme, at least, not from here...
  def self.current_theme_path
    raise 'DEPRECATED: The current theme is set in the controller'
    "#{themes_root}/#{config[:theme]}"
  end
  # DEPRECATED: There is no 'current' theme, at least, not from here...
  def self.current
    theme_from_path(current_theme_path)
  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

2 entries across 2 versions & 1 rubygems

Version Path
theme_generator-1.1.1 templates/theme.rb
theme_generator-1.1.0 templates/theme.rb