Class: Sassafras::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/sassafras.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Theme

Returns a new instance of Theme.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sassafras.rb', line 60

def initialize(base)
  is_hex = (base =~ /#.*/)
  @base_rgb   = is_hex ? Color::RGB.from_html(base) : Color::RGB.const_get(base.to_s.camelize)
  @colors     = { 'base' => 
    Tints.new(@base_rgb).colors.merge(
    Shades.new(@base_rgb).colors)
  }
  return unless self.class.colors
  self.class.colors.each do |name, steps|
    color = self.hue_adjusted_base_rgb(steps)
    @colors[name] = 
      Tints. new(color).colors.merge(
      Shades.new(color).colors)
  end
end

Instance Attribute Details

#base_rgbObject (readonly)

Returns the value of attribute base_rgb.



20
21
22
# File 'lib/sassafras.rb', line 20

def base_rgb
  @base_rgb
end

Class Method Details

.analogous(base) ⇒ Object



39
40
41
# File 'lib/sassafras.rb', line 39

def analogous(base)
  AnalogousTheme.new(base)
end

.basic(base) ⇒ Object



31
32
33
# File 'lib/sassafras.rb', line 31

def basic(base)
  BasicTheme.new(base)
end

.colorsObject



27
28
29
# File 'lib/sassafras.rb', line 27

def colors
  @colors
end

.complementary(base) ⇒ Object



35
36
37
# File 'lib/sassafras.rb', line 35

def complementary(base)
  ComplementaryTheme.new(base)
end

.create(type, base) ⇒ Object



23
24
25
# File 'lib/sassafras.rb', line 23

def create(type, base)
  Theme.send(type, base)
end

.rectangle(base) ⇒ Object



51
52
53
# File 'lib/sassafras.rb', line 51

def rectangle(base)
  RectangleTheme.new(base)
end

.split_complementary(base) ⇒ Object



47
48
49
# File 'lib/sassafras.rb', line 47

def split_complementary(base)
  SplitComplementaryTheme.new(base)
end

.square(base) ⇒ Object



55
56
57
# File 'lib/sassafras.rb', line 55

def square(base)
  SquareTheme.new(base)
end

.triadic(base) ⇒ Object



43
44
45
# File 'lib/sassafras.rb', line 43

def triadic(base)
  TriadicTheme.new(base)
end

Instance Method Details

#baseObject



76
77
78
# File 'lib/sassafras.rb', line 76

def base 
  @base_rgb.html
end

#colors(name = nil) ⇒ Object



80
81
82
83
# File 'lib/sassafras.rb', line 80

def colors(name=nil)
  return @colors[name.to_s] if name
  @colors
end

#get_bindingObject



97
# File 'lib/sassafras.rb', line 97

def get_binding; binding; end

#sassObject



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sassafras.rb', line 85

def sass
  returning "# Generated by Sassafras\n" do |str|
    colors.each do |set, colors|
      str << "# #{set}\n"
      colors.each do |name, hex|
        str << "!#{set}_#{name} = #{hex}\n"
      end
      str << "\n"
    end
  end
end