Sha256: fbbda4f72b2eb5fca7faf411b3073e76ff2769b461deb0a729b81b85d5095aea

Contents?: true

Size: 1.16 KB

Versions: 28

Compression:

Stored size: 1.16 KB

Contents

require 'yaml'

module Chart
  class Theme
    class ThemeNotFound < RuntimeError; end
    
    @@theme_files = ["#{File.dirname(__FILE__)}/../themes.yml"]

    attr_accessor :colors
    attr_accessor :bar_colors
    attr_accessor :background
    attr_accessor :chart_background
    
    def self.load(theme_name)
      theme = new(theme_name)
    end
    
    def self.theme_files
      @@theme_files
    end
    
    # Allows you to specify paths for custom theme files in YAML format
    def self.add_theme_file(file)
      @@theme_files << file
    end
    
    def initialize(theme_name)
      themes = {}
      @@theme_files.each {|f| themes.update YAML::load(File.open(f))}
      theme = themes[theme_name]
      if theme
        self.colors = theme[:colors]
        self.bar_colors = theme[:bar_colors]
        self.background = theme[:background]
        self.chart_background = theme[:chart_background]
        self
      else
        raise(ThemeNotFound, "Could not locate the #{theme_name} theme ...")
      end
    end
    
    def to_options
      {:background => background, :chart_background => chart_background, :bar_colors => bar_colors.join(',')}
    end
  end
end

Version data entries

28 entries across 28 versions & 5 rubygems

Version Path
googlecharts-1.6.12 lib/gchart/theme.rb
googlecharts-1.6.10 lib/gchart/theme.rb
ghazel-ghazel-googlecharts-1.4.0.4 lib/gchart/theme.rb
ghazel-googlecharts-1.4.0.1 lib/gchart/theme.rb
ghazel-googlecharts-1.4.0.2 lib/gchart/theme.rb
ghazel-googlecharts-1.4.0.3 lib/gchart/theme.rb
ghazel-googlecharts-1.4.0.4 lib/gchart/theme.rb
ghazel-googlecharts-1.4.0 lib/gchart/theme.rb
mattetti-googlecharts-1.3.5 lib/gchart/theme.rb
mattetti-googlecharts-1.3.6 lib/gchart/theme.rb
mattetti-googlecharts-1.3.7 lib/gchart/theme.rb
mattetti-googlecharts-1.4.0 lib/gchart/theme.rb
googlecharts-1.6.8 lib/gchart/theme.rb
googlecharts-1.6.7 lib/gchart/theme.rb
googlecharts-1.6.6 lib/gchart/theme.rb
googlecharts-1.6.3 lib/gchart/theme.rb
googlecharts-1.6.2 lib/gchart/theme.rb
googlecharts-1.6.1 lib/gchart/theme.rb
googlecharts-1.6.0 lib/gchart/theme.rb
googlecharts-1.5.4 lib/gchart/theme.rb