Class: Atum::Generation::ErbContext

Inherits:
Erubis::Context
  • Object
show all
Defined in:
lib/atum/generation/erb_context.rb

Instance Method Summary collapse

Instance Method Details

#break_line(line, max_line_length) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/atum/generation/erb_context.rb', line 17

def break_line(line, max_line_length)
  line.split.reduce([]) do |lines, word|
    if lines.empty? || (lines[-1] + " #{word}").size > max_line_length
      lines << word
    else
      lines[-1] << " #{word}" && lines
    end
  end
end

#commentify(comment, tabs) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/atum/generation/erb_context.rb', line 4

def commentify(comment, tabs)
  starter = ('  ' * tabs) + '# '
  max_line_length = 78 - (tabs * 2)
  comment.split("\n")
    .flat_map { |l| break_line(l, max_line_length) }
    .map { |l| starter + l.strip }
    .join("\n")
end

#method(name, params) ⇒ Object



13
14
15
# File 'lib/atum/generation/erb_context.rb', line 13

def method(name, params)
  "#{name}" + (params.length > 0 ? "(#{params})" : '')
end