Class: Slim::LogicLess::Context Private

Inherits:
Object
  • Object
show all
Defined in:
lib/slim/logic_less/context.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Scope

Instance Method Summary collapse

Constructor Details

#initialize(dict, lookup) ⇒ Context

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Context.



6
7
8
# File 'lib/slim/logic_less/context.rb', line 6

def initialize(dict, lookup)
  @scope = [Scope.new(dict, lookup)]
end

Instance Method Details

#[](name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/slim/logic_less/context.rb', line 10

def [](name)
  scope[name]
end

#inverted_section(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
47
# File 'lib/slim/logic_less/context.rb', line 44

def inverted_section(name)
  value = scope[name]
  yield if !value || (value.respond_to?(:empty?) && value.empty?)
end

#lambda(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/slim/logic_less/context.rb', line 14

def lambda(name)
  scope.lambda(name) do |*dict|
    if dict.empty?
      yield
    else
      new_scope do
        dict.inject(''.dup) do |result, d|
          scope.dict = d
          result << yield
        end
      end
    end
  end
end

#section(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/slim/logic_less/context.rb', line 29

def section(name)
  if dict = scope[name]
    if !dict.respond_to?(:has_key?) && dict.respond_to?(:each)
      new_scope do
        dict.each do |d|
          scope.dict = d
          yield
        end
      end
    else
      new_scope(dict) { yield }
    end
  end
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
# File 'lib/slim/logic_less/context.rb', line 49

def to_s
  scope.to_s
end