Git Product home page Git Product logo

Comments (11)

bcoughlan avatar bcoughlan commented on August 13, 2024

Correct link: http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#htmlstyle_attributes_

You may want to take note of what's happening in #52 as it may pose some problems

from hamlpy.

md3sum avatar md3sum commented on August 13, 2024

Hi Kyle
While looking into fixing html style attributes, would you by any chance be looking to solve the issue with non-value based attributes like the itemscope attribute in HTML5 (More info is on the Schema.org site)?
In HAML, you would do: %div{:itemscope=>true} but in HamlPy, that actually results in itemscope being assigned the value of true, which is not what is desirable for this element.
Cheers,
Mehershad

from hamlpy.

md3sum avatar md3sum commented on August 13, 2024

Ok, So I did some looking around.
I am not saying this is the solution, but its what I thought would be the solution and looking at the source in the original HAML github branch, I think it confirmed what I thought.

So here it is, to enable the itemscope style emtpy attributes in an tag, HAML does this in this file in the build_attributes function:

if value == true
    next " #{attr}" if is_html
    next " #{attr}=#{attr_wrapper}#{attr}#{attr_wrapper}"
elsif value == false
    next
end

In HamlPy, in this file, I assume that condition would have to be added to the _parse_attribute_dictionary function where it says:

if isinstance(v, int) or isinstance(v, float):
    self.attributes += "%s='%s' " % (k, v)
else

add something like this:

if v.lower() in ("yes", "true", "t", "1"):
    self.attributes += "%s " % (k,)
if isinstance(v, int) or isinstance(v, float):
    self.attributes += "%s='%s' " % (k, v)
else

The problem is that the eval statement causes the attributes to get ordered in lexicographic order from what I can understand and even using an OrderedDict does not solve the ordering for now resulting in:

<div itemprop='foo' itemscope>

I honestly don't have an explanation for why does eval swap the ordering of the keys in the dictionary. Here is a series of statements I ran in the Python Interpreter:

>>> eval("{'items':'true', 'itemp':'what'}")
{'items': 'true', 'itemp': 'what'}
>>> eval("{'itemsc':'true', 'itempr':'what'}")
{'itemsc': 'true', 'itempr': 'what'}
>>> eval("{'itemsco':'true', 'itempro':'what'}")
{'itemsco': 'true', 'itempro': 'what'}
>>> eval("{'itemscop':'true', 'itemprop':'what'}")
{'itemprop': 'what', 'itemscop': 'true'}

Notice they swap ordering when they reach itemscop and itemprop

Thoughts?

  • Mehershad

ps> Should I make this a separate issue and propose the solution or are we answering on the same page re: the issue?

from hamlpy.

md3sum avatar md3sum commented on August 13, 2024

I have emailed the mailing list of schema.org asking if the order even matters or if we are fine with where it stands.
Let's see if they answer.

from hamlpy.

md3sum avatar md3sum commented on August 13, 2024

Ok, the response was that the order does not matter. So the above fix I have posted does the job for me.
What is the process to commit the changes to the branch?

from hamlpy.

bcoughlan avatar bcoughlan commented on August 13, 2024

What I did was fork the project, make my changes on my fork, and then submit a pull request (http://help.github.com/pull-requests/). It's then up to the project owner to accept the pull request and merge the code with the main branch

from hamlpy.

bcoughlan avatar bcoughlan commented on August 13, 2024

Hi md3sum, the yes/true/t/1 is interfering with attributes that are supposed to have that value. How would you feel about something like this instead?

itemscope: None

from hamlpy.

md3sum avatar md3sum commented on August 13, 2024

@bcoughlan Sorry about the delay. I was out of the country. I am OK with the change. Sorry for having the code interfere with some other working solution.
Just for knowledge - what solutions does it interfere with?
Cheers

from hamlpy.

bcoughlan avatar bcoughlan commented on August 13, 2024

@md3sum Just things like %input{type:"submit", value:"true" or %option{value:'1'}

from hamlpy.

md3sum avatar md3sum commented on August 13, 2024

@bcoughlan Ah, Gotcha. Sorry for the trouble and thanks for the fix. :)

from hamlpy.

bcoughlan avatar bcoughlan commented on August 13, 2024

No apologies needed, these things happen!

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.