moovweb / tritium

Tritium is a magical document modifying language. It's JavaScript-like and simple to learn. Think XSLT without the nightmare. It was designed by Hampton Catlin (@hcatlin), and has been heavily influenced by Aaron Leung (@akhleung).
http://tritium.io
Mozilla Public License 2.0
33 stars 7 forks source link

Attribute Order #12

Closed HamptonMakes closed 12 years ago

HamptonMakes commented 12 years ago

Seems to be going out of order...

xml() {
  $("./root") {
    attributes(http-equiv: "hi", superdude: "you", keep_spaces: " ")
  }
}

Comes out as...

<root http-equiv="hi" keep_spaces=" " superdude="you"/>
HamptonMakes commented 12 years ago

Seems to be in the parser....

akhleung commented 12 years ago

Yeah, I'm using Go's built-in maps to accumulate the keyword args as they're being parsed, and maps are unordered. Is the order important? I assumed not. As long as the relative ordering of the ordinal args is consistent, the behavior should be the same. I.e., all the following should be equivalent:

foo("bar", "hux", a: "A", b: "B") foo("bar", a: "A", "hux", b: "B") foo(b: "B", a: "A", "bar", "hux")

In other words, as long as "bar" comes before "hux", all the preceding examples should have the same behavior.

On Mon, Jan 16, 2012 at 2:59 PM, Hampton Catlin reply@reply.github.com wrote:

Seems to be in the parser....


Reply to this email directly or view it on GitHub: https://github.com/moovweb/tritium/issues/12#issuecomment-3519980

HamptonMakes commented 12 years ago

The problem is that it breaks the tests... Ruby keeps track of the order, so we need to... that or its impossible to Spec test the input/output expectations.

On Jan 16, 2012, at 3:05 PM, Aaron Leung wrote:

Yeah, I'm using Go's built-in maps to accumulate the keyword args as they're being parsed, and maps are unordered. Is the order important? I assumed not. As long as the relative ordering of the ordinal args is consistent, the behavior should be the same. I.e., all the following should be equivalent:

foo("bar", "hux", a: "A", b: "B") foo("bar", a: "A", "hux", b: "B") foo(b: "B", a: "A", "bar", "hux")

In other words, as long as "bar" comes before "hux", all the preceding examples should have the same behavior.

On Mon, Jan 16, 2012 at 2:59 PM, Hampton Catlin reply@reply.github.com wrote:

Seems to be in the parser....


Reply to this email directly or view it on GitHub: https://github.com/moovweb/tritium/issues/12#issuecomment-3519980


Reply to this email directly or view it on GitHub: https://github.com/moovweb/tritium/issues/12#issuecomment-3520081

akhleung commented 12 years ago

All right, I can make the change.

akhleung commented 12 years ago

Keyword argument order should be preserved now. I.e., something like:

foo(a: 1, b: 2, c: 3)

will consistently expand to something like:

$tmp1 = 1 $tmp2 = 2 $tmp3 = 3 foo() { set("a", $tmp1) set("b", $tmp2) set("c", $tmp3) }