Class: Cat::SkinNode

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

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ SkinNode

Returns a new instance of SkinNode.



16
17
18
19
20
# File 'lib/cat/skin_node.rb', line 16

def initialize(name, &block)
  @name = name
  @styles = ["box-sizing: border-box;"]
  instance_eval(&block) if block_given?
end

Instance Method Details

#animation(name = :rotating) ⇒ Object



81
82
83
84
# File 'lib/cat/skin_node.rb', line 81

def animation(name = :rotating)
  @styles << Style::Animation.new(name)
  self
end

#centerObject



36
37
38
39
# File 'lib/cat/skin_node.rb', line 36

def center
  @styles << Style::Center.new
  self
end

#clip(mode = true) ⇒ Object



61
62
63
64
# File 'lib/cat/skin_node.rb', line 61

def clip(mode = true)
  @styles << Style::Clip.new
  self
end

#ellipseObject



26
27
28
29
# File 'lib/cat/skin_node.rb', line 26

def ellipse
  @styles << Style::Ellipse.new
  self
end

#expand(with: []) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/cat/skin_node.rb', line 90

def expand(with: [])
  %{
.#{@name} {
  #{to_s}
  #{include_children(with)}
}
  }
end

#fill(color) ⇒ Object



31
32
33
34
# File 'lib/cat/skin_node.rb', line 31

def fill(color)
  @styles << Style::Fill.new(color)
  self
end

#include_children(items) ⇒ Object



22
23
24
# File 'lib/cat/skin_node.rb', line 22

def include_children(items)
  items.map { |node| node.skin }.join("\n")
end

#mask(size) ⇒ Object



51
52
53
54
# File 'lib/cat/skin_node.rb', line 51

def mask(size)
  @styles << Style::Mask.new(size)
  self
end

#offset(amount, direction = :top) ⇒ Object



71
72
73
74
# File 'lib/cat/skin_node.rb', line 71

def offset(amount, direction = :top)
  @styles << Style::Offset.new(amount, direction)
  self
end

#position(top: nil, right: nil, bottom: nil, left: nil) ⇒ Object



66
67
68
69
# File 'lib/cat/skin_node.rb', line 66

def position(top: nil, right: nil, bottom: nil, left: nil)
  @styles << Style::Position.new(top: top, right: right, bottom: bottom, left: left)
  self
end

#rotate(deg) ⇒ Object



56
57
58
59
# File 'lib/cat/skin_node.rb', line 56

def rotate(deg)
  @styles << Style::Rotate.new(deg)
  self
end

#rounded(top: nil, right: nil, bottom: nil, left: nil) ⇒ Object



76
77
78
79
# File 'lib/cat/skin_node.rb', line 76

def rounded(top: nil, right: nil, bottom: nil, left: nil)
  @styles << Style::Rounded.new(top: top, right: right, bottom: bottom, left: left)
  self
end

#size(width, height = nil) ⇒ Object



41
42
43
44
# File 'lib/cat/skin_node.rb', line 41

def size(width, height = nil)
  @styles << Style::Size.new(width, height)
  self
end

#stroke(width = nil, color: nil, only: [:top, :right, :bottom, :left]) ⇒ Object



46
47
48
49
# File 'lib/cat/skin_node.rb', line 46

def stroke(width = nil, color: nil, only: [:top, :right, :bottom, :left])
  @styles << Style::Stroke.new(width, color, only)
  self
end

#to_sObject



86
87
88
# File 'lib/cat/skin_node.rb', line 86

def to_s
  @styles.join("\n")
end