본문 바로가기

Geek

Redmine 소스 Tab Width 변경하기.

Redmine에서 제일 신경이 많이 쓰이는 부분중에 하나는 소스보기에서 탭 넓이가 8인 점이다.

구글링 하다 보니 역시 Redmine에서 해당 일감이 올라와 있는데 아직 적용되진 않았다.

무려 4년이 넘게 적용되지 않는 것을 보니 앞으로도 적용할 생각이 없을 것 같아 간단하게 메모하도록 하자.


일단, 해당 이슈에서 정리해놓았듯이,

${REDMINE_ROOT}/lib/redmine/core_ext/string/conversions.rb

파일에 다음의 함수를 추가하도록 하자.

        def expand(tab_width=4)
          text = self.dup
          out = ''
          text.each_line do |line|
            column = 0
            line.each_char do |c|
              if c == "\t" 
                next_tab_column = column + (tab_width - column % tab_width)
                while column < next_tab_column
                  out << " " 
                  column += 1
                end
              elsif c == "\b" 
                column += -1
              else
                column += 1
                out << c
              end
            end
          end
          out
        end


그런 후에,

${REDMINE_ROOT}/app/helpers/application_helper.rb

파일에서 syntax_highlite 함수에서 content 라는 변수를 content.expand(4) 라고 변경하도록 한다.

def syntax_highlight (name, content)
    Redmine::SyntaxHighlighting.highlight_by_filename(content.expand(4), name)
end


Redmine을 재시작하면 소스코드의 Tab Width가 변경된 것을 확인할 수 있다.