lib/onebox/mixins/git_blob_onebox.rb
def removeLeadingIndentation(str)
          min_space = 100
          a_lines = str.lines
          a_lines.each do |l|
            l = l.chomp("\n")  # remove new line
            m = l.match(/^[ ]*/) # find leading spaces 0 or more
            unless m.nil? || l.size == m[0].size || m[0].size == 0 # no match | only spaces in line | empty line
              m_str_length = m[0].size
              if m_str_length <= 1  # minimum space is 1 or nothing we can break we found our minimum
                min_space = m_str_length
                break #stop iteration
              end
              if m_str_length < min_space
                min_space = m_str_length
              end
            else
              next # SKIP no match or line is only spaces
            end
          end
          a_lines.each do |l|
            re = Regexp.new "^[ ]{#{min_space}}"  #match the minimum spaces of the line
            l.gsub!(re, "")
          end
          a_lines.join
        end
#minimize/compact leading indentation while preserving overall indentation
minimize/compact leading indentation while preserving overall indentation
minimize / compact leading indentation while preserving overall indentation
def removeLeadingIndentation(str)
          min_space = 100
          a_lines = str.lines
          a_lines.each do |l|
            l = l.chomp("\n")  
            m = l.match(/^[ ]*/) 
            unless m.nil? || l.size == m[0].size || m[0].size == 0 
              m_str_length = m[0].size
              if m_str_length <= 1  
                min_space = m_str_length
                break 
              end
              if m_str_length < min_space
                min_space = m_str_length
              end
            else
              next 
            end
          end
          a_lines.each do |l|
            re = Regexp.new "^[ ]{#{min_space}}"  
            l.gsub!(re, "")
          end
          a_lines.join
        end
def removeLeadingIndentation ( str ) min_space = 100 a_lines = str . lines a_lines . each do | l | l = l . chomp ( "\n" ) m = l . match ( / ^[ ]* / ) unless m . nil? || l . size == m [ 0 ] . size || m [ 0 ] . size == 0 m_str_length = m [ 0 ] . size if m_str_length <= 1 min_space = m_str_length break end if m_str_length < min_space min_space = m_str_length end else next end end a_lines . each do | l | re = Regexp . new "^[ ]{#{min_space}}" l . gsub! ( re , "" ) end a_lines . join end
minimize/compact leading indentation while preserving overall indentation
minimize / compact leading indentation while preserving overall indentation
# remove new line # find leading spaces 0 or more # no match | only spaces in line | empty line # minimum space is 1 or nothing we can break we found our minimum #stop iteration # SKIP no match or line is only spaces #match the minimum spaces of the line
str