Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard keys for :class and :for #5

Closed
asmala opened this issue Jan 10, 2014 · 6 comments
Closed

Use standard keys for :class and :for #5

asmala opened this issue Jan 10, 2014 · 6 comments

Comments

@asmala
Copy link
Contributor

asmala commented Jan 10, 2014

Given that the HTML attributes get passed via sablono.compiler/compile-attrs, is there a reason to stick to the React convention of using :htmlFor and :className, instead of the standard :for and :class? These could be easily rewritten on the fly within compile-attr to follow React conventions.

Sticking to the standard key names would allow sablono to more readily share code with hiccup and related libraries (see also this hiccup issue), and would seem more intuitive to the average Clojure user. What do you think?

Something like this:

(def ^:private react-attrs
  {:for :htmlFor
   :class :className})

(defn compile-attrs
  "Compile a HTML attribute map."
  [attrs]
  (->> (seq (rename-keys attrs react-attrs))
       (map #(apply compile-attr %1))
       (apply merge)
       (to-js)))
@r0man
Copy link
Owner

r0man commented Jan 10, 2014

Patch with Tests welcome ...

@r0man
Copy link
Owner

r0man commented Jan 10, 2014

I think this would also mean relacing all of those attributes with "dash" versions:
http://facebook.github.io/react/docs/tags-and-attributes.html#html-attributes

@r0man
Copy link
Owner

r0man commented Jan 10, 2014

And what about events?
http://facebook.github.io/react/docs/events.html

@asmala
Copy link
Contributor Author

asmala commented Jan 10, 2014

Good point. My main concern was alignment with hiccup conventions, so for and class were the ones that were an issue. It would be trivial to write a full mapping between HTML attributes and JS DOM attributes. What do you think?

I'm preparing a pull request against your updated code. Should have it done tomorrow.

@r0man
Copy link
Owner

r0man commented Jan 11, 2014

Hi Asmala,

thanks for the patch! I applied it an made a minor change. I
moved the camel-caseing code to the util namespace and also call
it from the interpreter in case attributes could not be optimized
at compile time. Your changed are now in 0.2.0.

Thanks Roman.

@r0man r0man closed this as completed Jan 11, 2014
@asmala
Copy link
Contributor Author

asmala commented Jan 11, 2014

Happy to help! I'd like too see the common parts of the hiccup family libraries pulled into one cross-compileable library, so this was just scratching my own itch. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants