{"action":"created","issue":{"url":"https://api.github.com/repos/stencila/stencila/issues/96","labels_url":"https://api.github.com/repos/stencila/stencila/issues/96/labels{/name}","comments_url":"https://api.github.com/repos/stencila/stencila/issues/96/comments","events_url":"https://api.github.com/repos/stencila/stencila/issues/96/events","html_url":"https://github.com/stencila/stencila/issues/96","id":126323697,"number":96,"title":"Snippets","user":{"login":"nokome","id":1152336,"avatar_url":"https://avatars.githubusercontent.com/u/1152336?v=3","gravatar_id":"","url":"https://api.github.com/users/nokome","html_url":"https://github.com/nokome","followers_url":"https://api.github.com/users/nokome/followers","following_url":"https://api.github.com/users/nokome/following{/other_user}","gists_url":"https://api.github.com/users/nokome/gists{/gist_id}","starred_url":"https://api.github.com/users/nokome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nokome/subscriptions","organizations_url":"https://api.github.com/users/nokome/orgs","repos_url":"https://api.github.com/users/nokome/repos","events_url":"https://api.github.com/users/nokome/events{/privacy}","received_events_url":"https://api.github.com/users/nokome/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/stencila/stencila/labels/1%20-%20Ready","name":"1 - Ready","color":"009800"},{"url":"https://api.github.com/repos/stencila/stencila/labels/c++","name":"c++","color":"f7c6c7"},{"url":"https://api.github.com/repos/stencila/stencila/labels/Sheets","name":"Sheets","color":"eb6420"},{"url":"https://api.github.com/repos/stencila/stencila/labels/Stencils","name":"Stencils","color":"5319e7"},{"url":"https://api.github.com/repos/stencila/stencila/labels/web","name":"web","color":"bfdadc"}],"state":"open","locked":false,"assignee":{"login":"nokome","id":1152336,"avatar_url":"https://avatars.githubusercontent.com/u/1152336?v=3","gravatar_id":"","url":"https://api.github.com/users/nokome","html_url":"https://github.com/nokome","followers_url":"https://api.github.com/users/nokome/followers","following_url":"https://api.github.com/users/nokome/following{/other_user}","gists_url":"https://api.github.com/users/nokome/gists{/gist_id}","starred_url":"https://api.github.com/users/nokome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nokome/subscriptions","organizations_url":"https://api.github.com/users/nokome/orgs","repos_url":"https://api.github.com/users/nokome/repos","events_url":"https://api.github.com/users/nokome/events{/privacy}","received_events_url":"https://api.github.com/users/nokome/received_events","type":"User","site_admin":false},"milestone":null,"comments":21,"created_at":"2016-01-13T02:13:04Z","updated_at":"2016-01-22T08:54:51Z","closed_at":null,"body":"Create methods (exposed as Web API as well) that list and specify code snippets for a `Spread` (later to be merged with `Contexts` so available to `Stencils` as well).\r\n\r\n`snippets()` method and `GET @snippets` API endpoint to return a nested JSON object of snippet name/descriptions that can be browsed or searched:\r\n\r\n```js\r\n {\"Maths\":{\"sum\":\"Sum of numbers\", \"count\": \"Count of ...\"}, \"Dates and times\":{...}}\r\n```\r\n\r\n`snippet(name)` method and `GET @snippet?name=xxx` to return a JSON object specifying the snippet:\r\n\r\n```GET @snippet?name=log10```:\r\n```js\r\n{\r\n    \"desc\" : \"Base 10 logarithm of value\",\r\n    \"params\" : {\r\n        \"value\" : {\r\n            \"desc\": \"Value to compute logarithm for\"\r\n        }\r\n    },\r\n    \"code\" : \"log10(${value})\"\r\n}\r\n```\r\n\r\nThis uses the same ES6 string substitution format used by [SublimeText snippets](http://docs.sublimetext.info/en/latest/extensibility/snippets.html) and [Ace snippets](https://cloud9-sdk.readme.io/docs/snippets) but instead of having a placeholder syntax makes that explicit using `default` in `params`.\r\n\r\nBut with optional parameters it is difficult (impossible?) to generate valid and succinct code with substitution. So we might add a `eval` attribute which gives JS expression for generating a snippet. e.g.\r\n\r\n```js\r\n{\r\n    \"desc\" : \"Sum of values\",\r\n    \"params\" : {\r\n        \"value\" : {\r\n            \"desc\": \"Values to sum\"\r\n        },\r\n        \"na_rm\" : {\r\n            \"desc\": \"Should missing values (including ‘NaN’) be removed?\",\r\n            \"optional\": true\r\n        }\r\n    },\r\n    \"eval\" : \" 'sum('+nums+na_rm?(\",\"+na_rm):''+')' \"\r\n}\r\n```\r\nAn `exec` attribute could be used for more complicated, multiline code generating functions.\r\n\r\nThese will be used to generate UI's for setting cell expressions. This is what it looks like in Calc:\r\n![image](https://cloud.githubusercontent.com/assets/1152336/12283039/18b646be-ba08-11e5-8311-d5bc272310b2.png)\r\n"},"comment":{"url":"https://api.github.com/repos/stencila/stencila/issues/comments/173851412","html_url":"https://github.com/stencila/stencila/issues/96#issuecomment-173851412","issue_url":"https://api.github.com/repos/stencila/stencila/issues/96","id":173851412,"user":{"login":"michael","id":2931,"avatar_url":"https://avatars.githubusercontent.com/u/2931?v=3","gravatar_id":"","url":"https://api.github.com/users/michael","html_url":"https://github.com/michael","followers_url":"https://api.github.com/users/michael/followers","following_url":"https://api.github.com/users/michael/following{/other_user}","gists_url":"https://api.github.com/users/michael/gists{/gist_id}","starred_url":"https://api.github.com/users/michael/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michael/subscriptions","organizations_url":"https://api.github.com/users/michael/orgs","repos_url":"https://api.github.com/users/michael/repos","events_url":"https://api.github.com/users/michael/events{/privacy}","received_events_url":"https://api.github.com/users/michael/received_events","type":"User","site_admin":false},"created_at":"2016-01-22T08:54:50Z","updated_at":"2016-01-22T08:54:50Z","body":"We call in five mins."}}