Project

General

Profile

Patch #1864 » 1864-add-js-to-themes.diff

Eric Davis, 2008-10-25 06:46

View differences:

lib/redmine/themes.rb
35 35
  
36 36
    # Class used to represent a theme
37 37
    class Theme
38
      attr_reader :name, :dir, :stylesheets
38
      attr_reader :name, :dir, :stylesheets, :images, :javascripts
39 39
      
40 40
      def initialize(path)
41 41
        @dir = File.basename(path)
42 42
        @name = @dir.humanize
43 43
        @stylesheets = Dir.glob("#{path}/stylesheets/*.css").collect {|f| File.basename(f).gsub(/\.css$/, '')}
44
        @javascripts = Dir.glob("#{path}/javascripts/*.js").collect {|f| File.basename(f).gsub(/\.js$/, '')}
45
        @images      = Dir.glob("#{path}/images/*.*").collect {|f| File.basename(f)}
44 46
      end
45 47
      
46 48
      # Directory name used as the theme id
......
73 75
  def path_to_stylesheet(source)
74 76
    stylesheet_path source
75 77
  end
76
end
78

  
79
  def image_path(source)
80
    @current_theme ||= Redmine::Themes.theme(Setting.ui_theme)
81
    super((@current_theme && @current_theme.images.include?(source)) ?
82
      "/themes/#{@current_theme.dir}/images/#{source}" : source)
83
  end
84
  
85
  def path_to_image(source)
86
    image_path source    
87
  end
88
  
89
  def javascript_path(source)
90
    @current_theme ||= Redmine::Themes.theme(Setting.ui_theme)
91
    super((@current_theme && @current_theme.javascripts.include?(source)) ?
92
      "/themes/#{@current_theme.dir}/javascripts/#{source}" : source)
93
  end
94
  
95
  def path_to_javascript(source)
96
    javascript_path source
97
  end
98
  
99
  # or if we wanted to 'catch all' and allow the theme to have it's own version of anything in public
100
  # we could have just have compute_public_path look in the theme first
101
  # def compute_public_path(source, dir, ext = nil, include_host = true)
102
  # end
103
  
104
end
(2-2/2)