Class: Rad::Template::Context

Inherits:
Object
  • Object
show all
Includes:
Tilt::CompileSite, Tilt::ContextExt
Defined in:
lib/rad/template/_context.rb

Direct Known Subclasses

Controller::Context

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tilt::ContextExt

#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_templateObject

System



7
8
9
# File 'lib/rad/template/_context.rb', line 7

def _tilt_template
  @_tilt_template
end

#content_blockObject

Content Variables



46
47
48
# File 'lib/rad/template/_context.rb', line 46

def content_block
  @content_block
end

#scope_variablesObject

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

Returns:

  • (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_variablesObject



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

Returns:

  • (Boolean)


64
65
66
# File 'lib/rad/template/_context.rb', line 64

def has_content_for? name
  content_variables.include? name.to_s
end

#j(obj) ⇒ Object



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

Returns:

  • (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