2020-09-10 00:28:10 +02:00
|
|
|
module UtilHelper
|
|
|
|
def truncate(string, max=20, delim=" ")
|
|
|
|
parts = string.split(delim)
|
|
|
|
parts.length > max ?
|
|
|
|
parts[0..max].join(delim) + "..." : string
|
|
|
|
end
|
|
|
|
|
|
|
|
def make_some(string, backup=" ")
|
|
|
|
string.strip().length > 0 ? string : backup
|
|
|
|
end
|
2020-09-10 12:13:46 +02:00
|
|
|
|
|
|
|
def text_segment(string, max=20, delim=" ")
|
|
|
|
make_some(truncate(string.gsub(/<\/?[^>]*>/, ""), max, delim))
|
|
|
|
end
|
2020-09-10 00:28:10 +02:00
|
|
|
end
|