forked from github/developer.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.rb
More file actions
28 lines (23 loc) · 664 Bytes
/
strings.rb
File metadata and controls
28 lines (23 loc) · 664 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'active_support/core_ext/string'
module GitHub
module Strings
# taken from Liquid: http://git.io/vBNqH
def strip_html(str)
str.to_s.gsub(%r{<script.*?</script>}m, '') \
.gsub(/<!--.*?-->/m, '') \
.gsub(%r{<style.*?</style>}m, '') \
.gsub(/<.*?>/m, '')
end
# taken from Rails: http://git.io/vBNcY
def squish(str)
str.gsub(/[[:space:]]+/, ' ').strip
end
def escape_quoted_characters(str)
str.gsub('\\', '\\\\\\').gsub('"', '\"')
end
def clean_for_json(str)
strip_html(squish(escape_quoted_characters(str)))
end
end
end
include GitHub::Strings