From 12d047aef0337dcd49ba51a53cc075c695fd65ff Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Tue, 8 Oct 2019 18:14:54 +1100 Subject: [PATCH] document default filter --- lib/liquid/standardfilters.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 0f4a110..6728e57 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -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