Class: FlavourSaver::Helpers::Defaults

Inherits:
Object
  • Object
show all
Defined in:
lib/flavour_saver/helpers.rb

Direct Known Subclasses

Decorator

Instance Method Summary collapse

Instance Method Details

#each(collection) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/flavour_saver/helpers.rb', line 10

def each(collection)
  r = []
  count = 0
  collection.each do |element|
    locals ={
      'index' => count,
      'last' => count == collection.size - 1,
      'first' => count == 0
    }

    locals['key'], element = element if collection.is_a?(Hash)

    r << yield.contents(element, locals)
    count += 1
  end
  yield.rendered!
  r.join ''
end

#if(value) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/flavour_saver/helpers.rb', line 29

def if(value)
  if truthy?(value)
    yield.contents
  else
    yield.inverse
  end
end

#log(message) ⇒ Object



45
46
47
48
# File 'lib/flavour_saver/helpers.rb', line 45

def log(message)
  FS.logger.debug("FlavourSaver: #{message}")
  ''
end

#thisObject



41
42
43
# File 'lib/flavour_saver/helpers.rb', line 41

def this
  @source || self
end

#unless(value, &b) ⇒ Object



37
38
39
# File 'lib/flavour_saver/helpers.rb', line 37

def unless(value, &b)
  self.if(!truthy?(value), &b)
end

#with(args) ⇒ Object



6
7
8
# File 'lib/flavour_saver/helpers.rb', line 6

def with(args)
  yield.contents args
end