Skip to content

Commit

Permalink
contextualize value before invoking to_liquid
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Jan 24, 2024
1 parent 28f31d0 commit 5c8ad2a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ext/liquid_c/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ inline static VALUE value_to_liquid_and_set_context(VALUE value, VALUE context_t
if (klass == rb_cString || klass == rb_cArray || klass == rb_cHash)
return value;

value = rb_funcall(value, id_to_liquid, 0);

// set value's context before invoking #to_liquid
if (rb_respond_to(value, id_set_context))
rb_funcall(value, id_set_context, 1, context_to_set);

return value;
VALUE liquid_value = rb_funcall(value, id_to_liquid, 0);

if (liquid_value != value && rb_respond_to(liquid_value, id_set_context))
rb_funcall(liquid_value, id_set_context, 1, context_to_set);

return liquid_value;
}


Expand Down

0 comments on commit 5c8ad2a

Please sign in to comment.