I have a 'widget' that comprises an html/css block of code. It is a type of data layout, which I call the 'stack'.
The stack has bits of .erb
(Ruby on Rails) embedded in it, which enters the data for each user.
I need to include this stack in multiple places, where it needs to represent different data from different models.
So, one stack might contain a field called @company.name
and the other stack might contain @project.name || "Unidentified Project"
.
How does one refactor / organize this situation? Options that I can see:
- Have two separate
stacks
, which would introduce redundancy and inconsistency, but would be an obvious answer to the problem without limit to scenario-specific customization. - Include
if
statements for every data point to test which circumstance the stack is being used for, but this is very code-ugly and unsustainably complicated for more than 2 stacks. - Some unknown unknown.
How would you tackle this?