|
|
@ -79,6 +79,33 @@ module OctopressLiquidFilters
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Improved version of Liquid's truncate:
|
|
|
|
|
|
|
|
# - Doesn't cut in the middle of a word.
|
|
|
|
|
|
|
|
# - Uses typographically correct ellipsis (…) insted of '...'
|
|
|
|
|
|
|
|
def truncate(input, length)
|
|
|
|
|
|
|
|
if input.length > length && input[0..(length-1)] =~ /(.+)\b.+$/im
|
|
|
|
|
|
|
|
$1.strip + ' …'
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
input
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Improved version of Liquid's truncatewords:
|
|
|
|
|
|
|
|
# - Uses typographically correct ellipsis (…) insted of '...'
|
|
|
|
|
|
|
|
def truncatewords(input, length)
|
|
|
|
|
|
|
|
truncate = input.split(' ')
|
|
|
|
|
|
|
|
if truncate.length > length
|
|
|
|
|
|
|
|
truncate[0..length-1].join(' ').strip + ' …'
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
input
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Condenses multiple spaces and tabs into a single space
|
|
|
|
|
|
|
|
def condense_spaces(input)
|
|
|
|
|
|
|
|
input.gsub(/\s{2,}/, ' ')
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Removes trailing forward slash from a string for easily appending url segments
|
|
|
|
# Removes trailing forward slash from a string for easily appending url segments
|
|
|
|
def strip_slash(input)
|
|
|
|
def strip_slash(input)
|
|
|
|
if input =~ /(.+)\/$|^\/$/
|
|
|
|
if input =~ /(.+)\/$|^\/$/
|
|
|
|