Giter Club home page Giter Club logo

Comments (8)

inducer avatar inducer commented on May 25, 2024

This is a good idea. At the same time, I am wondering where these default macros (or really code snippets to be included by default) should live. The obvious solution would be to have a "magical" file somewhere in the git repository that gets included by default. I am little bit worried about the discoverability of this approach, however. For example, since relate already integrates information from the repository and the database, there is a bit of a feel that information just gets pulled "at random" from various sources. This would add one more layer of that. Any suggestions/thoughts?

from relate.

dzhuang avatar dzhuang commented on May 25, 2024

Sorry for my tentative suggestion. I had previously imagine if we can add something like allowed attribute (list type) in the course.yml above chunks, which will be treated as a global attribute when rendering the pages. Something like:

name: Sample Course
number: CS123
run: Fall 2014
default_macro:
    - {% from foo.jinja import bar1, bar2 %}
    - {% from foo2.jinja import bar3, bar4 %}

chunks:

However, I must admit that I do not fully grasp Django, Jinja2 and the mechanism of Relate, the idea is not mature or totally not applicable.

BTW: Maybe this article is helpful.

from relate.

inducer avatar inducer commented on May 25, 2024

I'm not completely comfortable putting something like this in just yet, I would still like to let the idea "simmer" a little so that I have more time to form an opinion.

One particular concern is that there are two different Jinja contexts, one for the overall YAML document, and then another for each of the text blocks that contain course markup. I am sort of resisting having default macros that apply at the YAML document level, because I believe that forcing explicit inclusion once per document is not too onerous. At the level of the individual markup chunks however, I can see the convenience, but magical inclusion of some macro snippet behind the user's back still doesn't entirely feel discoverable.

The article you linked does look helpful by the way.

from relate.

dzhuang avatar dzhuang commented on May 25, 2024

You are right. I agree with you especially when I found that I need to import a frequently used macro into the caller of another macro.

from relate.

inducer avatar inducer commented on May 25, 2024

Let's leave it sit and come back to it later.

from relate.

dzhuang avatar dzhuang commented on May 25, 2024

OK.

from relate.

dzhuang avatar dzhuang commented on May 25, 2024

It seems that using Jinja macro is a very expensive operation, although it can greatly reduce duplicate and complex template code. Can I get a conclusion that we'd better not use Jinja macro for frequently visited pages?

from relate.

inducer avatar inducer commented on May 25, 2024

If you enable caching, then the expense is incurred once, so it should not be a big deal. Without caching, page rendering is pretty expensive, although I think Markdown is more expensive than Jinja. I could be wrong on that though.

from relate.

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.