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

Comments

Projects
None yet
1 participant
@adamldavis
Owner

adamldavis commented Sep 14, 2016

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

This comment has been minimized.

Show comment
Hide comment
@adamldavis

adamldavis Sep 30, 2016

Owner

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.

Owner

adamldavis commented Sep 30, 2016

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.

@adamldavis adamldavis closed this Sep 30, 2016

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