modulojs / modulo

A drop-in JavaScript framework for modular web components, kept to about 2000 lines
https://modulojs.org/
GNU Lesser General Public License v2.1
12 stars 1 forks source link

Template tag and filter ideas #23

Open michaelpb opened 1 year ago

michaelpb commented 1 year ago
1440     //trim: s => s.trim(), // TODO: improve interface to be more useful
1441     //invoke: (s, arg) => s(arg),
1442     //getAttribute: (s, arg) => s.getAttribute(arg),
1443 
1444     // Idea: Generalized "matches" filter that gets registered like such:
1445     //     defaultOptions.filters.matches = {name: //ig}
1446     // Then we could configure "named" RegExps in Script that get used in
1447     // template
michaelpb commented 1 year ago
{% paginate navigation %}

{% for link in navigation.visible %}
   <a href="{{ link.url }}">{{ link.title }}</a>
{% endfor %}

{% if navigation.next %}
   <a href="{{ navigation.next }}">Next</a>
{% endif %}
{% if navigation.previous %}
    <a href="{{ navigation.previous }}">Previous</a>
{% endif %}
michaelpb commented 1 year ago
    1327     'with': (text, tmplt) => {
    1328         const code = text.split(/s+/g).map(tmplt.parseAssign).join('\n');
    1329         return { start: 'if(1){\n' + code, end: '}' };
    1330     },

    1151 
    1152     parseAssign(text) {
    1153         const index = text.indexOf('=') + 1; // Index at 1 (0 if missing)
    1154         const expr = this.parseExpr(text.slice(index)); // Parse on the right
    1155         return `CTX.${ text.slice(0, index - 1) } = ${ expr }`;
    1156     }
michaelpb commented 1 year ago
{% when ready a is 10%}
{% when next-page b is 100 %}

{% if ready and next-page %}
{% endif %}

(alternative for complex expressions?)
{% condition ready = a is 10%}
{% condition next-page = b is 100 %}