Comments (8)
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.
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.
I talk about more haml in work with attributes values
from hamlpy.
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:
- No characters should be escaped between
{% ... %}
- Escape with ``'
instead of
"` - 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.
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.
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.
Hey, if anyone is interested I'm working on this at the moment on the element_parser
branch.
Barry
from hamlpy.
Are there any plans to merge the element_parser branch with recent changes in the master branch?
from hamlpy.
Related Issues (20)
- %a processing bug HOT 1
- jinja2 macro and call tags closed as blocks HOT 1
- HamlPy cannot run from library.zip HOT 3
- Python3 support for hamlpy HOT 10
- HamlPy comment before else produces incorrect output
- Not found on PyPi
- JS inline comments // don't work
- Reverse HTML to HamlPy compiler
- Can't find templatize HOT 2
- "or" statement does not work as expected in "if" tests
- Django if-else tags common inner content HOT 1
- support for :preserve tag?
- Load / extends html file
- HamlPy linter?
- Can't encode UTF8 characters in shell
- Quoting issues when using inline variable with filter
- Using a "with" statement does not close the tag properly HOT 2
- Hamlpy on django 1.11 uses the standard django-templates instead hamlpy HOT 2
- How to write an attribute starting with the symbol #
- A ReDoS vulnerability exists in nodes.py
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hamlpy.