Class: Ruby2sass::Renderer
- Inherits:
-
Object
- Object
- Ruby2sass::Renderer
show all
- Defined in:
- lib/ruby2sass/renderer.rb
Instance Method Summary
collapse
-
#each_loop(variable, list, &block) ⇒ Object
-
#else_statement(&block) ⇒ Object
-
#extend(selector) ⇒ Object
-
#for_loop(variable, from:, to:, &block) ⇒ Object
-
#function(name, *args, &block) ⇒ Object
-
#if_statement(condition, &block) ⇒ Object
-
#import(path) ⇒ Object
-
#include(name, *args) ⇒ Object
-
#initialize(&block) ⇒ Renderer
constructor
A new instance of Renderer.
-
#keyframes(name, &block) ⇒ Object
-
#media(*args, &block) ⇒ Object
-
#method_missing(method_name, *args) ⇒ Object
-
#mixin(name, *args, &block) ⇒ Object
-
#raw(sass_content) ⇒ Object
-
#return(value) ⇒ Object
-
#s(selector, &block) ⇒ Object
-
#to_css(include: nil, compress: false) ⇒ Object
-
#to_sass ⇒ Object
-
#v(name, value) ⇒ Object
-
#while_loop(condition, &block) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Renderer
Returns a new instance of Renderer.
5
6
7
8
9
10
|
# File 'lib/ruby2sass/renderer.rb', line 5
def initialize(&block)
@output = StringIO.new
@indentation = 0
@input_block = block
@variables = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
154
155
156
157
158
|
# File 'lib/ruby2sass/renderer.rb', line 154
def method_missing(method_name, *args)
property = method_name.to_s.tr('_', '-')
value = args.first
write_line("#{property}: #{value};")
end
|
Instance Method Details
#each_loop(variable, list, &block) ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/ruby2sass/renderer.rb', line 110
def each_loop(variable, list, &block)
write_line("@each $#{variable} in #{list} {")
indent
instance_eval(&block) if block_given?
dedent
write_line('}')
end
|
#else_statement(&block) ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/ruby2sass/renderer.rb', line 94
def else_statement(&block)
write_line('@else {')
indent
instance_eval(&block) if block_given?
dedent
write_line('}')
end
|
#extend(selector) ⇒ Object
82
83
84
|
# File 'lib/ruby2sass/renderer.rb', line 82
def extend(selector)
write_line("@extend #{selector};")
end
|
#for_loop(variable, from:, to:, &block) ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/ruby2sass/renderer.rb', line 102
def for_loop(variable, from:, to:, &block)
write_line("@for $#{variable} from #{from} through #{to} {")
indent
instance_eval(&block) if block_given?
dedent
write_line('}')
end
|
#function(name, *args, &block) ⇒ Object
126
127
128
129
130
131
132
133
|
# File 'lib/ruby2sass/renderer.rb', line 126
def function(name, *args, &block)
args_str = args.empty? ? '' : "(#{args.join(', ')})"
write_line("@function #{name}#{args_str} {")
indent
instance_eval(&block) if block_given?
dedent
write_line('}')
end
|
#if_statement(condition, &block) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/ruby2sass/renderer.rb', line 86
def if_statement(condition, &block)
write_line("@if #{condition} {")
indent
instance_eval(&block) if block_given?
dedent
write_line('}')
end
|
#import(path) ⇒ Object
78
79
80
|
# File 'lib/ruby2sass/renderer.rb', line 78
def import(path)
write_line("@import '#{path}';")
end
|
#include(name, *args) ⇒ Object
67
68
69
70
|
# File 'lib/ruby2sass/renderer.rb', line 67
def include(name, *args)
args_str = args.empty? ? '' : "(#{args.join(', ')})"
write_line("@include #{name}#{args_str};")
end
|
#keyframes(name, &block) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/ruby2sass/renderer.rb', line 50
def keyframes(name, &block)
write_line("@keyframes #{name} {")
indent
instance_eval(&block) if block_given?
dedent
write_line('}')
end
|
42
43
44
45
46
47
48
|
# File 'lib/ruby2sass/renderer.rb', line 42
def media(*args, &block)
write_line("@media #{args.join(' ')} {")
indent
instance_eval(&block) if block_given?
dedent
write_line('}')
end
|
#mixin(name, *args, &block) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/ruby2sass/renderer.rb', line 58
def mixin(name, *args, &block)
args_str = args.empty? ? '' : "(#{args.join(', ')})"
write_line("@mixin #{name}#{args_str} {")
indent
instance_eval(&block) if block_given?
dedent
write_line('}')
end
|
#raw(sass_content) ⇒ Object
139
140
141
|
# File 'lib/ruby2sass/renderer.rb', line 139
def raw(sass_content)
@output << sass_content
end
|
#return(value) ⇒ Object
135
136
137
|
# File 'lib/ruby2sass/renderer.rb', line 135
def return(value)
write_line("@return #{value};")
end
|
#s(selector, &block) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/ruby2sass/renderer.rb', line 30
def s(selector, &block)
write_line("#{selector} {")
indent
if block.arity == 1
block.call(SelectorContext.new(self))
else
instance_eval(&block)
end
dedent
write_line('}')
end
|
#to_css(include: nil, compress: false) ⇒ Object
150
151
152
|
# File 'lib/ruby2sass/renderer.rb', line 150
def to_css(include: nil, compress: false)
Ruby2sass::CssRender.new(to_sass, include, compress).render
end
|
#to_sass ⇒ Object
143
144
145
146
147
148
|
# File 'lib/ruby2sass/renderer.rb', line 143
def to_sass
return @sass_output if @sass_output
instance_eval(&@input_block) if @input_block
@sass_output = @output.string
end
|
#v(name, value) ⇒ Object
72
73
74
75
76
|
# File 'lib/ruby2sass/renderer.rb', line 72
def v(name, value)
@variables[name] = "$#{name}"
write_line("$#{name}: #{value};")
@variables[name]
end
|
#while_loop(condition, &block) ⇒ Object
118
119
120
121
122
123
124
|
# File 'lib/ruby2sass/renderer.rb', line 118
def while_loop(condition, &block)
write_line("@while #{condition} {")
indent
instance_eval(&block) if block_given?
dedent
write_line('}')
end
|