I am transforming a website that contains elements with inline styles with fixed width and heights in pixels, like this:
<div id="row1_column1" class="one-column" style="width:728px;height:1px;">
...
</div>
I would like to create a function that transforms a fixed pixel dimension (e.g., 768px) into a relative value (e.g., 75%) based on a maximum value. I would like to write it this way:
@func XMLNode.relativize_fixed_dimensions(Number %full_width, Number %full_height) {
attribute("style") {
value() {
replace(/width:\s*(\d)+px/) {
set(concat("width:", (%1 / %full_width), "%"))
}
replace(/height:\s*(\d)+px/) {
set(concat("height:", (%1 / %full_height), "%"))
}
}
}
}
However, as per the moovweb documentation, there is no type such as Number, and no operators such as / either.
What I'd like to know is: is it possible to do mathematical transformations in tritium so I can achieve what I need?
Unfortunately, there's no way to do this as of today. There is no way to perform a numerical expression on tritium. I believe this is in the roadmap for the future, but not sure when it would become a feature.
What I would suggest is to implement the change using javascript for now.