Class: Remarkably::Engines::CSS
Instance Attribute Summary
Attributes inherited from Base::Engine
#remarkably_engine
Instance Method Summary
collapse
-
#clear! ⇒ Object
-
#css_class(args, hash, &block) ⇒ Object
-
#css_id(args, hash, &block) ⇒ Object
-
#css_prefix(prefix, &block) ⇒ Object
-
#css_pseudo(args, hash, &block) ⇒ Object
-
#method!(sym, args, hash, &block) ⇒ Object
-
#to_s ⇒ Object
#initialize, #method_missing, #missing_method
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Remarkably::Base::Engine
Instance Method Details
#clear! ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/remarkably/engines/css.rb', line 60
def clear!
super
@css_prefix=''
@css_depth=0
@css_prefix_rendered=false
@css_first_use=true
end
|
#css_class(args, hash, &block) ⇒ Object
44
45
46
|
# File 'lib/remarkably/engines/css.rb', line 44
def css_class args, hash, &block
css_prefix ".", &block
end
|
#css_id(args, hash, &block) ⇒ Object
48
49
50
|
# File 'lib/remarkably/engines/css.rb', line 48
def css_id args, hash, &block
css_prefix "#", &block
end
|
#css_prefix(prefix, &block) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/remarkably/engines/css.rb', line 37
def css_prefix prefix, &block
@css_prefix << prefix
block.call
@css_prefix.chop!
self
end
|
#css_pseudo(args, hash, &block) ⇒ Object
52
53
54
|
# File 'lib/remarkably/engines/css.rb', line 52
def css_pseudo args, hash, &block
css_prefix ":", &block
end
|
#method!(sym, args, hash, &block) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/remarkably/engines/css.rb', line 6
def method! sym, args, hash, &block
sym = sym.to_s.downcase
sym = "##{sym}".chop if sym[-1].chr == '!'
sym = ".#{sym}".chop if sym[-1].chr == '?'
if block_given?
current_prefix = @css_prefix
@css_prefix = (@css_prefix+"#{sym}#{args.map{|a|a.to_s}.join} ")
@css_depth+=1
@css_prefix_rendered=false
block.call
@css_depth-=1
@css_prefix = current_prefix
else
unless @css_prefix_rendered
unless @css_first_use
@output.chop!
@output << "}"
end
@output << "\n#{@css_prefix}{"
@css_prefix_rendered = true
@css_first_use = false
end
@output << "#{sym.to_s.split('').map{|n|n=='_' ? '-' : n}.join('')}:#{args.map{|a|a.to_s}.join(' ')};"
end
self
end
|
#to_s ⇒ Object
56
57
58
|
# File 'lib/remarkably/engines/css.rb', line 56
def to_s
"#{super.chop}}".strip+"\n"
end
|