Class: Sapling::CssGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/sapling/generators/css_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sapling) ⇒ CssGenerator

Returns a new instance of CssGenerator.



7
8
9
# File 'lib/sapling/generators/css_generator.rb', line 7

def initialize(sapling)
  @sapling=sapling
end

Instance Attribute Details

#saplingObject

Returns the value of attribute sapling.



5
6
7
# File 'lib/sapling/generators/css_generator.rb', line 5

def sapling
  @sapling
end

Instance Method Details

#css_class(feature, on) ⇒ Object



15
16
17
# File 'lib/sapling/generators/css_generator.rb', line 15

def css_class(feature, on)
  "#{prefix}_#{feature.to_s}_#{on ? 'on' : 'off'}"
end

#prefixObject



11
12
13
# File 'lib/sapling/generators/css_generator.rb', line 11

def prefix
  "sapling_css"
end

#to_s(options = {}) ⇒ Object

see Sapling::API::Client for options



20
21
22
23
24
25
26
27
28
29
# File 'lib/sapling/generators/css_generator.rb', line 20

def to_s(options={})
  features = Set.new @sapling.features
  active_features = Set.new @sapling.active_features options
  inactive_features = features - active_features

  [
  active_features.collect   {|f|".#{css_class(f, false)} { display:none !important; }"},
  inactive_features.collect {|f|".#{css_class(f, true)} { display:none !important; }"},
  ].flatten.join("\n")
end