Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #255 (closed enhancement: fixed)

Opened 14 years ago

Last modified 11 years ago

Enable interactive JavaScript interpreter on pages while in development

Reported by: kevin Owned by: godoy
Priority: normal Milestone: 0.9
Component: TurboGears Version:
Severity: normal Keywords: javascript interactive interpreter development
Cc:

Description

From Gunfighter on the mailing list:

MochiKit has a ton of great features. A feature I've found helpful when
working with my TG app is the interactive interpreter as demonstrated
on the MochiKit site:
http://www.mochikit.com/examples/interpreter/index.html

I decided to integrate this into my application as a debugging tool,
but didn't want it to pop up on each page, so here's what I came up
with:

You should already have this line in the header:
<script type="text/javascript" src="tg_js/MochiKit.js"></script>

Download the MochiKit distribution (http://mochikit.com/download.html)
and put it somewhere accessible (like the static folder of your
project), then put the following code in your header as well
(substituting your path to the MochiKit distro as appropriate):
---------------------------------------------
<link href="[PATH TO MOCHIKIT]/examples/interpreter/interpreter.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript" src="[PATH TO
MOCHIKIT]/examples/interpreter/interpreter.js"></script>
<script type="text/javascript">
function debug() {
   if (!debug.box) {
       debug.box = document.createElement("div");
       debug.box.setAttribute("style",
                              "background-color: white; " +
                              "border: solid black 3px; " +
                              "padding: 10px;");
       document.body.appendChild(debug.box);
   }

   // Start Mochikit interpreter
   if (!(typeof(interpreterManager) == "undefined")) {
           debugString = '<h5>Interactive Javascript
Interpreter/Debugger</h5><form id="interpreter_form"><div
id="interpreter_area"><div id="interpreter_output"></div></div><input
id="interpreter_text" name="input_text" type="text" class="textbox"
size="100" /></form>';
           debug.box.innerHTML = debugString;
           interpreterManager.initialize();
   } else {
           debugString = '<h5>MochiKit Interactive
Interpreter/Debugger Not Found</h5>';
           debug.box.innerHTML = debugString;
   }
}
</script>
---------------------------------------------

The code shouldn't intrude in your normal day-to-day development/usage
of the application; however, when you need to peek under the hood and
check out or experiment with the JavaScript on any given page, you just
type "javascript:window.debug()" in your browser's address bar (or
create a bookmarklet for it), and up pops the interpreter at the bottom
of your page.

If we make a special development mode version of sitetemplate that includes this automatically, this can automatically be available when working on a TG app.

Change History

comment:1 Changed 13 years ago by godoy

  • Owner changed from anonymous to godoy
  • Keywords javascript interactive interpreter development added
  • Milestone set to 0.9

I'll try making a widget with this... Lets see what comes of it... As a first step, I'll make it enabled all the time, as a second step I'll disable it in production mode.

comment:2 Changed 13 years ago by godoy

OK. It is done (first step, I mean). I'll check licensing issues since I'm just packaging the interpreter CSS and JS from MochiKit? examples and the code above (which I believe it free domain as stated in this trac, so there's only MochiKit? licensing to deal with) and I'll publish this preliminar widget so that it can be (ab)used.

It is nice seeing it at the bottom of the toolbox ;-)

(And writing a widget is getting VERY easy with TG!)

comment:3 Changed 13 years ago by godoy

  • Status changed from new to closed
  • Resolution set to fixed

Made available at  http://cheeseshop.python.org/pypi/MochiInterpreter/0.5 since MochiKit? is licensed under MIT License. I've also added a "LICENSE.interpreter" with Bob's MIT quotation from his LICENSE.txt for MochiKit?.

I'll be implementing step 2 soon, but I'll close this bug.

comment:4 Changed 13 years ago by godoy

comment:5 Changed 13 years ago by bob@…

You'll probably want to sync up with MochiKit? 1.3's interpreter example soon, I added multi-line input.

comment:6 Changed 13 years ago by godoy

Thanks Bob! I'll do that. I was also thinking about tying the version to the version of MochiKit?, so this would be MochiInterpreter? 1.3 when synchronized with your 1.3 release. It would be easier to follow :-)

comment:7 Changed 13 years ago by michele

Good idea Jorge.

Note: See TracTickets for help on using tickets.