Giter VIP home page Giter VIP logo

Comments (14)

jessemiller avatar jessemiller commented on August 17, 2024

I just committed a test that uses your code there and I think it outputs the right stuff. If you check out the code, take a look under hamlpy/test/templates you will see two files multiLineDict.hamlpy and multiLineDict.html. Running nosetests template_compare_test.py from the test directory should pass, confirming they are the same.

If that doesn't actually test the problem you're having, could you try to recreate the problem in the test and let me know and I don't mind fixing it up. Thanks!

from hamlpy.

bcoughlan avatar bcoughlan commented on August 17, 2024

Tested this out in my own environment and can't reproduce

from hamlpy.

bigdrum avatar bigdrum commented on August 17, 2024

But this is broken:

%div{'class': 'row'}
    %img{'src': '/static/imgs/ibl_logo_{{id}}.gif', 
        'alt': 'IBL Logo'}
    %br

from hamlpy.

bcoughlan avatar bcoughlan commented on August 17, 2024

Hmmmm ok, I've narrowed it down to this:

Start of elements.py

MULTILINE_ATTR_ELEMENT_REGEX = re.compile(r"""
(?P<tag>%\w+(\:\w+)?)?
(?P<id>\#[\w-]*)?
(?P<class>\.[\w\.-]*)*
(?P<attribute_start>\{[^\}]+$)
""", re.X)

As you can see towards the end (after attribute_start) this regex is looking for an opening { without a closing }. The regex should ignore brackets in single or double quotes, (which is why cooyeah's example doesn't work).

I don't see an easy way to solve this problem with regular expressions, can anyone else?

If not, I'll rewrite it not to use regular expressions.

from hamlpy.

bigdrum avatar bigdrum commented on August 17, 2024

This is a quick hack:

M = re.compile(r"""
(?P<tag>%\w+(\:\w+)?)?
(?P<id>\#[\w-]*)?
(?P<class>\.[\w\.-]*)*
(?P<attribute_start>\{([^\}]|\{\{[^\{\}]+\}\}|\#\{[^\{\}]+\})*$)
""", re.X)

But I would ++1 for not using regex to do the parsing.

from hamlpy.

bcoughlan avatar bcoughlan commented on August 17, 2024

Another problem caused by that regex occurs with Javascript/CSS. That regex doesn't match document.ready(function() { but does match document.ready(function() { x=2 which could cause problems.

I have a non-regex solution almost working, the trouble is how do differentiate between CSS and HAML, e.g. the CSS .myclass { is both valid CSS and a valid multi-line HAML string. I think the easiest way is to check if it's inside a :css filter, but then that could cause problems with the regular <link rel CSS tags.

Any thoughts?

from hamlpy.

bcoughlan avatar bcoughlan commented on August 17, 2024

OK, I've made a fix on my fork. All the tests pass and both examples above work as expected but I'd like a second opinion before writing tests and making a pull request.

I've used isinstance to exclude text inside filter nodes. Although it's "considered harmful" (ahem), I don't see the harm in this case

My main concerns are that the errors produced from missing braces will be unintelligible and that simply excluding filter nodes isn't sufficient.

from hamlpy.

bcoughlan avatar bcoughlan commented on August 17, 2024

Sorry for the accidental commits, can't seem to figure out how to undo them :/

from hamlpy.

bcoughlan avatar bcoughlan commented on August 17, 2024

Going to delete my repository and recommit, sorry to those who will get a blast of emails!

from hamlpy.

md3sum avatar md3sum commented on August 17, 2024

Hi,
I did notice that regex as being a source of problems too but I am currently not using the github synced code.
I use pip install hamlpy to get my packages.
Would you be able to commit the latest version to pypi so it could be upgraded using the pip commands if its not too much to ask for? :)
Thank you.
M

from hamlpy.

bcoughlan avatar bcoughlan commented on August 17, 2024

Hi md3sum,

If you have easy_install, easy_install hamlpy pulls directly from the github repo. When/if Jesse approves the pull request I made you should be able to get the changes that way.

Barry

from hamlpy.

md3sum avatar md3sum commented on August 17, 2024

I ran a pip install upgrade hamlpy but it said there was nothing to update since version 0.4
I assume I have to wait :)

from hamlpy.

jessemiller avatar jessemiller commented on August 17, 2024

Should be merged and updated in PyPi. Sorry for the delay.. startup life and all that..

from hamlpy.

md3sum avatar md3sum commented on August 17, 2024

No worries Jesse. I have sent another pull request for #58. Let us know when you get around to it. :)

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.