Closed jensljungblad closed 5 years ago
The issue here is perhaps that other elements, apart from the root component, would have access to actual functions (helpers) defined on the element, making the API not consistent. Perhaps the component and the element should be seen more as component/element builders somehow? Should element also have a render function? That way you could implement the element in ruby as well.. So element to_s
would run render
which would return @value
by default?
I guess the discrepancy here is that components render by default a partial, while elements currently lack a render altogether.
Also, should elements be instantiated already at component creation?
Another solution would be to just compute a hash when rendering. Never to expose the actual objects in the template.
I think the only reason for the delegation craziness when rendering is because of helpers. Attributes and elements could have their values passed to the template as locals, no need for them to be functions. Only helpers need that. But if helpers are getters only, and calculated at render time, there is no need for them to be passed as functions either.
Without thinking further, either there could be a DSL, or perhaps even simpler: