Giter VIP home page Giter VIP logo

Comments (8)

timmyomahony avatar timmyomahony commented on July 18, 2024

I was about to post the same issue. Logic and template tags in attributes is the one thing stopping me from using this I think. Maybe it can be done using a filter?

from hamlpy.

bcoughlan avatar bcoughlan commented on July 18, 2024

This hamlpy:

    {% for a in b %}
    %a{'class': "link {% if forloop.first %}link-first {% else %}{% if forloop.last %}link-last{% endif %}{% endif %}"}
      this is link
    {% endfor %}

Gives me this output:

{% for a in b %}
    <a class='link {% if forloop.first %}link-first {% else %}{% if forloop.last %}link-last{% endif %}{% endif %}'>
      this is link
    </a>
{% endfor %}

Is this not what you were expecting?

from hamlpy.

neoascetic avatar neoascetic commented on July 18, 2024

I talk about more haml in work with attributes values

from hamlpy.

bcoughlan avatar bcoughlan commented on July 18, 2024

How would your syntax from #50 work when mixing text and tags? Like this?

class: "link" + {% if forloop.first %} + "link-first"...

The only disadvantage of putting template tags in strings is that it prevents putting an {% if ..%} around the whole attribute to remove its name.

Also, I don't think & quot; should be used at all, it could prevent inline javascript. It should be \'. The need for & quot; is a HTML need, not just a HAML need, and as such it should be left up to the developer to replace them.

Given the above, I think the following rules should apply:

  1. No characters should be escaped between {% ... %}
  2. Escape with ``'instead of"`
  3. Add a feature that lets the user wrap a tag around a whole attribute

Personally I'm a fan of getting rid of the Python dictionary syntax in favour of SHPAMLs syntax:

{% for a in b %}
%a class="link {% if forloop.first %}link-first {% endif %}" | this is link
{% endfor %}

Eliminates these problems because the tags attribute text is identical to HTML. It also eases the pain of migrating HTML to HAML
Any thoughts?

from hamlpy.

neoascetic avatar neoascetic commented on July 18, 2024

I think this is good enaugh:

- for a in b
    %a.link{
        'class':
            - if forloop.first
                link-first
            - else
                - if forloop.last
                    link-last
        'href':
            - url some_view
        }
        this is a link

from hamlpy.

bcoughlan avatar bcoughlan commented on July 18, 2024

CC: @markusgattol @mkcode

I was playing with how to parse this and would like some input. Parsing the example from @neoascetic above is fine (when it's a multiline string), but it would be nice to have an inline one too, e.g:

%a.link{'href': -url 'some_view', 'class': =var1}

But a problem arises here when there are commas in the template tag:

%a.link{'data-time': - now "jS, o\f F", 'class': =var1}

It's hard for the parser to know if the comma is part of the attribute dictionary or part of the template tag. I'd rather not get into allowing escaped commas as that could get very ugly and confusing particularly as the comma is not necessarily always in quotes.

I propose this as a solution:

Allow use of the inline variable syntax (={var1}) and extend it to template tags (-{url some_view}), so we could have:

 %a.link{'href': -{url 'some_view'}, 'class': ={var1}}

Note that this syntax already works in attribute strings (e.g. 'class': "some_class ={var1} some_other_class"), so the syntax is consistent with the langauge, and it solves the issue of having to escape quotes (see #86).

Any input or better ideas would be appreciated.

Regards,
Barry

from hamlpy.

bcoughlan avatar bcoughlan commented on July 18, 2024

Hey, if anyone is interested I'm working on this at the moment on the element_parser branch.

Barry

from hamlpy.

a1s avatar a1s commented on July 18, 2024

Are there any plans to merge the element_parser branch with recent changes in the master branch?

from hamlpy.

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.