omf_web 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/README.md +168 -13
  2. data/bin/omf-web-basic +3 -3
  3. data/doc/index.md +205 -0
  4. data/example/NOT_WORKING/brooklyn/brooklyn_server.rb +2 -2
  5. data/example/NOT_WORKING/frisbee/data_sources/parse_log.rb +1 -1
  6. data/example/NOT_WORKING/frisbee/viz_server.rb +1 -1
  7. data/example/NOT_WORKING/gec12/gec12_demo_server.rb +1 -1
  8. data/example/NOT_WORKING/gec12/visualization.rb +2 -2
  9. data/example/NOT_WORKING/network/network_server.rb +2 -2
  10. data/example/NOT_WORKING/wimax/test.rb +2 -2
  11. data/example/NOT_WORKING/wimax/viz_server.rb +2 -2
  12. data/example/bridge/auth_basic.rb +75 -0
  13. data/example/bridge/config.ru +101 -0
  14. data/example/bridge/configure/configure_widget.rb +32 -0
  15. data/example/bridge/data_sources/sensor-sqlite.rb +28 -6
  16. data/example/bridge/data_sources/test31.sq3 +0 -0
  17. data/example/bridge/htdocs/{js/graph → graph/js}/bridge.js +2 -2
  18. data/example/bridge/htdocs/{js/graph → graph/js}/event_line_chart.js +7 -6
  19. data/example/bridge/htdocs/{js/graph → graph/js}/event_table.js +13 -5
  20. data/example/bridge/htdocs/template/login.html +23 -0
  21. data/example/bridge/viz_server.rb +3 -5
  22. data/example/bridge/widgets/configure.yaml +12 -0
  23. data/example/bridge/widgets/login.yaml +16 -0
  24. data/example/bridge/{overview.yaml → widgets/overview.yaml} +7 -4
  25. data/example/demo/data_sources/animals.rb +1 -1
  26. data/example/demo/data_sources/downloads.rb +1 -1
  27. data/example/demo/data_sources/generator.rb +1 -1
  28. data/example/demo/data_sources/histogram.rb +1 -1
  29. data/example/demo/data_sources/mobile_network.rb +4 -3
  30. data/example/demo/data_sources/movies.rb +1 -1
  31. data/example/demo/data_sources/network.rb +4 -3
  32. data/example/demo/data_sources/returns.rb +1 -1
  33. data/example/demo/data_sources/static_network.rb +4 -3
  34. data/example/demo/data_sources/walk.rb +1 -1
  35. data/example/demo/demo_viz_server.rb +1 -1
  36. data/example/demo/widgets/linked_graphs_tab.yaml +1 -1
  37. data/example/openflow-gec15/README.md +21 -0
  38. data/example/openflow-gec15/code_tab.yaml +36 -0
  39. data/example/openflow-gec15/dashboard_tab.yaml +72 -0
  40. data/example/openflow-gec15/doc/screenshot.png +0 -0
  41. data/example/openflow-gec15/exp_source.rb +104 -0
  42. data/example/openflow-gec15/of_viz_server.rb +63 -0
  43. data/example/openflow-gec15/openflow-demo.sq3 +0 -0
  44. data/example/openflow-gec15/raw_tab.yaml +37 -0
  45. data/example/openflow-gec15/repository/of-exp.rb +12 -0
  46. data/example/openflow-gec15/repository/sample.md +52 -0
  47. data/example/openflow-gec15/repository/trema-ctl6.rb +148 -0
  48. data/example/simple/README.md +2 -0
  49. data/example/simple/data_sources/gimi31.sq3 +0 -0
  50. data/example/simple/data_sources/ping_source.rb +56 -0
  51. data/example/simple/simple_viz_server.rb +39 -0
  52. data/example/simple/widgets/charts_tab.yaml +38 -0
  53. data/lib/omf-web/config.ru +31 -3
  54. data/lib/omf-web/data_source_proxy.rb +29 -26
  55. data/lib/omf-web/rack/session_authenticator.rb +93 -0
  56. data/lib/omf-web/rack/tab_mapper.rb +10 -5
  57. data/lib/omf-web/rack/websocket_handler.rb +17 -6
  58. data/lib/omf-web/theme/abstract_page.rb +1 -1
  59. data/lib/omf-web/theme/bright/flow_renderer.rb +2 -2
  60. data/lib/omf-web/theme/bright/layout_renderer.rb +15 -0
  61. data/lib/omf-web/theme/bright/mustache_renderer.rb +29 -0
  62. data/lib/omf-web/theme/bright/one_column_renderer.rb +2 -2
  63. data/lib/omf-web/theme/bright/page.rb +33 -8
  64. data/lib/omf-web/theme/bright/tabbed_renderer.rb +2 -3
  65. data/lib/omf-web/theme/bright/two_columns_renderer.rb +3 -4
  66. data/lib/omf-web/version.rb +1 -1
  67. data/lib/omf-web/widget/code_widget.rb +0 -7
  68. data/lib/omf-web/widget/layout/two_columns_layout.rb +3 -2
  69. data/lib/omf-web/widget/mustache_widget.rb +44 -0
  70. data/lib/omf-web/widget.rb +14 -1
  71. data/lib/omf_common/lobject.rb +6 -3
  72. data/omf_web.gemspec +3 -1
  73. data/share/htdocs/graph/js/abstract_nv_chart.js +14 -4
  74. data/share/htdocs/graph/js/abstract_widget.js +5 -4
  75. data/share/htdocs/graph/js/line_chart3.js +2 -0
  76. data/share/htdocs/graph/js/map2.js +3 -3
  77. data/share/htdocs/graph/js/network2.js +51 -19
  78. data/share/htdocs/graph/js/scatter_plot.js +6 -2
  79. data/share/htdocs/graph/js/table2.js +5 -2
  80. data/share/htdocs/js/data_source2.js +40 -8
  81. data/share/htdocs/js/mustache.js +29 -0
  82. data/share/htdocs/theme/abstract/abstract.js +10 -3
  83. data/share/htdocs/vendor/mustache-0.7.0/CHANGES +21 -0
  84. data/share/htdocs/vendor/mustache-0.7.0/LICENSE +10 -0
  85. data/share/htdocs/vendor/mustache-0.7.0/README.md +374 -0
  86. data/share/htdocs/vendor/mustache-0.7.0/jquery.mustache.js +635 -0
  87. data/share/htdocs/vendor/mustache-0.7.0/mustache.js +612 -0
  88. data/share/htdocs/vendor/nv_d3/js/nv.d3.js +9 -1
  89. data/share/htdocs/vendor/raphael-2.1.0/raphael.js +5815 -0
  90. metadata +74 -9
  91. data/DESIGN_NOTES.txt +0 -56
@@ -0,0 +1,374 @@
1
+ # mustache.js - Logic-less {{mustache}} templates with JavaScript
2
+
3
+ > What could be more logical awesome than no logic at all?
4
+
5
+ [mustache.js](http://github.com/janl/mustache.js) is an implementation of the [mustache](http://mustache.github.com/) template system in JavaScript.
6
+
7
+ [Mustache](http://mustache.github.com/) is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object.
8
+
9
+ We call it "logic-less" because there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values.
10
+
11
+ For a language-agnostic overview of mustache's template syntax, see the `mustache(5)` [manpage](http://mustache.github.com/mustache.5.html).
12
+
13
+ ## Where to use mustache.js?
14
+
15
+ You can use mustache.js to render mustache templates anywhere you can use JavaScript. This includes web browsers, server-side environments such as [node](http://nodejs.org/), and [CouchDB](http://couchdb.apache.org/) views.
16
+
17
+ mustache.js ships with support for both the [CommonJS](http://www.commonjs.org/) module API and the [Asynchronous Module Definition](https://github.com/amdjs/amdjs-api/wiki/AMD) API, or AMD.
18
+
19
+ ## Who uses mustache.js?
20
+
21
+ An updated list of mustache.js users is kept [on the Github wiki](http://wiki.github.com/janl/mustache.js/beard-competition). Add yourself or your company if you use mustache.js!
22
+
23
+ ## Usage
24
+
25
+ Below is quick example how to use mustache.js:
26
+
27
+ var view = {
28
+ title: "Joe",
29
+ calc: function () {
30
+ return 2 + 4;
31
+ }
32
+ };
33
+
34
+ var output = Mustache.render("{{title}} spends {{calc}}", view);
35
+
36
+ In this example, the `Mustache.render` function takes two parameters: 1) the [mustache](http://mustache.github.com/) template and 2) a `view` object that contains the data and code needed to render the template.
37
+
38
+ ## Templates
39
+
40
+ A [mustache](http://mustache.github.com/) template is a string that contains any number of mustache tags. Tags are indicated by the double mustaches that surround them. `{{person}}` is a tag, as is `{{#person}}`. In both examples we refer to `person` as the tag's key.
41
+
42
+ There are several types of tags available in mustache.js.
43
+
44
+ ### Variables
45
+
46
+ The most basic tag type is a simple variable. A `{{name}}` tag renders the value of the `name` key in the current context. If there is no such key, nothing is rendered.
47
+
48
+ All variables are HTML-escaped by default. If you want to render unescaped HTML, use the triple mustache: `{{{name}}}`. You can also use `&` to unescape a variable.
49
+
50
+ View:
51
+
52
+ {
53
+ "name": "Chris",
54
+ "company": "<b>GitHub</b>"
55
+ }
56
+
57
+ Template:
58
+
59
+ * {{name}}
60
+ * {{age}}
61
+ * {{company}}
62
+ * {{{company}}}
63
+ * {{&company}}
64
+
65
+ Output:
66
+
67
+ * Chris
68
+ *
69
+ * &lt;b&gt;GitHub&lt;/b&gt;
70
+ * <b>GitHub</b>
71
+ * <b>GitHub</b>
72
+
73
+ JavaScript's dot notation may be used to access keys that are properties of objects in a view.
74
+
75
+ View:
76
+
77
+ {
78
+ "name": {
79
+ "first": "Michael",
80
+ "last": "Jackson"
81
+ },
82
+ "age": "RIP"
83
+ }
84
+
85
+ Template:
86
+
87
+ * {{name.first}} {{name.last}}
88
+ * {{age}}
89
+
90
+ Output:
91
+
92
+ * Michael Jackson
93
+ * RIP
94
+
95
+ ### Sections
96
+
97
+ Sections render blocks of text one or more times, depending on the value of the key in the current context.
98
+
99
+ A section begins with a pound and ends with a slash. That is, `{{#person}}` begins a `person` section, while `{{/person}}` ends it. The text between the two tags is referred to as that section's "block".
100
+
101
+ The behavior of the section is determined by the value of the key.
102
+
103
+ #### False Values or Empty Lists
104
+
105
+ If the `person` key exists and has a value of `null`, `undefined`, or `false`, or is an empty list, the block will not be rendered.
106
+
107
+ View:
108
+
109
+ {
110
+ "person": false
111
+ }
112
+
113
+ Template:
114
+
115
+ Shown.
116
+ {{#person}}
117
+ Never shown!
118
+ {{/person}}
119
+
120
+ Output:
121
+
122
+ Shown.
123
+
124
+ #### Non-Empty Lists
125
+
126
+ If the `person` key exists and is not `null`, `undefined`, or `false`, and is not an empty list the block will be rendered one or more times.
127
+
128
+ When the value is a list, the block is rendered once for each item in the list. The context of the block is set to the current item in the list for each iteration. In this way we can loop over collections.
129
+
130
+ View:
131
+
132
+ {
133
+ "stooges": [
134
+ { "name": "Moe" },
135
+ { "name": "Larry" },
136
+ { "name": "Curly" }
137
+ ]
138
+ }
139
+
140
+ Template:
141
+
142
+ {{#stooges}}
143
+ <b>{{name}}</b>
144
+ {{/stooges}}
145
+
146
+ Output:
147
+
148
+ <b>Moe</b>
149
+ <b>Larry</b>
150
+ <b>Curly</b>
151
+
152
+ When looping over an array of strings, a `.` can be used to refer to the current item in the list.
153
+
154
+ View:
155
+
156
+ {
157
+ "musketeers": ["Athos", "Aramis", "Porthos", "D'Artagnan"]
158
+ }
159
+
160
+ Template:
161
+
162
+ {{#musketeers}}
163
+ * {{.}}
164
+ {{/musketeers}}
165
+
166
+ Output:
167
+
168
+ * Athos
169
+ * Aramis
170
+ * Porthos
171
+ * D'Artagnan
172
+
173
+ If the value of a section variable is a function, it will be called in the context of the current item in the list on each iteration.
174
+
175
+ View:
176
+
177
+ {
178
+ "beatles": [
179
+ { "firstName": "John", "lastName": "Lennon" },
180
+ { "firstName": "Paul", "lastName": "McCartney" },
181
+ { "firstName": "George", "lastName": "Harrison" },
182
+ { "firstName": "Ringo", "lastName": "Starr" }
183
+ ],
184
+ "name": function () {
185
+ return this.firstName + " " + this.lastName;
186
+ }
187
+ }
188
+
189
+ Template:
190
+
191
+ {{#beatles}}
192
+ * {{name}}
193
+ {{/beatles}}
194
+
195
+ Output:
196
+
197
+ * John Lennon
198
+ * Paul McCartney
199
+ * George Harrison
200
+ * Ringo Starr
201
+
202
+ #### Functions
203
+
204
+ If the value of a section key is a function, it is called with the section's literal block of text, un-rendered, as its first argument. The second argument is a special rendering function that uses the current view as its view argument. It is called in the context of the current view object.
205
+
206
+ View:
207
+
208
+ {
209
+ "name": "Tater",
210
+ "bold": function () {
211
+ return function (text, render) {
212
+ return "<b>" + render(text) + "</b>";
213
+ }
214
+ }
215
+ }
216
+
217
+ Template:
218
+
219
+ {{#bold}}Hi {{name}}.{{/bold}}
220
+
221
+ Output:
222
+
223
+ <b>Hi Tater.</b>
224
+
225
+ ### Inverted Sections
226
+
227
+ An inverted section opens with `{{^section}}` instead of `{{#section}}`. The block of an inverted section is rendered only if the value of that section's tag is `null`, `undefined`, `false`, or an empty list.
228
+
229
+ View:
230
+
231
+ {
232
+ "repos": []
233
+ }
234
+
235
+ Template:
236
+
237
+ {{#repos}}<b>{{name}}</b>{{/repos}}
238
+ {{^repos}}No repos :({{/repos}}
239
+
240
+ Output:
241
+
242
+ No repos :(
243
+
244
+ ### Comments
245
+
246
+ Comments begin with a bang and are ignored. The following template:
247
+
248
+ <h1>Today{{! ignore me }}.</h1>
249
+
250
+ Will render as follows:
251
+
252
+ <h1>Today.</h1>
253
+
254
+ Comments may contain newlines.
255
+
256
+ ### Partials
257
+
258
+ Partials begin with a greater than sign, like {{> box}}.
259
+
260
+ Partials are rendered at runtime (as opposed to compile time), so recursive partials are possible. Just avoid infinite loops.
261
+
262
+ They also inherit the calling context. Whereas in ERB you may have this:
263
+
264
+ <%= partial :next_more, :start => start, :size => size %>
265
+
266
+ Mustache requires only this:
267
+
268
+ {{> next_more}}
269
+
270
+ Why? Because the `next_more.mustache` file will inherit the `size` and `start` variables from the calling context. In this way you may want to think of partials as includes, or template expansion, even though it's not literally true.
271
+
272
+ For example, this template and partial:
273
+
274
+ base.mustache:
275
+ <h2>Names</h2>
276
+ {{#names}}
277
+ {{> user}}
278
+ {{/names}}
279
+
280
+ user.mustache:
281
+ <strong>{{name}}</strong>
282
+
283
+ Can be thought of as a single, expanded template:
284
+
285
+ <h2>Names</h2>
286
+ {{#names}}
287
+ <strong>{{name}}</strong>
288
+ {{/names}}
289
+
290
+ In mustache.js an object of partials may be passed as the third argument to `Mustache.render`. The object should be keyed by the name of the partial, and its value should be the partial text.
291
+
292
+ ### Set Delimiter
293
+
294
+ Set Delimiter tags start with an equals sign and change the tag delimiters from `{{` and `}}` to custom strings.
295
+
296
+ Consider the following contrived example:
297
+
298
+ * {{ default_tags }}
299
+ {{=<% %>=}}
300
+ * <% erb_style_tags %>
301
+ <%={{ }}=%>
302
+ * {{ default_tags_again }}
303
+
304
+ Here we have a list with three items. The first item uses the default tag style, the second uses ERB style as defined by the Set Delimiter tag, and the third returns to the default style after yet another Set Delimiter declaration.
305
+
306
+ According to [ctemplates](http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html), this "is useful for languages like TeX, where double-braces may occur in the text and are awkward to use for markup."
307
+
308
+ Custom delimiters may not contain whitespace or the equals sign.
309
+
310
+ ## Plugins for JavaScript Libraries
311
+
312
+ mustache.js may be built specifically for several different client libraries, including the following:
313
+
314
+ - [jQuery](http://jquery.com/)
315
+ - [MooTools](http://mootools.net/)
316
+ - [Dojo](http://www.dojotoolkit.org/)
317
+ - [YUI](http://developer.yahoo.com/yui/)
318
+ - [qooxdoo](http://qooxdoo.org/)
319
+
320
+ These may be built using [Rake](http://rake.rubyforge.org/) and one of the following commands:
321
+
322
+ $ rake jquery
323
+ $ rake mootools
324
+ $ rake dojo
325
+ $ rake yui
326
+ $ rake qooxdoo
327
+
328
+ ## Testing
329
+
330
+ The mustache.js test suite uses the [vows](http://vowsjs.org/) testing framework. In order to run the tests you'll need to install [node](http://nodejs.org/). Once that's done you can install vows using [npm](http://npmjs.org/).
331
+
332
+ $ npm install -g vows
333
+
334
+ Then run the tests.
335
+
336
+ $ vows --spec
337
+
338
+ The test suite consists of both unit and integration tests. If a template isn't rendering correctly for you, you can make a test for it by doing the following:
339
+
340
+ 1. Create a template file named `mytest.mustache` in the `test/_files`
341
+ directory. Replace `mytest` with the name of your test.
342
+ 2. Create a corresponding view file named `mytest.js` in the same directory.
343
+ This file should contain a JavaScript object literal enclosed in
344
+ parentheses. See any of the other view files for an example.
345
+ 3. Create a file with the expected output in `mytest.txt` in the same
346
+ directory.
347
+
348
+ Then, you can run the test with:
349
+
350
+ $ TEST=mytest vows test/render_test.js
351
+
352
+ ## Thanks
353
+
354
+ mustache.js wouldn't kick ass if it weren't for these fine souls:
355
+
356
+ * Chris Wanstrath / defunkt
357
+ * Alexander Lang / langalex
358
+ * Sebastian Cohnen / tisba
359
+ * J Chris Anderson / jchris
360
+ * Tom Robinson / tlrobinson
361
+ * Aaron Quint / quirkey
362
+ * Douglas Crockford
363
+ * Nikita Vasilyev / NV
364
+ * Elise Wood / glytch
365
+ * Damien Mathieu / dmathieu
366
+ * Jakub Kuźma / qoobaa
367
+ * Will Leinweber / will
368
+ * dpree
369
+ * Jason Smith / jhs
370
+ * Aaron Gibralter / agibralter
371
+ * Ross Boucher / boucher
372
+ * Matt Sanford / mzsanford
373
+ * Ben Cherry / bcherry
374
+ * Michael Jackson / mjijackson