dekiscript primer

16
DekiScript Primer

Upload: mindtouch

Post on 08-May-2015

3.858 views

Category:

Technology


0 download

DESCRIPTION

Introduction to DekiScript, the scripting language in MindTouch Deki

TRANSCRIPT

Page 1: DekiScript Primer

DekiScript Primer

Page 2: DekiScript Primer

Motivation for DekiScript

• Use Case– Embed dynamic content– Create dynamic layouts– Anybody can use it safely (i.e. not JavaScript)

• Design principles– Not case-sensitive– Simple data types– Native support for XML– Concurrent (e.g. write-once, read-many)

Page 3: DekiScript Primer

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

Page 4: DekiScript Primer

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

Page 5: DekiScript Primer

Control Flow Statements

DekiScript

var x = 123;

let x += 1;

if(x) { … } else { … }

foreach(var x in y) { … }

{{ var x = 0; foreach(var y in [ 1, 2, 3, 4 ]) {

if(y % 2 == 0) {let x += y;

}}x;

}}

Page 6: DekiScript Primer

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

Page 7: DekiScript Primer

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

Page 8: DekiScript Primer

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

Page 9: DekiScript Primer

Sample: Gravatars

Gravatar for most recent page author

<div style=“float: right;”><center>

{{ page.author.gravatar }}<br/>{{ web.link(user.uri, user.name) }}

</center></div>

Page 10: DekiScript Primer

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>

Page 11: DekiScript Primer

Sample: Gravatars, The Sequel

Gravatars for sub-page authors

<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>

Page 12: DekiScript Primer

Finding Functions

Page 13: DekiScript Primer

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

Page 14: DekiScript Primer

Sample: Custom Search Form

Embed a form for constrained search

Use this page to only search pages tagged with "extensions":{{ dhtml.inputbox{value: __request.args.q, button: "Search", field: "q", publish: page.uri} }}

{{ if(__request.args.q) { wiki.search(__request.args.q, _, _, "tag:extensions")

} }}

Page 15: DekiScript Primer

Sample: Notebook

Simple notebook application

<p>{{ wiki.create{ label: "Add a note", template: "NotebookPage", title: date.format(date.now, "yyyy MMMM, d") ..

' (' .. user.name .. ')' } }}</p><ul> <li foreach="var p in page.subpages">

{{web.link(p.uri, p.title)}} <span style="color: rgb(128, 128, 128); font-size: small;”>

({{#p.comments}} comments)</span><br />{{ var h = wiki.page(p.path); h["//*[@class='summary']"] }}

</li></ul>

Page 16: DekiScript Primer

Questions?

• Slides and samples available at– http://wiki.developer.mindtouch.com/DekiCon

• Discussion forums at– http://forums.developer.mindtouch.com

• Latest news at– http://www.mindtouch.com/blog