Sha256: 11d521d0212286c722283165ec455f3b48725ecccffea2dc75dc84f39e351b2d

Contents?: true

Size: 732 Bytes

Versions: 28

Compression:

Stored size: 732 Bytes

Contents

def bake_format(data, output, indent)
  start_line = 0
  end_line = data.lines.count
  bake_format_in_range(data, output, indent, start_line, end_line)
end

def bake_format_in_range(data, output, indent, start_line, end_line)
  indent_level = 0
  data.each_line.with_index do |l, index|
    opening = l.count('{')
    closing = l.count('}')
    old_indent_level = indent_level
    indent_level = indent_level + opening - closing

    prefix =
      if indent_level > old_indent_level
        indent * old_indent_level
      else
        indent * indent_level
      end

    if index.between?(start_line, end_line)
      l = (prefix + l.strip).rstrip
    end

    output.puts(l)
  end
  output.close
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
bake-toolkit-2.72.0 lib/format/bake_format.rb
bake-toolkit-2.71.0 lib/format/bake_format.rb
bake-toolkit-2.70.1 lib/format/bake_format.rb
bake-toolkit-2.70.0 lib/format/bake_format.rb
bake-toolkit-2.69.0 lib/format/bake_format.rb
bake-toolkit-2.68.1 lib/format/bake_format.rb
bake-toolkit-2.68.0 lib/format/bake_format.rb
bake-toolkit-2.67.0 lib/format/bake_format.rb
bake-toolkit-2.66.0 lib/format/bake_format.rb
bake-toolkit-2.65.2 lib/format/bake_format.rb
bake-toolkit-2.65.1 lib/format/bake_format.rb
bake-toolkit-2.65.0 lib/format/bake_format.rb
bake-toolkit-2.64.4 lib/format/bake_format.rb
bake-toolkit-2.64.3 lib/format/bake_format.rb
bake-toolkit-2.64.2 lib/format/bake_format.rb
bake-toolkit-2.64.1 lib/format/bake_format.rb
bake-toolkit-2.64.0 lib/format/bake_format.rb
bake-toolkit-2.63.2 lib/format/bake_format.rb
bake-toolkit-2.63.1 lib/format/bake_format.rb
bake-toolkit-2.63.0 lib/format/bake_format.rb