DekiScript Primer
Motivation for DekiScript <ul><li>Use Case </li></ul><ul><ul><li>Embed dynamic content </li></ul></ul><ul><ul><li>Create d...
Data Types Type Value Nil nil, null, _ Bool true, false Number (num) 123, -1.23e4 String (str) “ hi”, ‘bye’ List [ 1, 2, 3...
Basic Operations DekiScript Output {{ nil }} {{ “1” + “23” }} 24 {{ 1 .. 23 }} 123 {{ [ 1 ] .. [ 2, 3 ] }} [ 1, 2, 3] {{ {...
Control Flow Statements {{  var x = 0;  foreach(var y in [ 1, 2, 3, 4 ]) { if(y % 2 == 0) { let x += y; } } x; }} DekiScri...
User object Properties user.name User name user.homepage Homepage object user.anonymous True if user is not logged in user...
Page object Properties page.name Page name page.title Page title page.uri Uri for page page.api Uri for page web-service p...
Site object Properties site.name Name of site site.hostname Internet hostname site.api Uri for site web-service site.uri U...
Sample: Gravatars <ul><li>Gravatar for most recent page author </li></ul><div style=“float: right;”> <center> {{ page.auth...
Control Flow Attributes DekiScript Attributes <div block=“var f = page.files”>…</div> <ul if=“#f”>…</ul> <li  foreach=“var...
Sample: Gravatars, The Sequel <ul><li>Gravatars for sub-page authors </li></ul><table init=“var s = page.subpages” if=“#s”...
Finding Functions
Advanced Constructs Construct {{save: … }} Substitute on save {{edit: …}} Substitute on edit <p class=“noinclude”> Hide wh...
Sample: Custom Search Form <ul><li>Embed a form for constrained search </li></ul>Use this page to only search pages tagged...
Sample: Notebook <ul><li>Simple notebook application </li></ul><p>{{ wiki.create{  label: &quot;Add a note&quot;,  templat...
Questions? <ul><li>Slides and samples available at </li></ul><ul><ul><li>http://wiki.developer.mindtouch.com/DekiCon </li>...
Upcoming SlideShare
Loading in …5
×

DekiScript Primer

4,646 views

Published on

Introduction to DekiScript, the scripting language in MindTouch Deki

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,646
On SlideShare
0
From Embeds
0
Number of Embeds
800
Actions
Shares
0
Downloads
15
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

DekiScript Primer

  1. 1. DekiScript Primer
  2. 2. Motivation for DekiScript <ul><li>Use Case </li></ul><ul><ul><li>Embed dynamic content </li></ul></ul><ul><ul><li>Create dynamic layouts </li></ul></ul><ul><ul><li>Anybody can use it safely (i.e. not JavaScript) </li></ul></ul><ul><li>Design principles </li></ul><ul><ul><li>Not case-sensitive </li></ul></ul><ul><ul><li>Simple data types </li></ul></ul><ul><ul><li>Native support for XML </li></ul></ul><ul><ul><li>Concurrent (e.g. write-once, read-many) </li></ul></ul>
  3. 3. Data Types Type Value Nil nil, null, _ Bool true, false Number (num) 123, -1.23e4 String (str) “ hi”, ‘bye’ List [ 1, 2, 3 ] Map { a: 1, b: 2, c: 3 } Uri n/a Xml n/a
  4. 4. Basic Operations DekiScript Output {{ nil }} {{ “1” + “23” }} 24 {{ 1 .. 23 }} 123 {{ [ 1 ] .. [ 2, 3 ] }} [ 1, 2, 3] {{ { x: 1 } .. { y : 2 } }} { x: 1, y: 2 } {{ “123” != nil ? “1” : 0 }} 1 {{ nil ?? 123 }} 123 {{ false ?? 123 }} False {{ #[ 1, 2, 3 ] }} 3
  5. 5. Control Flow Statements {{ var x = 0; foreach(var y in [ 1, 2, 3, 4 ]) { if(y % 2 == 0) { let x += y; } } x; }} DekiScript var x = 123; let x += 1; if(x) { … } else { … } foreach(var x in y) { … }
  6. 6. User object Properties user.name User name user.homepage Homepage object user.anonymous True if user is not logged in user.gravatar Gravatar image user.uri Uri for user homepage user.api Uri for user web-service
  7. 7. Page object Properties page.name Page name page.title Page title page.uri Uri for page page.api Uri for page web-service page.date Date when page was edited page.author Last author on page page.subpages Sub-pages of current page page.files Files attached to page page.tags Tags associated with page
  8. 8. Site object Properties site.name Name of site site.hostname Internet hostname site.api Uri for site web-service site.uri Uri for site homepage site.homepage Homepage object site.feed Uri for site RSS feed site.pagecount Number of pages on site site.usercount Number of registered users
  9. 9. Sample: Gravatars <ul><li>Gravatar for most recent page author </li></ul><div style=“float: right;”> <center> {{ page.author.gravatar }}<br/> {{ web.link(user.uri, user.name) }} </center> </div>
  10. 10. Control Flow Attributes DekiScript Attributes <div block=“var f = page.files”>…</div> <ul if=“#f”>…</ul> <li foreach=“var x in page.files” where=“string.endswith(x.name, ‘.doc’)”> … </li> <span init=“var f = page.files” if=“#f”>…</span>
  11. 11. Sample: Gravatars, The Sequel <ul><li>Gravatars for sub-page authors </li></ul><table init=“var s = page.subpages” if=“#s” class=“table”> <tr> <th>Title</th> <th>Author</th> <th>Gravatar</th> </tr> <tr foreach=“var p in s” class=“{{__count % 2 ? ‘bg2’ : ‘bg1’}}” > <td>{{ web.link(p.uri, p.title) }}</td> <td>{{ web.link(p.author.uri, p.author.name) }}</td> <td>{{ p.author.gravatar }}</td> </tr> </table>
  12. 12. Finding Functions
  13. 13. Advanced Constructs Construct {{save: … }} Substitute on save {{edit: …}} Substitute on edit <p class=“noinclude”> Hide when included <p class=“includeonly”> Show only when included <pre|span class=“script”> Contents is script <pre class=“script” function=“syntax.xml($, true)”> Content transforms $ Template parameters __request.args Query request parameters
  14. 14. Sample: Custom Search Form <ul><li>Embed a form for constrained search </li></ul>Use this page to only search pages tagged with &quot;extensions&quot;: {{ dhtml.inputbox{value: __request.args.q, button: &quot;Search&quot;, field: &quot;q&quot;, publish: page.uri} }} {{ if(__request.args.q) { wiki.search(__request.args.q, _, _, &quot;tag:extensions&quot;) } }}
  15. 15. Sample: Notebook <ul><li>Simple notebook application </li></ul><p>{{ wiki.create{ label: &quot;Add a note&quot;, template: &quot;NotebookPage&quot;, title: date.format(date.now, &quot;yyyy MMMM, d&quot;) .. ' (' .. user.name .. ')' } }}</p> <ul> <li foreach=&quot;var p in page.subpages&quot;> {{web.link(p.uri, p.title)}} <span style=&quot;color: rgb(128, 128, 128); font-size: small;”> ({{#p.comments}} comments) </span><br /> {{ var h = wiki.page(p.path); h[&quot;//*[@class='summary']&quot;] }} </li> </ul>
  16. 16. Questions? <ul><li>Slides and samples available at </li></ul><ul><ul><li>http://wiki.developer.mindtouch.com/DekiCon </li></ul></ul><ul><li>Discussion forums at </li></ul><ul><ul><li>http://forums.developer.mindtouch.com </li></ul></ul><ul><li>Latest news at </li></ul><ul><ul><li>http://www.mindtouch.com/blog </li></ul></ul>

×