{"action":"closed","number":644,"pull_request":{"url":"https://api.github.com/repos/sass/node-sass/pulls/644","id":28413606,"html_url":"https://github.com/sass/node-sass/pull/644","diff_url":"https://github.com/sass/node-sass/pull/644.diff","patch_url":"https://github.com/sass/node-sass/pull/644.patch","issue_url":"https://api.github.com/repos/sass/node-sass/issues/644","number":644,"state":"closed","locked":false,"title":"Custom functions","user":{"login":"matryo","id":10783858,"avatar_url":"https://avatars.githubusercontent.com/u/10783858?v=3","gravatar_id":"","url":"https://api.github.com/users/matryo","html_url":"https://github.com/matryo","followers_url":"https://api.github.com/users/matryo/followers","following_url":"https://api.github.com/users/matryo/following{/other_user}","gists_url":"https://api.github.com/users/matryo/gists{/gist_id}","starred_url":"https://api.github.com/users/matryo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matryo/subscriptions","organizations_url":"https://api.github.com/users/matryo/orgs","repos_url":"https://api.github.com/users/matryo/repos","events_url":"https://api.github.com/users/matryo/events{/privacy}","received_events_url":"https://api.github.com/users/matryo/received_events","type":"User","site_admin":false},"body":"This is a refactor of #530 (custom importers) to also support #332 (custom functions). \r\n\r\nThe mechanism to synchronize the worker thread that runs libsass and the main v8 loop has been centralized and abstracted into an object called `CallbackBridge` that has two specializations: `CustomImporterBridge` and `CustomFunctionBridge`. The former supports the existing functionality (#530) while the other makes it possible to register custom functions that are backed up by v8 functions and takes care of translating `Sass_Value`s to something that makes sense to the JS runtime and vice versa.\r\n\r\nThe function arguments are relayed to the JS callback by means of wrapping `Sass_Value*` pointers into v8 objects. Those objects mimic the API offered by libsass and as such could be a bit cumbersome to work with on the javascript side. This problem could however be largely mitigated by translating those wrapper objects into JS primitives upon entering the JS callback and back into wrapper objects upon return. The only edge cases that I can think of is that of `SASS_NUMBER` values when they carry units and `SASS_COLOR` where we could parse strings and detect patterns like `\\d+(px|em|%)` and `rgba?\\(...)\\` or resolve to use more JS friendly facades.\r\n\r\nThis is a quick example demonstrating how compass' `headings` function may be implemented:\r\n\r\n```javascript\r\nsass.render({\r\n  data: '#{headings(2,5)} { color: #08c; }',\r\n  functions: {\r\n    'headings($from: 0, $to: 6)': function(from, to) {\r\n      var i, f = from.getValue(), t = to.getValue(),\r\n          list = new sass.types.List(t - f + 1);\r\n\r\n      for (i = f; i <= t; i++) {\r\n        list.setValue(i - f, new sass.types.String('h' + i));\r\n      }\r\n\r\n      return list;\r\n    }\r\n  }\r\n});\r\n```","created_at":"2015-01-31T11:23:01Z","updated_at":"2015-03-23T05:33:24Z","closed_at":"2015-03-23T05:33:24Z","merged_at":"2015-03-23T05:33:24Z","merge_commit_sha":"6a9b82cceb450818a07f797adc8a6abbfaff09cd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sass/node-sass/pulls/644/commits","review_comments_url":"https://api.github.com/repos/sass/node-sass/pulls/644/comments","review_comment_url":"https://api.github.com/repos/sass/node-sass/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sass/node-sass/issues/644/comments","statuses_url":"https://api.github.com/repos/sass/node-sass/statuses/07a9540a1d7918605e25e248899d3cacd0bf43d1","head":{"label":"matryo:custom_functions","ref":"custom_functions","sha":"07a9540a1d7918605e25e248899d3cacd0bf43d1","user":{"login":"matryo","id":10783858,"avatar_url":"https://avatars.githubusercontent.com/u/10783858?v=3","gravatar_id":"","url":"https://api.github.com/users/matryo","html_url":"https://github.com/matryo","followers_url":"https://api.github.com/users/matryo/followers","following_url":"https://api.github.com/users/matryo/following{/other_user}","gists_url":"https://api.github.com/users/matryo/gists{/gist_id}","starred_url":"https://api.github.com/users/matryo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matryo/subscriptions","organizations_url":"https://api.github.com/users/matryo/orgs","repos_url":"https://api.github.com/users/matryo/repos","events_url":"https://api.github.com/users/matryo/events{/privacy}","received_events_url":"https://api.github.com/users/matryo/received_events","type":"User","site_admin":false},"repo":{"id":30107472,"name":"node-sass","full_name":"matryo/node-sass","owner":{"login":"matryo","id":10783858,"avatar_url":"https://avatars.githubusercontent.com/u/10783858?v=3","gravatar_id":"","url":"https://api.github.com/users/matryo","html_url":"https://github.com/matryo","followers_url":"https://api.github.com/users/matryo/followers","following_url":"https://api.github.com/users/matryo/following{/other_user}","gists_url":"https://api.github.com/users/matryo/gists{/gist_id}","starred_url":"https://api.github.com/users/matryo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matryo/subscriptions","organizations_url":"https://api.github.com/users/matryo/orgs","repos_url":"https://api.github.com/users/matryo/repos","events_url":"https://api.github.com/users/matryo/events{/privacy}","received_events_url":"https://api.github.com/users/matryo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/matryo/node-sass","description":"Node.js bindings to libsass","fork":true,"url":"https://api.github.com/repos/matryo/node-sass","forks_url":"https://api.github.com/repos/matryo/node-sass/forks","keys_url":"https://api.github.com/repos/matryo/node-sass/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matryo/node-sass/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matryo/node-sass/teams","hooks_url":"https://api.github.com/repos/matryo/node-sass/hooks","issue_events_url":"https://api.github.com/repos/matryo/node-sass/issues/events{/number}","events_url":"https://api.github.com/repos/matryo/node-sass/events","assignees_url":"https://api.github.com/repos/matryo/node-sass/assignees{/user}","branches_url":"https://api.github.com/repos/matryo/node-sass/branches{/branch}","tags_url":"https://api.github.com/repos/matryo/node-sass/tags","blobs_url":"https://api.github.com/repos/matryo/node-sass/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matryo/node-sass/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matryo/node-sass/git/refs{/sha}","trees_url":"https://api.github.com/repos/matryo/node-sass/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matryo/node-sass/statuses/{sha}","languages_url":"https://api.github.com/repos/matryo/node-sass/languages","stargazers_url":"https://api.github.com/repos/matryo/node-sass/stargazers","contributors_url":"https://api.github.com/repos/matryo/node-sass/contributors","subscribers_url":"https://api.github.com/repos/matryo/node-sass/subscribers","subscription_url":"https://api.github.com/repos/matryo/node-sass/subscription","commits_url":"https://api.github.com/repos/matryo/node-sass/commits{/sha}","git_commits_url":"https://api.github.com/repos/matryo/node-sass/git/commits{/sha}","comments_url":"https://api.github.com/repos/matryo/node-sass/comments{/number}","issue_comment_url":"https://api.github.com/repos/matryo/node-sass/issues/comments{/number}","contents_url":"https://api.github.com/repos/matryo/node-sass/contents/{+path}","compare_url":"https://api.github.com/repos/matryo/node-sass/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matryo/node-sass/merges","archive_url":"https://api.github.com/repos/matryo/node-sass/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matryo/node-sass/downloads","issues_url":"https://api.github.com/repos/matryo/node-sass/issues{/number}","pulls_url":"https://api.github.com/repos/matryo/node-sass/pulls{/number}","milestones_url":"https://api.github.com/repos/matryo/node-sass/milestones{/number}","notifications_url":"https://api.github.com/repos/matryo/node-sass/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matryo/node-sass/labels{/name}","releases_url":"https://api.github.com/repos/matryo/node-sass/releases{/id}","created_at":"2015-01-31T08:53:09Z","updated_at":"2015-03-23T01:18:09Z","pushed_at":"2015-03-23T05:23:53Z","git_url":"git://github.com/matryo/node-sass.git","ssh_url":"git@github.com:matryo/node-sass.git","clone_url":"https://github.com/matryo/node-sass.git","svn_url":"https://github.com/matryo/node-sass","homepage":"https://npmjs.org/package/node-sass","size":14532,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sass:master","ref":"master","sha":"f95647614e009ae53df5718f676b8b087708cab4","user":{"login":"sass","id":317889,"avatar_url":"https://avatars.githubusercontent.com/u/317889?v=3","gravatar_id":"","url":"https://api.github.com/users/sass","html_url":"https://github.com/sass","followers_url":"https://api.github.com/users/sass/followers","following_url":"https://api.github.com/users/sass/following{/other_user}","gists_url":"https://api.github.com/users/sass/gists{/gist_id}","starred_url":"https://api.github.com/users/sass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sass/subscriptions","organizations_url":"https://api.github.com/users/sass/orgs","repos_url":"https://api.github.com/users/sass/repos","events_url":"https://api.github.com/users/sass/events{/privacy}","received_events_url":"https://api.github.com/users/sass/received_events","type":"Organization","site_admin":false},"repo":{"id":4128353,"name":"node-sass","full_name":"sass/node-sass","owner":{"login":"sass","id":317889,"avatar_url":"https://avatars.githubusercontent.com/u/317889?v=3","gravatar_id":"","url":"https://api.github.com/users/sass","html_url":"https://github.com/sass","followers_url":"https://api.github.com/users/sass/followers","following_url":"https://api.github.com/users/sass/following{/other_user}","gists_url":"https://api.github.com/users/sass/gists{/gist_id}","starred_url":"https://api.github.com/users/sass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sass/subscriptions","organizations_url":"https://api.github.com/users/sass/orgs","repos_url":"https://api.github.com/users/sass/repos","events_url":"https://api.github.com/users/sass/events{/privacy}","received_events_url":"https://api.github.com/users/sass/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sass/node-sass","description":":rainbow: Node.js bindings to libsass","fork":false,"url":"https://api.github.com/repos/sass/node-sass","forks_url":"https://api.github.com/repos/sass/node-sass/forks","keys_url":"https://api.github.com/repos/sass/node-sass/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sass/node-sass/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sass/node-sass/teams","hooks_url":"https://api.github.com/repos/sass/node-sass/hooks","issue_events_url":"https://api.github.com/repos/sass/node-sass/issues/events{/number}","events_url":"https://api.github.com/repos/sass/node-sass/events","assignees_url":"https://api.github.com/repos/sass/node-sass/assignees{/user}","branches_url":"https://api.github.com/repos/sass/node-sass/branches{/branch}","tags_url":"https://api.github.com/repos/sass/node-sass/tags","blobs_url":"https://api.github.com/repos/sass/node-sass/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sass/node-sass/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sass/node-sass/git/refs{/sha}","trees_url":"https://api.github.com/repos/sass/node-sass/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sass/node-sass/statuses/{sha}","languages_url":"https://api.github.com/repos/sass/node-sass/languages","stargazers_url":"https://api.github.com/repos/sass/node-sass/stargazers","contributors_url":"https://api.github.com/repos/sass/node-sass/contributors","subscribers_url":"https://api.github.com/repos/sass/node-sass/subscribers","subscription_url":"https://api.github.com/repos/sass/node-sass/subscription","commits_url":"https://api.github.com/repos/sass/node-sass/commits{/sha}","git_commits_url":"https://api.github.com/repos/sass/node-sass/git/commits{/sha}","comments_url":"https://api.github.com/repos/sass/node-sass/comments{/number}","issue_comment_url":"https://api.github.com/repos/sass/node-sass/issues/comments{/number}","contents_url":"https://api.github.com/repos/sass/node-sass/contents/{+path}","compare_url":"https://api.github.com/repos/sass/node-sass/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sass/node-sass/merges","archive_url":"https://api.github.com/repos/sass/node-sass/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sass/node-sass/downloads","issues_url":"https://api.github.com/repos/sass/node-sass/issues{/number}","pulls_url":"https://api.github.com/repos/sass/node-sass/pulls{/number}","milestones_url":"https://api.github.com/repos/sass/node-sass/milestones{/number}","notifications_url":"https://api.github.com/repos/sass/node-sass/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sass/node-sass/labels{/name}","releases_url":"https://api.github.com/repos/sass/node-sass/releases{/id}","created_at":"2012-04-24T18:46:30Z","updated_at":"2015-03-23T01:28:48Z","pushed_at":"2015-03-23T05:33:24Z","git_url":"git://github.com/sass/node-sass.git","ssh_url":"git@github.com:sass/node-sass.git","clone_url":"https://github.com/sass/node-sass.git","svn_url":"https://github.com/sass/node-sass","homepage":"https://npmjs.org/package/node-sass","size":18453,"stargazers_count":1540,"watchers_count":1540,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":216,"mirror_url":null,"open_issues_count":21,"forks":216,"open_issues":21,"watchers":1540,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sass/node-sass/pulls/644"},"html":{"href":"https://github.com/sass/node-sass/pull/644"},"issue":{"href":"https://api.github.com/repos/sass/node-sass/issues/644"},"comments":{"href":"https://api.github.com/repos/sass/node-sass/issues/644/comments"},"review_comments":{"href":"https://api.github.com/repos/sass/node-sass/pulls/644/comments"},"review_comment":{"href":"https://api.github.com/repos/sass/node-sass/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sass/node-sass/pulls/644/commits"},"statuses":{"href":"https://api.github.com/repos/sass/node-sass/statuses/07a9540a1d7918605e25e248899d3cacd0bf43d1"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"am11","id":3840695,"avatar_url":"https://avatars.githubusercontent.com/u/3840695?v=3","gravatar_id":"","url":"https://api.github.com/users/am11","html_url":"https://github.com/am11","followers_url":"https://api.github.com/users/am11/followers","following_url":"https://api.github.com/users/am11/following{/other_user}","gists_url":"https://api.github.com/users/am11/gists{/gist_id}","starred_url":"https://api.github.com/users/am11/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/am11/subscriptions","organizations_url":"https://api.github.com/users/am11/orgs","repos_url":"https://api.github.com/users/am11/repos","events_url":"https://api.github.com/users/am11/events{/privacy}","received_events_url":"https://api.github.com/users/am11/received_events","type":"User","site_admin":false},"comments":53,"review_comments":22,"commits":1,"additions":2330,"deletions":205,"changed_files":38}}