mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
Add replace_last and remove_last filters
This commit is contained in:
@@ -268,6 +268,11 @@ module Liquid
|
|||||||
input.to_s.sub(string.to_s, replacement.to_s)
|
input.to_s.sub(string.to_s, replacement.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Replace the last occurrences of a string with another
|
||||||
|
def replace_last(input, string, replacement = '')
|
||||||
|
input.to_s.reserve.sub(string.to_s.reserve, replacement.to_s.reserve).reserve
|
||||||
|
end
|
||||||
|
|
||||||
# remove a substring
|
# remove a substring
|
||||||
def remove(input, string)
|
def remove(input, string)
|
||||||
input.to_s.gsub(string.to_s, '')
|
input.to_s.gsub(string.to_s, '')
|
||||||
@@ -278,6 +283,11 @@ module Liquid
|
|||||||
input.to_s.sub(string.to_s, '')
|
input.to_s.sub(string.to_s, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# remove the last occurences of a substring
|
||||||
|
def remove_last(input, string)
|
||||||
|
input.to_s.reverse.sub(string.to_s.reverse, '').reverse
|
||||||
|
end
|
||||||
|
|
||||||
# add one string to another
|
# add one string to another
|
||||||
def append(input, string)
|
def append(input, string)
|
||||||
input.to_s + string.to_s
|
input.to_s + string.to_s
|
||||||
|
|||||||
Reference in New Issue
Block a user