document default filter

This commit is contained in:
Mike Angell
2019-10-08 18:14:54 +11:00
parent c109615da7
commit 12d047aef0

View File

@@ -421,6 +421,16 @@ module Liquid
result.is_a?(BigDecimal) ? result.to_f : result
end
# Set a default value when the input is nil, false or empty
#
# Example:
# {{ product.title | default: "No Title" }}
#
# Use `allow_false` when an input should only be tested against nil or empty and not false.
#
# Example:
# {{ product.title | default: "No Title", allow_false: true }}
#
def default(input, default_value = '', options = {})
options = {} unless options.is_a?(Hash)
false_check = options['allow_false'] ? input.nil? : !input