Class: Rad::Template::Context
Instance Attribute Summary collapse
Instance Method Summary
collapse
#capture, #concat, #output
Constructor Details
#initialize(instance_variables = nil) ⇒ Context
Returns a new instance of Context.
9
10
11
|
# File 'lib/rad/template/_context.rb', line 9
def initialize instance_variables = nil
set_instance_variables! instance_variables if instance_variables
end
|
Instance Attribute Details
#_tilt_template ⇒ Object
7
8
9
|
# File 'lib/rad/template/_context.rb', line 7
def _tilt_template
@_tilt_template
end
|
#content_block ⇒ Object
46
47
48
|
# File 'lib/rad/template/_context.rb', line 46
def content_block
@content_block
end
|
#scope_variables ⇒ Object
for saving :format, :current_dir and others
14
15
16
|
# File 'lib/rad/template/_context.rb', line 14
def scope_variables
@scope_variables
end
|
Instance Method Details
#blank?(obj) ⇒ Boolean
35
36
37
|
# File 'lib/rad/template/_context.rb', line 35
def blank? obj
obj.is_a?(String) ? !!(obj =~ /\A\s*\z/) : obj.blank?
end
|
#content_for(name, content = nil, &block) ⇒ Object
48
49
50
51
52
|
# File 'lib/rad/template/_context.rb', line 48
def content_for name, content = nil, &block
content ||= capture(&block)
(content_variables[name.to_s] ||= "") << content
nil
end
|
#content_variables ⇒ Object
47
|
# File 'lib/rad/template/_context.rb', line 47
def content_variables; @content_variables ||= {}.to_openobject end
|
#find_relative_template(*args) ⇒ Object
68
69
70
|
# File 'lib/rad/template/_context.rb', line 68
def find_relative_template *args
self.class.find_relative_template *args
end
|
#has_content_for?(name) ⇒ Boolean
64
65
66
|
# File 'lib/rad/template/_context.rb', line 64
def has_content_for? name
content_variables.include? name.to_s
end
|
31
32
33
|
# File 'lib/rad/template/_context.rb', line 31
def j obj
obj.to_s.json_escape
end
|
#prepend_to(name, content = nil, &block) ⇒ Object
53
54
55
56
57
|
# File 'lib/rad/template/_context.rb', line 53
def prepend_to name, content = nil, &block
content ||= capture(&block)
(content_variables[name.to_s] ||= "").insert 0, content
nil
end
|
#present?(obj) ⇒ Boolean
38
39
40
|
# File 'lib/rad/template/_context.rb', line 38
def present? obj
!blank?(obj)
end
|
#wrap_content_for(name, &block) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/rad/template/_context.rb', line 58
def wrap_content_for name, &block
block.must_be.defined
content = capture((content_variables[name.to_s] || ""), &block)
content_variables[name.to_s] ||= content
nil
end
|