简体   繁体   中英

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 (eg, 768px) into a relative value (eg, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM