@@ -113,24 +113,63 @@ def inspect
113113
114114 def equal_variables ( left , right )
115115 if left . is_a? ( MethodLiteral )
116- if right . respond_to? ( left . method_name )
117- return right . send ( left . method_name )
118- else
119- return nil
120- end
116+ return call_method_literal ( left , right )
121117 end
122118
123119 if right . is_a? ( MethodLiteral )
124- if left . respond_to? ( right . method_name )
125- return left . send ( right . method_name )
126- else
127- return nil
128- end
120+ return call_method_literal ( right , left )
129121 end
130122
131123 left == right
132124 end
133125
126+ def call_method_literal ( literal , value )
127+ method_name = literal . method_name
128+
129+ # If the object responds to the method, use it
130+ if value . respond_to? ( method_name )
131+ return value . send ( method_name )
132+ end
133+
134+ # Implement blank?/empty? for common types that don't have it
135+ # (ActiveSupport adds these, but Liquid should work without it)
136+ case method_name
137+ when :blank?
138+ liquid_blank? ( value )
139+ when :empty?
140+ liquid_empty? ( value )
141+ end
142+ end
143+
144+ # Implement blank? semantics matching ActiveSupport
145+ def liquid_blank? ( value )
146+ case value
147+ when NilClass , FalseClass
148+ true
149+ when TrueClass , Numeric
150+ false
151+ when String
152+ # Blank if empty or whitespace only
153+ value . empty? || value . match? ( /\A \s *\z / )
154+ when Array , Hash
155+ value . empty?
156+ else
157+ # Fall back to empty? if available, otherwise false
158+ value . respond_to? ( :empty? ) ? value . empty? : false
159+ end
160+ end
161+
162+ # Implement empty? semantics
163+ # Note: nil is NOT empty (but IS blank). empty? checks if a collection has zero elements.
164+ def liquid_empty? ( value )
165+ case value
166+ when String , Array , Hash
167+ value . empty?
168+ else
169+ value . respond_to? ( :empty? ) ? value . empty? : false
170+ end
171+ end
172+
134173 def interpret_condition ( left , right , op , context )
135174 # If the operator is empty this means that the decision statement is just
136175 # a single variable. We can just poll this variable from the context and
@@ -154,8 +193,8 @@ def interpret_condition(left, right, op, context)
154193 end
155194
156195 def deprecated_default_context
157- warn ( "DEPRECATION WARNING: Condition#evaluate without a context argument is deprecated" \
158- " and will be removed from Liquid 6.0.0." )
196+ warn ( "DEPRECATION WARNING: Condition#evaluate without a context argument is deprecated " \
197+ "and will be removed from Liquid 6.0.0." )
159198 Context . new
160199 end
161200
0 commit comments