Class: Shaf::Generator::Helper
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Shaf::Generator::Helper
- Defined in:
- lib/shaf/generator/helper.rb
Instance Method Summary collapse
-
#binding ⇒ Object
public method mapped to Kernel’s private #binding.
- #indentation(level) ⇒ Object (also: #i)
- #print(lines, indent_level = 2) ⇒ Object
- #print_nested(sections, indent_level = 2) ⇒ Object
- #strip_blank(lines) ⇒ Object
Instance Method Details
#binding ⇒ Object
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 |
#print(lines, indent_level = 2) ⇒ Object
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 |
#print_nested(sections, indent_level = 2) ⇒ Object
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 |