Module: GitCommitNotifier::EscapeHelper

Included in:
DiffToHtml, ResultProcessor
Defined in:
lib/git_commit_notifier/escape_helper.rb

Overview

Provides content escaping helpers.

Instance Method Summary collapse

Instance Method Details

#decode_escaped_filename(filename) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/git_commit_notifier/escape_helper.rb', line 27

def decode_escaped_filename( filename )
  filename.gsub( /\\\d\d\d\\\d\d\d/ ) { |match|
    mb_char_code  = match.split( '\\' )[ 1, 2 ]
    mb_char_code.map! { |x| x.oct }
    mb_char_code.pack( 'C*' ).force_encoding( 'UTF-8')
  }
end

#escape_content(s) ⇒ String

Escapes expanded content using CGI.escapeHTML and #expand_tabs.

Parameters:

  • s (String)

    Text to be expanded and extended.

Returns:

  • (String)

    Escaped and expanded text.

See Also:



23
24
25
# File 'lib/git_commit_notifier/escape_helper.rb', line 23

def escape_content(s)
  CGI.escapeHTML(expand_tabs(s, 4)).gsub(" ", " ")
end

#expand_tabs(s, tabWidth) ⇒ String

Expand tabs into spaces.

Parameters:

  • s (String)

    Text to be expanded.

  • tabWidth (FixNum)

    One tab indentation (in count of spaces).

Returns:

  • (String)

    Expanded text.



10
11
12
13
14
15
16
17
# File 'lib/git_commit_notifier/escape_helper.rb', line 10

def expand_tabs(s, tabWidth)
  delta = 0
  s.gsub(/\t/) do |m|
    add = tabWidth - (delta + $~.offset(0)[0]) % tabWidth
    delta += add - 1
    " " * add
  end
end