# $Id: ext_theme.rb,v 1.1 2004/05/12 18:26:04 eto Exp $
# Copyright (C) 2003-2004 Kouichirou Eto, All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
# You can redistribute it and/or modify it under the terms of the GNU GPL2.

module Qwik
  class ServerMemory
    def theme
      @theme = ThemeFactory.new(@config) if @theme.nil?
      @theme
    end
  end

  class Plugin
    def theme_list
      ar = @memory.theme.get_list
      e = @g.ul
      ar.each {|t|
	e << @g.li{t}
      }
      e
    end
  end

  class ThemeFactory
    def initialize(config)
      @config = config
      @theme_path = @config.theme_dir.path
    end

    def get_list
      @themes = []
      @theme_path.each_entry {|d|
	dir = @theme_path+d
	next unless dir.directory?
	s = d.to_s
	next if s =~ /^\./
	next if s =~ /^CVS/
	@themes << d.to_s
      }
      @themes
    end
  end
end
