Comments (14)
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.
Tested this out in my own environment and can't reproduce
from hamlpy.
But this is broken:
%div{'class': 'row'}
%img{'src': '/static/imgs/ibl_logo_{{id}}.gif',
'alt': 'IBL Logo'}
%br
from hamlpy.
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.
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.
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.
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.
Sorry for the accidental commits, can't seem to figure out how to undo them :/
from hamlpy.
Going to delete my repository and recommit, sorry to those who will get a blast of emails!
from hamlpy.
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.
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.
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.
Should be merged and updated in PyPi. Sorry for the delay.. startup life and all that..
from hamlpy.
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)
- %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.