Class: Sassy::SCSS::Rule

Inherits:
Object
  • Object
show all
Includes:
IsSCSS
Defined in:
lib/sassy/scss/rule.rb

Instance Method Summary collapse

Methods included from IsSCSS

included

Constructor Details

#initialize(selector, &block) ⇒ Rule

Returns a new instance of Rule.

Raises:

  • (ArgumentError)


10
11
12
13
14
# File 'lib/sassy/scss/rule.rb', line 10

def initialize(selector, &block)
  raise ArgumentError if selector.blank?
  @selector = selector
  instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



42
43
44
45
46
47
48
# File 'lib/sassy/scss/rule.rb', line 42

def method_missing(method, *args, &block)
  if block_given?
    r(method, &block)
  else
    d(method.to_s.gsub('_', '-'), args[0])
  end
end

Instance Method Details

#d(property, value) ⇒ Object



28
29
30
# File 'lib/sassy/scss/rule.rb', line 28

def d(property, value)
  declarations.add(property, value)
end

#declarationsObject



16
17
18
# File 'lib/sassy/scss/rule.rb', line 16

def declarations
  @declarations ||= DeclarationSet.new
end

#r(selector, &block) ⇒ Object



24
25
26
# File 'lib/sassy/scss/rule.rb', line 24

def r(selector, &block)
  rules.add(selector, &block)
end

#rulesObject



20
21
22
# File 'lib/sassy/scss/rule.rb', line 20

def rules
  @rules ||= RuleSet.new
end

#to_scssObject



32
33
34
35
36
37
38
# File 'lib/sassy/scss/rule.rb', line 32

def to_scss
  a = ["#{@selector} {"]
  a << declarations.to_scss unless declarations.empty?
  a << rules.to_scss unless rules.empty?
  a << "}"
  a.join(" ")
end