Module: Forger::Template::Helper::PartialHelper

Included in:
Forger::Template::Helper
Defined in:
lib/forger/template/helper/partial_helper.rb

Instance Method Summary collapse

Instance Method Details

#indent(text, indentation_amount) ⇒ Object

add indentation



34
35
36
37
38
# File 'lib/forger/template/helper/partial_helper.rb', line 34

def indent(text, indentation_amount)
  text.split("\n").map do |line|
    " " * indentation_amount + line
  end.join("\n")
end

#partial(path, vars = {}, options = {}) ⇒ Object

The partial’s path is a relative path given without the extension and

Example: Given: file in app/partials/mypartial.sh The path should be: mypartial

If the user specifies the extension then use that instead of auto-adding the detected format.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/forger/template/helper/partial_helper.rb', line 16

def partial(path,vars={}, options={})
  path = partial_path_for(path)
  path = auto_add_format(path)

  result = RenderMePretty.result(path, context: self)
  result = indent(result, options[:indent]) if options[:indent]
  if options[:indent]
    # Add empty line at beginning because empty lines gets stripped during
    # processing anyway. This allows the user to call partial without having
    # to put the partial call at very beginning of the line.
    # This only should happen if user is using indent option.
    ["\n", result].join("\n")
  else
    result
  end
end

#partial_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
5
6
# File 'lib/forger/template/helper/partial_helper.rb', line 2

def partial_exist?(path)
  path = partial_path_for(path)
  path = auto_add_format(path)
  path && File.exist?(path)
end