Sha256: c57ac23edfd52f583c35628d6566cc0ed3c1c209b10b705ee74707253bda3af3
Contents?: true
Size: 869 Bytes
Versions: 13
Compression:
Stored size: 869 Bytes
Contents
# -*- coding: utf-8; mode: ruby; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 # -*- vim:fenc=utf-8:filetype=ruby:et:sw=2:ts=2:sts=2 # Provides content escaping helpers. module GitCommitNotifier::EscapeHelper # Expand tabs into spaces. # @param [String] s Text to be expanded. # @param [FixNum] tabWidth One tab indentation (in count of spaces). # @return [String] Expanded text. 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 # Escapes expanded content using CGI.escapeHTML and {#expand_tabs}. # @param [String] s Text to be expanded and extended. # @return [String] Escaped and expanded text. # @see #expand_tabs def escape_content(s) CGI.escapeHTML(expand_tabs(s, 4)).gsub(" ", " ") end end
Version data entries
13 entries across 13 versions & 1 rubygems