Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In tritium, how can I do math operations?

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?

like image 879
fegemo Avatar asked Nov 26 '25 04:11

fegemo


1 Answers

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.

like image 140
noj Avatar answered Nov 27 '25 22:11

noj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!