{"action":"created","issue":{"url":"https://api.github.com/repos/cloudkite/Classy/issues/96","labels_url":"https://api.github.com/repos/cloudkite/Classy/issues/96/labels{/name}","comments_url":"https://api.github.com/repos/cloudkite/Classy/issues/96/comments","events_url":"https://api.github.com/repos/cloudkite/Classy/issues/96/events","html_url":"https://github.com/cloudkite/Classy/issues/96","id":93046205,"number":96,"title":"Support custom functions in NSExpression / CASExpressionSolver","user":{"login":"keithnorm","id":22611,"avatar_url":"https://avatars.githubusercontent.com/u/22611?v=3","gravatar_id":"","url":"https://api.github.com/users/keithnorm","html_url":"https://github.com/keithnorm","followers_url":"https://api.github.com/users/keithnorm/followers","following_url":"https://api.github.com/users/keithnorm/following{/other_user}","gists_url":"https://api.github.com/users/keithnorm/gists{/gist_id}","starred_url":"https://api.github.com/users/keithnorm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithnorm/subscriptions","organizations_url":"https://api.github.com/users/keithnorm/orgs","repos_url":"https://api.github.com/users/keithnorm/repos","events_url":"https://api.github.com/users/keithnorm/events{/privacy}","received_events_url":"https://api.github.com/users/keithnorm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-04T20:33:34Z","updated_at":"2015-07-05T19:32:23Z","closed_at":null,"body":"Hey Jonas, I'm hoping to add some color utility functions to Classy, something like:\r\n\r\n```\r\nUIView.overlay {\r\n  background-color: alpha($some-color, 0.5)\r\n}\r\n```\r\n\r\nThis can nearly be done with a UIColor extension that implements `alpha:(NSNumber *val)` and can be called via `NSExpression` like this (in Swift):\r\n\r\n```Swift\r\nNSExpression(format: \"function(%@, 'alpha:', %f)\", someColor, 0.5)\r\n```\r\n\r\nI'd like to implement this in a way that it would get handled by `CASExpressionSolver` (as opposed to happening within the UIColor transformer the way `rgb` and related methods are handled) because then it would allow any extension to become callable from within a Classy property.\r\n\r\nI spent some time tracing through `CASExpressionSolver` and I don't fully understand what it's doing, particularly inside of `extractTuples`. I can probably figure it out given a bit more time but I wanted to see if you could help at all to figure out how I might go about implementing this. Ultimately I think `evaluateTokens` given a function token just needs to be aware of if the function is built in or custom, and generate the custom function format string if it is custom, but the arguments I need are getting removed in `extractTuples` I think.\r\n\r\nAnyway, if you have any insight or if you have a minute to help me think it through I would appreciate it. Thanks!"},"comment":{"url":"https://api.github.com/repos/cloudkite/Classy/issues/comments/118657279","html_url":"https://github.com/cloudkite/Classy/issues/96#issuecomment-118657279","issue_url":"https://api.github.com/repos/cloudkite/Classy/issues/96","id":118657279,"user":{"login":"keithnorm","id":22611,"avatar_url":"https://avatars.githubusercontent.com/u/22611?v=3","gravatar_id":"","url":"https://api.github.com/users/keithnorm","html_url":"https://github.com/keithnorm","followers_url":"https://api.github.com/users/keithnorm/followers","following_url":"https://api.github.com/users/keithnorm/following{/other_user}","gists_url":"https://api.github.com/users/keithnorm/gists{/gist_id}","starred_url":"https://api.github.com/users/keithnorm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithnorm/subscriptions","organizations_url":"https://api.github.com/users/keithnorm/orgs","repos_url":"https://api.github.com/users/keithnorm/repos","events_url":"https://api.github.com/users/keithnorm/events{/privacy}","received_events_url":"https://api.github.com/users/keithnorm/received_events","type":"User","site_admin":false},"created_at":"2015-07-05T19:32:23Z","updated_at":"2015-07-05T19:32:23Z","body":"I got a basic version working but it's a little hacky I think, and it works for cases like\r\n\r\n```\r\n$color = #00ff00\r\nbackground-color: alpha($color, 0.5);\r\n// and\r\nbackground-color: alpha(green, 0.5);\r\n// but not\r\nbackground-color: alpha(rgb(0, 255, 0), 0.5)\r\n```\r\n\r\nbecause I wasn't quite sure what the best approach was given tokens that have an inner and outer expression like that.\r\n\r\nAnyway, check it out if you get a minute and let me know if you have any thoughts on a different approach or anything https://github.com/keithnorm/Classy/pull/2. Thanks!"}}