3 category: JavaScript libraries
8 ### [Initialization](http://docs.ractivejs.org/latest/options)
13 template: '...', // required
16 init: function() {}, // on instantiate
17 complete: function() {}, // on finish animations
21 partials: { ... }, // global: Ractive.partials
22 transitions: { ... }, // global: Ractive.transitions
30 noIntro: true // true = disable transition on initial render
31 lazy: false // false = use keyevents, true = use change/blur
32 append: false // false = overwrite element, true = append
41 view.add('count', 1) //=> promise
42 view.subtract('count', 1) //=> promise
43 view.toggle('shown') //=> promise
47 view.reset({ a: true })
48 view.merge('list', [a,b,c])
53 ### Nodes and components
56 view.findAll('.klass')
58 view.nodes['hello'] // .find('#hello')
60 view.findComponent('photo')
61 view.findAllComponents('photo')
65 view.on('event', function() { ... })
74 view.insert('.node .path')
76 view.observe({ 'name': function() { ... } })
78 view.toHTML() //=> String
83 View = Ractive.extend({
88 ## [Components](https://github.com/RactiveJS/Ractive/wiki/Components)
90 See: https://github.com/RactiveJS/Ractive/issues/74
93 Widget = Ractive.extend({ ... })
95 ractive = new Ractive({
97 template: '<widget foo="bar"/>',
106 Ractive.partials.x = "<..>"
114 <button on-click='activate'>Activate!</button>
117 activate: function () { ... }
120 <button on-click='sort:name'>Sort by name</button>
121 view.on('sort', function (e, column) {
122 console.log('sorting by #{column}');
127 view.observe("name", function (name) {
128 console.log("Changed name to", name);
134 Body: {{{unescaped}}}
138 <li>{{this.name}}</li>
140 <li>{{.}}</li> <!-- same as 'this' -->
143 {{^user}}Not logged in{{/user}} <!-- if false -->
144 {{#user}}Welcome, sire{{/user}} <!-- if true -->
149 {{#statusDogs[selected]}}
151 ## Transformed attributes
153 This transforms the `list` attribute via a helper function called `sort()`.
155 {{# sort(list, "name") :num }}
156 <li>{{num}} - {{name}}</li>
157 {{/ end. any text goes here }}
160 sort: function(array, column) { return array.whatever(); }
167 <div intro="bump:{duration:400}">
169 Ractive.transitions.bump = function(t, params) {
170 params = t.processParams( params, {
172 color: t.isIntro ? 'rgb(0,255,0)' : 'rgb(255,0,0)'
184 ## [Decorators](http://docs.ractivejs.org/latest/decorators)
186 <span decorator="tooltip:hello there">Hover me</span>
189 tooltip: function (node, content) {
192 teardown: function () {
199 <span decorator="tooltip:'a','b',2,'c'">Hover me</span>
201 tooltip: function (node, a, b, two, c) { ... }
203 ## [Adaptors](http://docs.ractivejs.org/latest/adaptors)
206 filter: function (object, keypath, ractive) {
207 // return `true` if a particular object is of the type we want to adapt
209 wrap: function (ractive, object, keypath, prefixer) {
210 // set up event bindings here
211 object.on('change', function () { ractive.set(prefixer({...})); });
212 // then return a wrapper:
214 teardown: function () { .. },
215 // json representation
216 get: function () { return { a:2, b:3, c:4, ... }; },
217 // called on ractive.set
218 set: function (key, val) { },
219 // called on ractive.set on root (return false = die)
220 reset: function (data) { return false; }
225 ## [Computed properties](http://docs.ractivejs.org/latest/computed-properties)
228 template: '{{area}}',
230 area: function () { return this.get('width') * this.get('height'); }
231 area: '${width} * ${height}'
233 get: '${first} + " " + ${last}"
234 set: function (name) { ... }