Code Monkey home page Code Monkey logo

Comments (5)

Kijewski avatar Kijewski commented on July 22, 2024

That's not possible, but you could simply have a macro in the scope of your #[derive(Template)]:

macro_rules! log_debug {
    ($($tt:tt)*) => {{
        #[cfg(debug_assertions)] {
            ::log::debug!($($tt)*);
        }
    }}
}
{% call log_debug!("debug info here") %}

from askama.

b1ek avatar b1ek commented on July 22, 2024

That's not possible, but you could simply have a macro in the scope of your #[derive(Template)]:

macro_rules! log_debug {
    ($($tt:tt)*) => {{
        #[cfg(debug_assertions)] {
            ::log::debug!($($tt)*);
        }
    }}
}
{% call log_debug!("debug info here") %}

I see, that would do pretty much what i described.

However, in the template i would want to print the info into the template, like this:

<!--
  Memory: 0.2/16GB Available
  Chrome memory usage: 14GB
-->
{% cfg(debug_assertions) %}
    blah blah blah
{% endcfg %}

Is that kind of syntax possible? It is not described anywhere in the docs IIRC. The thing is i want that code to be completely excluded from the production build, as it gets rather massive over time

from askama.

Kijewski avatar Kijewski commented on July 22, 2024

I think this should work:

{% if cfg!(debug_assertions) %}
    blah blah blah
{% endif %}

from askama.

b1ek avatar b1ek commented on July 22, 2024

I think this should work:

{% if cfg!(debug_assertions) %}
    blah blah blah
{% endif %}

Thanks, i will try! Not sure that this will compile out the code tho, but it might work

from askama.

b1ek avatar b1ek commented on July 22, 2024

Yup, that did work and that code is compiled out. Thanks!

from askama.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.