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

Color functions #94

Merged
merged 29 commits into from
Jan 23, 2013
Merged

Color functions #94

merged 29 commits into from
Jan 23, 2013

Conversation

karlvr
Copy link
Contributor

@karlvr karlvr commented Jan 23, 2013

All of the color functions are now implemented and tested using the latest test-cases from less.js. [#66]

I am going to go on to the other functions to wrap this up.

Note this also includes the fix described in [#90]. If that isn't the right approach to that problem let me know and I can exclude it from this pull-request. That fix was needed to pass tests due to the implementation of the alpha function that was used in a filter (as referenced in [#90]). It would be possible to solve this another way, like contrast() has solved it by silently failing if the arguments are of the wrong type... I believe that filters are always filter: rules, so that should work safely!

karlvr added 27 commits January 22, 2013 19:08
Adds support for alpha into a subclass of ColorExpression, which then
uses
the rgba() format to output to the CSS.
The implementation of ARGB uses a new node called Anonymous. I copied this approach from the less.js source.
Hue & spin don't quite match the sample yet.
Still doesn't resolve hue not matching in functions-color.less -> .css. I have also tried another HSL->RGB->HSL converter and got the same result, so this example may not be correct. I will check to see how less.js handles it.
The almost-css21.less has an example of a filter declaration that
invokes
an alpha function. Now that we've implemented the alpha function this
test
fails as it's not supposed to be a function.

Best to just not process filter declarations I think.

References issue [SomMeri#90]
so we mimic the accuracy of less.js under computation such as to and
from
HSL.

Also change to use the existing formatting for numbers (didn't realise
I could pass null for originalString), which tidies up the output by
removing extra .0s on the ends of numbers.

These accuracy changes mean much more of the test case
functions-color.less
is now correct. There is one case of too many decimal places of accuracy
that I still need to address.

Also I have removed the first set of functions from the test case as
they
don't appear to be in less.js either?
Note that there is a bug in less.js (I am submitting a bug report) in
the contrast function when a threshold is given, so I have changed the
expected result and added more test-cases.
output.

A test-case to support this is coming, it was in less.js test-cases.
parameter isn't a color, to support filters I guess. Test-cases updated
with additional color testing cases from less.js.

This matches the test-case from less.js, included in
functions-color.less
now.

The bug in less.js is unclear actually, the documentation suggests that 
the threshold parameter to contrast should be a percentage but it
doesn't
work if it is. Less.js has updated their test-cases to use decimal
numbers
rather than percentages. I have included those cases, but left in the
percentage cases as we handle those "correctly", but don't match
less.js.
I didn't notice that they round them in less.js! Now the color functions 
test-cases all pass.
I have added a convertTo function to NumberExpression, based on the
implementation
in less.js.
remove _color("evil red").

These apparently are just test functions, perhaps to test custom
functions?
@karlvr
Copy link
Contributor Author

karlvr commented Jan 23, 2013

I've added to this pull request to include more math functions and some other misc functions. This wraps up #66.

This function doesn't take parameters, which was not supported in the
grammar. I have changed the grammar (added a ?) and modified TermBuilder
to recognise the change and created EmptyExpression to represent the
lack of parameters.

The pi test is now returned to functions.less.
In particular the round() error messages now match their test-cases so
all the tests pass.

Color functions now return FaultyExpression rather than null in the
event
of errors. Except for contrast() which accepts a faulty argument as per
less.js.
@ghost ghost assigned SomMeri Jan 23, 2013
SomMeri added a commit that referenced this pull request Jan 23, 2013
Color functions, math functions and filter declarations problem.
@SomMeri SomMeri merged commit c80f024 into SomMeri:master Jan 23, 2013
@karlvr karlvr deleted the color-functions branch January 23, 2013 20:06
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

Successfully merging this pull request may close these issues.

2 participants