Git Product home page Git Product logo

Comments (5)

dmclain avatar dmclain commented on August 13, 2024

I had a commit (0e53ea2) that allowed
#blah{'class':=minor}
which would then be converted into
#blah{'class':'{{minor}}'}
and then into
<div id="blah" class="{{minor}}">

It was just a simplistic find and replace, so it led to issues with code like
%a{"href":"{% url foo.bar param=object.value %}"}

The underlying issue in the codebase is that the attribute dictionary is parsed as a python dictionary by calling eval on the string. While that is very powerful and allows for a lot of complexity, it makes it difficult to change the parsing of the string. My commit used a simple regular expression to find variables prefixed with = to convert, but that's really not a robust approach.

To implement a better way of specifying django variables the parsing of attributes would need to either be handled by using lower level python parsing than eval (http://docs.python.org/library/parser.html) or rolling a parser for just attributes. Both are a lot of work for what amounts to a smarter way to add '{{ }}' around variables, but a cynic could describe HAML as just a lot of work for what amounts to a smarter way to add closing tags.

from hamlpy.

gon avatar gon commented on August 13, 2024

What is the right way to write this?

%img{'src':item.product.images.0.link}

from hamlpy.

dmclain avatar dmclain commented on August 13, 2024

%img{'src':'{{item.product.images.0.link}}'} will work

from hamlpy.

gon avatar gon commented on August 13, 2024

Yes that works! Thank you.

from hamlpy.

svetlyak40wt avatar svetlyak40wt commented on August 13, 2024

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.