Class: Shaf::Generator::Helper

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/shaf/generator/helper.rb

Instance Method Summary collapse

Instance Method Details

#bindingObject

public method mapped to Kernel’s private #binding



7
8
9
# File 'lib/shaf/generator/helper.rb', line 7

def binding
  super
end

#indentation(level) ⇒ Object Also known as: i



28
29
30
# File 'lib/shaf/generator/helper.rb', line 28

def indentation(level)
  ' ' * level
end


11
12
13
14
15
16
# File 'lib/shaf/generator/helper.rb', line 11

def print(lines, indent_level = 2)
  strip_blank(lines).inject do |result, line|
    indent = i(indent_level) unless line.empty?
    result + "\n#{indent}#{line}"
  end.chomp
end


18
19
20
# File 'lib/shaf/generator/helper.rb', line 18

def print_nested(sections, indent_level = 2)
  sections.map(&method(:print)).join("\n\n#{i(indent_level)}")
end

#strip_blank(lines) ⇒ Object



22
23
24
25
26
# File 'lib/shaf/generator/helper.rb', line 22

def strip_blank(lines)
  lines.map do |line|
    line.strip.empty? ? '' : line
  end
end