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

multiple values px / generator #38

Closed
ccfontes opened this issue Feb 18, 2014 · 7 comments
Closed

multiple values px / generator #38

ccfontes opened this issue Feb 18, 2014 · 7 comments

Comments

@ccfontes
Copy link

How do I write a generator like:

-moz-linear-gradient(top, #a90329 0%, #900000 44%, #6d0019 100%)

or a property with multiple px values like:

:padding "5px 0px 5px 50px"

any way more idiomatic than this?

@jeluard
Copy link
Collaborator

jeluard commented Feb 18, 2014

How about :

(defn padding
  [t r b l]
  {:padding [[(px t) (px r) (px b) (px l)]]})

Or you could probably make it unit agnostic.

@ccfontes
Copy link
Author

So the value of padding is a vector of a vector. looks strange, but I'm sure there were strong reasons!
How about the generator? Any idea?

@jeluard
Copy link
Collaborator

jeluard commented Feb 18, 2014

Well I guess the reason is there need to be some syntax to differentiate between the various CSS form you can find. See more details here.

In the linear-gradient case you could mix nested and non-nested vectors:

{:-moz-linear-gradient ["top" ["#a90329" (percent 0)] ...]}

@noprompt
Copy link
Owner

@ccfontes Yes, it does look strange but that was the best idea I had when coming up with a way to represent the difference between comma and space separated lists. If you want you can write a function or macro to clean that up.

(defmacro defproperty [name]
  `(defn ~name [& params#] 
      {'~name [params#]}))

(defproperty padding)

(padding [0 1] [2 3]) 
;; => {padding [([0 1] [2 3])]}

Edit: Paste fail

@ccfontes
Copy link
Author

Nah.. it's awesome!

@noprompt
Copy link
Owner

@ccfontes There are also some other examples (unrelated) here.

@ccfontes
Copy link
Author

Thanks!

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

No branches or pull requests

3 participants