tyxml icon indicating copy to clipboard operation
tyxml copied to clipboard

Consistent naming scheme for html and svg elements.

Open Drup opened this issue 10 years ago • 4 comments

Consistency is not W3C's strong point, but it's made worse in tyxml. The main pain point is dashes, since they are not valid in ocaml's identifiers.

So a more formal version of what we are currently loosely applying:

  • We always keep the name in the specification if it's a valid ocaml identifier, be it snake_case, nocase, CamlCase or whatever, even if it's internally inconsistent (I'm looking at you, fontFace)

  • Dashes are transformed in underscores systematically.

  • Underscores are kept.

  • Any other characters that could ever appear are transformed in an underscore too. I don't think I ever saw one, but better be sure.

  • In case of conflict between attributes of incompatible types. We put the element that it's disambiguated for between underscores, after the a.

    Example: the attribute max for input is transformed in a_input_max.

  • Specific transformation rules:

    • When transforming to an element, the first letter become a lowercase.
    • When transforming to a polymorphic variant, the first letter is capitalized. This is not mandatory (since polymorphic variant can start with a lowercase), but it's acceptable and is already applied almost consistently, so better keep it.
    • When transforming to an attribute, no letter is changed (it's ok, it starts with a_).

These should also keep the breaking rather minimal. Remarks ? cc @dsheets since you might have an opinion. :)

Drup avatar Apr 03 '15 21:04 Drup

Seems reasonable. Though W3C's "conventions" are inconsistent, I agree it is better to have a fairly verbatim mapping between them and Tyxml's names, as I reckon most developers rely on resources such as MDN, which of course use W3C's naming.

darioteixeira avatar Apr 04 '15 11:04 darioteixeira

Apparently, some svg attributes have ':' in the name. so that would become a '_' in this scheme.

Drup avatar Apr 27 '15 01:04 Drup

I pushed a bunch of functions and a little tool called autoname that does the transformation automatically.

The only things remaining to do is to transform the whole codebase .... sob.

Drup avatar Jul 26 '15 18:07 Drup

The situation is much better now, but not yet enforced by the ppx. We will get there eventually.

Drup avatar Apr 11 '16 15:04 Drup