demo/demo/widgets/live.py | 12 ++++++
development.ini | 2 +
docs/_templates/indexcontent.html | 4 ++
docs/main/HelloWorld.rst | 39 +++++++++++++++++++++-
docs/main/UsingLiveSocketOutsideOfMoksha.rst | 34 +++++++++++++++++++
moksha/api/widgets/amqp/amqp.py | 4 +-
moksha/api/widgets/stomp/stomp.py | 4 +-
moksha/apps/demo/MokshaJQPlotDemo/development.ini | 3 +
8 files changed, 96 insertions(+), 6 deletions(-)
New commits:
commit 49288d37bb85ea614449fe47e4a64009b01bcc49
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue Nov 23 15:54:26 2010 -0500
Add an example of using moksha.send_message in our HelloWorld docs
diff --git a/docs/main/HelloWorld.rst b/docs/main/HelloWorld.rst
index 56ca93f..2dc335d 100644
--- a/docs/main/HelloWorld.rst
+++ b/docs/main/HelloWorld.rst
@@ -248,6 +248,34 @@ You can send messages with Moksha's JavaScript API using the
following function:
moksha.send_message('helloworld', {'foo': 'bar'});
+So let's add a simple little text field to our HelloWorldWidget that allows people
+to send messages to the `helloworld` topic:
+
+.. code-block:: python
+
+ class HelloWorldWidget(LiveWidget):
+ topic = "helloworld"
+ template = """
+ <b>Hello World Widget</b>
+ <form onsubmit="return send_msg()">
+ <input name="text" id="text"/>
+ </form>
+
+ <ul id="data"/>
+
+ <script>
+ function send_msg() {
+ moksha.send_message('helloworld', {'msg':
$('#text').val()});
+ $('#text').val('');
+ return false;
+ }
+ </script>
+ """
+ onmessage = """
+ $('<li/>').text(json.msg).prependTo('#data');
+ """
+
+
Creating a database model
-------------------------
commit 74a2e0825f3029b6d3a3164221d11fbdf551b8d1
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue Nov 23 15:03:10 2010 -0500
Allow people to send messages in our basic HelloWorldWidget demo
diff --git a/demo/demo/widgets/live.py b/demo/demo/widgets/live.py
index f9d0ad4..d77e974 100644
--- a/demo/demo/widgets/live.py
+++ b/demo/demo/widgets/live.py
@@ -4,7 +4,19 @@ class HelloWorldWidget(LiveWidget):
topic = "helloworld"
template = """
<b>Hello World Widget</b>
+ <form onsubmit="return send_msg()">
+ <input name="text" id="text"/>
+ </form>
+
<ul id="data"/>
+
+ <script>
+ function send_msg() {
+ moksha.send_message('helloworld', {'msg':
$('#text').val()});
+ $('#text').val('');
+ return false;
+ }
+ </script>
"""
onmessage = """
$('<li/>').text(json.msg).prependTo('#data');
commit b9323c9e0f5fa5394faf0523dd4c7b57d359055b
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue Nov 23 14:41:17 2010 -0500
Use jQuery.parseJSON in our live widgets, which will use the native browser
JSON mechanisms if available.
diff --git a/moksha/api/widgets/amqp/amqp.py b/moksha/api/widgets/amqp/amqp.py
index 86589b6..d1c907e 100644
--- a/moksha/api/widgets/amqp/amqp.py
+++ b/moksha/api/widgets/amqp/amqp.py
@@ -89,7 +89,7 @@ class AMQPSocket(Widget):
var dest = msg.header.delivery_properties.routing_key;
var json = null;
try {
- var json = $.secureEvalJSON(msg.body);
+ var json = $.parseJSON(msg.body);
} catch(err) {
moksha.error("Unable to decode JSON message body");
moksha.error(msg);
diff --git a/moksha/api/widgets/stomp/stomp.py b/moksha/api/widgets/stomp/stomp.py
index dafa2ab..a332d75 100644
--- a/moksha/api/widgets/stomp/stomp.py
+++ b/moksha/api/widgets/stomp/stomp.py
@@ -114,7 +114,7 @@ class StompWidget(Widget):
var dest = f.headers.destination;
var json = null;
try {
- var json = $.secureEvalJSON(f.body);
+ var json = $.parseJSON(f.body);
} catch(err) {
moksha.error("Unable to decode JSON message
body");
moksha.error(msg);
commit 8a2ec5e9df4d36e3bf6196db36723efa8f600736
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue Nov 23 14:38:30 2010 -0500
Use moksha.error instead of debug
diff --git a/moksha/api/widgets/amqp/amqp.py b/moksha/api/widgets/amqp/amqp.py
index 785a1a5..86589b6 100644
--- a/moksha/api/widgets/amqp/amqp.py
+++ b/moksha/api/widgets/amqp/amqp.py
@@ -92,7 +92,7 @@ class AMQPSocket(Widget):
var json = $.secureEvalJSON(msg.body);
} catch(err) {
moksha.error("Unable to decode JSON message body");
- moksha.debug(msg);
+ moksha.error(msg);
}
if (moksha_callbacks[dest]) {
for (var i=0; i < moksha_callbacks[dest].length; i++) {
diff --git a/moksha/api/widgets/stomp/stomp.py b/moksha/api/widgets/stomp/stomp.py
index 51c7c13..dafa2ab 100644
--- a/moksha/api/widgets/stomp/stomp.py
+++ b/moksha/api/widgets/stomp/stomp.py
@@ -117,7 +117,7 @@ class StompWidget(Widget):
var json = $.secureEvalJSON(f.body);
} catch(err) {
moksha.error("Unable to decode JSON message
body");
- moksha.debug(msg);
+ moksha.error(msg);
}
if (moksha_callbacks[dest]) {
for (var i=0; i < moksha_callbacks[dest].length; i++) {
commit 9b23967191316df31aa55f7e61b8594e162367c1
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue Nov 23 14:38:02 2010 -0500
Specify the mako compiled templates directory
diff --git a/development.ini b/development.ini
index 21e350d..7b938e8 100644
--- a/development.ini
+++ b/development.ini
@@ -151,6 +151,8 @@ sqlalchemy.pool_recycle = 3600
# Uses python's logging config file format
#
http://docs.python.org/lib/logging-config-fileformat.html
+templating.mako.compiled_templates_dir = %(here)s/data/templates
+
[loggers]
keys = root, moksha, sqlalchemy, tg, auth, pylons
diff --git a/moksha/apps/demo/MokshaJQPlotDemo/development.ini
b/moksha/apps/demo/MokshaJQPlotDemo/development.ini
index e28d11d..0305c5d 100644
--- a/moksha/apps/demo/MokshaJQPlotDemo/development.ini
+++ b/moksha/apps/demo/MokshaJQPlotDemo/development.ini
@@ -68,7 +68,8 @@ templating.mako.reloadfromdisk = true
# you'll most certainly want to have apache or nginx to write in a directory
# that does not contain any source code in any form for obvious security reasons.
#
-#templating.mako.compiled_templates_dir = /some/dir/where/webserver/has/access
+templating.mako.compiled_templates_dir = %(here)s/data/templates
+
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
commit 4f5bf842b49a4999abc28c58de6925749caac061
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu Nov 18 16:43:44 2010 -0500
Document Sending messages to from the Live Widget in our Hello World doc
diff --git a/docs/main/HelloWorld.rst b/docs/main/HelloWorld.rst
index 0f8616e..56ca93f 100644
--- a/docs/main/HelloWorld.rst
+++ b/docs/main/HelloWorld.rst
@@ -239,6 +239,15 @@ new messages as they arrive in the users web browser.
:doc:`LiveWidget`
+Sending messages to from the Live Widget
+----------------------------------------
+
+You can send messages with Moksha's JavaScript API using the following function:
+
+.. code-block:: javascript
+
+ moksha.send_message('helloworld', {'foo': 'bar'});
+
Creating a database model
-------------------------
commit 49ea3990bbd57abdb968961735eea9708d1bb0a2
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu Nov 18 16:43:27 2010 -0500
Link to the demo source in our Hello World doc
diff --git a/docs/main/HelloWorld.rst b/docs/main/HelloWorld.rst
index 729c75a..0f8616e 100644
--- a/docs/main/HelloWorld.rst
+++ b/docs/main/HelloWorld.rst
@@ -5,7 +5,7 @@ Hello World Moksha Demo
The goal of this tutorial is to show the simplicity of Moksha's API by creating
basic "Hello World" components in one demo.
-<link to directory of code and tarball>
+:Demo Source:
https://fedorahosted.org/moksha/browser/demo
The Controller
--------------
commit 61f9d561826244e1597257f6282b19be74a7a8ba
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu Nov 18 16:43:11 2010 -0500
Link to our new docs from our main index
diff --git a/docs/_templates/indexcontent.html b/docs/_templates/indexcontent.html
index fc32192..ecfeb3c 100644
--- a/docs/_templates/indexcontent.html
+++ b/docs/_templates/indexcontent.html
@@ -7,6 +7,8 @@
<span class="linkdescr">High-level goals and
concepts</span></p>
<p class="biglink"><a class="biglink" href="{{
pathto("main/GettingStarted") }}">Getting Started</a><br/>
<span class="linkdescr">Instructions for diving
in</span></p>
+ <p class="biglink"><a class="biglink" href="{{
pathto("main/HelloWorld") }}">Hello World Demo</a><br/>
+ <span class="linkdescr">A simple Hello World
demo</span></p>
<p class="biglink"><a class="biglink" href="{{
pathto("main/MokshaLabs") }}">Moksha Labs</a><br/>
<span class="linkdescr">Experimental apps and
widgets</span></p>
<p class="biglink"><a class="biglink" href="{{
pathto("main/Messaging") }}">Messaging</a><br/>
@@ -22,6 +24,8 @@
<span class="linkdescr">Features of and the technology behind
them</span></p>
<p class="biglink"><a class="biglink" href="{{
pathto("main/QuickstartTemplates") }}">Quickstart
Templates</a><br/>
<span class="linkdescr">Quickly create Moksha
components</span></p>
+ <p class="biglink"><a class="biglink" href="{{
pathto("main/UsingLiveSocketOutsideOfMoksha") }}">Using the Live Socket
outside of Moksha</a><br/>
+ <span class="linkdescr">Hook any web page up to your message
broker</span></p>
<p class="biglink"><a class="biglink" href="{{
pathto("main/PluginEntryPoints") }}">Plugin Entry
Points</a><br/>
<span class="linkdescr">Details on plugging in various
components</span></p>
<p class="biglink"><a class="biglink" href="{{
pathto("main/IntegratingWithTG2") }}">TurboGears2</a><br/>
commit 291bd0e842fc98f9e70285c4b34d997671523f8f
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu Nov 18 16:42:51 2010 -0500
Add an initial doc on using Moksha's real-time pipes outside of Python
diff --git a/docs/main/UsingLiveSocketOutsideOfMoksha.rst
b/docs/main/UsingLiveSocketOutsideOfMoksha.rst
new file mode 100644
index 0000000..37dc9ed
--- /dev/null
+++ b/docs/main/UsingLiveSocketOutsideOfMoksha.rst
@@ -0,0 +1,34 @@
+Using Moksha's real-time pipes outside of Python
+================================================
+
+Want to add realtime functionality to your existing web site, but don't want to
+have to learn Python or TurboGears?
+
+Thankfully, Moksha allows you to leverage it's realtime pipes on any existing
+web page without having to write a line of Python code.
+
+Add code snippet to your web page
+Configure your message broker
+Start Moksha
+
+.. code-block:: html
+
+ <html>
+ <head>
+ <script
src="http://code.jquery.com/jquery-latest.min.js"></scrip...
+ </head>
+ <body>
+ <ul id="data"/>
+ </body>
+ <script>
+ function consume_message(msg) {
+ $('<li/>').text(msg).appendTo('#data')
+ }
+ </script>
+ <script type="text/javascript"
src="http://localhost:8080/livesocket?topic=helloworld&callback=consume_message"></script>
+ </html>
+
+Caveats
+-------
+
+Must be under the same domain name.