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

Add better support for conditional styles and code reuse #3

Closed
adamldavis opened this issue Sep 14, 2016 · 1 comment
Closed

Add better support for conditional styles and code reuse #3

adamldavis opened this issue Sep 14, 2016 · 1 comment
Milestone

Comments

@adamldavis
Copy link
Owner

In comparable systems, you can define a method which is called elsewhere, pass parameters, and conditionally add styles. GrooCSS should easily support this with a few additions.

For example, something like:

def mycolor(alpha) { styles {
   if (alpha == 0) color '#123'
   else color rgba(0,0,0,alpha)
}}

and elsewhere within a style-group:
add mycolor(0.5)

@adamldavis adamldavis added this to the 0.8 milestone Sep 14, 2016
@adamldavis
Copy link
Owner Author

This has been added. I've added the following within a test:

        def mycolor = { alpha -> styles {
            if (alpha == 0) color '#123'
            else color rgba(0, 0, 0, alpha)
        }}
        assert mycolor(0).styleList[0] == new Style('color', '#123')
        assert mycolor(0.5).styleList[0]==new Style('color', 'rgba(0, 0, 0, 0.50)')

You can't create inner methods within a closure, so I've used a closure instead.

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

1 participant