Commits

Greg Slepak committed 689c291

- Converted all javascript stuff in dragonfly.js to using jQuery
- Improved the ajax functions and demo to use jQuery
- Separated "User Guide" into "User Guide" and "Examples"

  • Participants
  • Parent commits c8be3c6

Comments (0)

Files changed (13)

+Version 0.50
+
+  * massive rewrite. too many changes to list, if you want to see them look through the mercurial change log:
+	http://code.google.com/p/dragonfly-newlisp/source/list
+	or the updates list (similar to the other link, but with fewer details):
+	http://code.google.com/p/dragonfly-newlisp/updates/list
+
 Version 0.20
 
   * changed license from MIT to GNU (GPL v3)

File UPGRADE_GUIDE

 	are user-customizable and which are not, and to make naming
 	conflicts more difficult.
 	
-* To avoid having too many constants all over the place, possibly
-  causing confusion and conflicts with other similarly named variables,
-  and to avoid cluttering the code, all environment variables have simply
-  been placed into the PHP-like env map. Some constants still
-  exist, namely those starting with 'dragonfly'
+* Environment variables are now global constants and therefore
+  the ones formerly in Dragonfly context should be converted like this:
 
-	Dragonfly:host => (env "HTTP_HOST")
-	Dragonfly:useragent => (env "HTTP_USER_AGENT")
-	Dragonfly:server => (env "SERVER_SOFTWARE")
-	Dragonfly:programfiles => (env "PROGRAMFILES")
-	Dragonfly:proxy => (env "HTTP_PROXY")	
+	Dragonfly:host => HTTP_HOST
+	Dragonfly:useragent => HTTP_USER_AGENT
+	Dragonfly:server => SERVER_SOFTWARE
+	Dragonfly:programfiles => PROGRAMFILES
+	Dragonfly:proxy => HTTP_PROXY	
 
-	You can also use the new PHP-like symbol $SERVER instead of env.
+	Alternatively you can use 'env' or '$SERVER' to access them:
 	
-	Example: ($SERVER "HTTP_HOST")
+	Example: ($SERVER "HTTP_HOST")
+	

File example-site/dragonfly-framework/plugins-active/dragonfly_basic.lsp

 ;;  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ;;
 ;; @module Dragonfly
-;; @author Marc Hildmann <marc.hildmann at gmail.com>
+;; @author Marc Hildmann <marc.hildmann at gmail.com>, Greg Slepak <greg at taoeffect.com>
 ;; @version 0.20
 ;; 
 ;; @location http://code.google.com/p/dragonfly-newlisp/
 
 (context 'Dragonfly)
 
-; TODO: these are copied from dragonfly.lsp, and they're probably going to be
-;       moved or deleted further.
-(constant 'databases-path (string DOCUMENT_ROOT"/databases/"))
-
-; init symbols for Dragonfly listener
-(set 'viewname "")
-(set 'action "")
-(set 'params "")
-(set 'selector "")
-
 ;; @syntax (Dragonfly:benchmark-start)
 ;; <p>Sets the start point for benchmarking.</p>
 ;; 
 	<h2>REQUEST METHOD</h2>"REQUEST_METHOD"
 	<h2>DEFAULT VIEW</h2>"DEFAULT_VIEW"
 	<h2>CURRENT VIEW</h2>"viewname"
-	<h2>VIEW ACTION</h2>"action"
 	<h2>USER-AGENT</h2>"HTTP_USER_AGENT"
 	<h2>Proxy</h2>"HTTP_PROXY"
 	<h2>SERVER</h2>"SERVER_SOFTWARE"
 ;; <p>Writes the Google Analytics tracking code.</p>
 ;;
 (define (google-analytics analytics-id)
-	(print "
-	<script type=\"text/javascript\">
-		var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");
-		document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));
+	(print [text]
+	<script type="text/javascript">
+		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+		document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
 		</script>
-		<script type=\"text/javascript\">
+		<script type="text/javascript">
 		try {
-			var pageTracker = _gat._getTracker(\""analytics-id"\");
+			var pageTracker = _gat._getTracker("[/text] analytics-id [text]");
 			pageTracker._trackPageview();
 		} catch(err) {}
 	</script>				
-	")
+	[/text])
 )
 
 
 ;; @param <view> a string containing the view
 ;; <p>Writes a internal link</p>
 ;; 
-(define (link_to link-name view action)
-	
-  	; if Dragonfly runs on newLISP webSERVER_SOFTWARE, we cannot
+(define (link_to link-name view , link-url)
+  	; if Dragonfly runs on newLISP SERVER_SOFTWARE, we cannot
   	; use .htaccess, so we've to write the "?" into the url
     ; else we miss it
-	(if (true? (find "newLISP" SERVER_SOFTWARE))
+	(if (find "newLISP" SERVER_SOFTWARE)
 		(set 'link-url (string "?" view))
 		(set 'link-url (string "/" view))
 	)
-	(if action (write-buffer link-url (string "/" action)))
-	
-  	(print "<a href='"(web-root link-url)"'>"link-name"</a>")
+  	(print "<a href=\"" (web-root link-url) "\">" link-name "</a>")
 )
 
 ;; @syntax (Dragonfly:link_to <link_name> <url>)
 ;; <p>Writes a standard HTML link</p>
 ;; 
 (define (link_to_external link-name url)
-		
   	(print "<a href='"url"'>"link-name"</a>")
-
 )
 
 ;; @syntax (Dragonfly:link_mailto <link_name> <options>)
 ;; <p>Writes a standard HTML mailto link</p>
 ;; 
 (define (link_mailto link-name link-url)
-  (print "<a href='mailto:"link-url"'>"link-name"</a>")
+	(print "<a href='mailto:"link-url"'>"link-name"</a>")
 )
 
 
 ; !AJAX Functions
 ;===============================================================================
 
-;; @syntax (Dragonfly:ajax-updater <html-elementid> <request-url> <params-url> <timeout>)
+;; @syntax (Dragonfly:ajax-updater <html-elementid> <request-url> <str-params> <timeout>)
 ;; @param <html-elementid> a string containing the elementID
 ;; @param <request-url> a string containing the url which is called frequently
-;; @param <params-url> a string containing params which are POSTED against request-url
-;; @param <timeout> an integer containing the number of microseconds after recalling the request-url
+;; @param <str-params> a string containing params which are POSTED against request-url
+;; @param <int-timeout> an integer containing the number of microseconds after recalling the request-url
 ;; <p>Writes a simple AJAX-updater, e.g. for displaying the time on a website.</p>
-;;
-(define (ajax-updater html-elementid request-url params-url timeout)
-	(print "<div id='"html-elementid"'>&nbsp;</div>")
-	(print "<script language='javascript'>")
-	(print "function responseFunction(responseText, responseStatus) {")
-	(print "var response = responseText;")
-	(print "document.getElementById('"html-elementid"').innerHTML = response;")	
-	(print "setTimeout(\"ajax"html-elementid".post('"params-url"');\","timeout");")
-	(print "}")
-	
+(define (ajax-updater html-elementid request-url str-params timeout)
 	; check for newLISP as webSERVER_SOFTWARE, then we've to use a ? before request-url, because there's no working .htaccess
 	(when (find "newLISP" SERVER_SOFTWARE)
 		(if (starts-with request-url "/") (pop request-url))
 		(push "/?" request-url)
 	)
 	(set 'request-url (web-root request-url))
-	(print "var ajax"html-elementid" = new AjaxRequest(\""request-url"\", responseFunction);")
-	
-	(print "ajax"html-elementid".post(\""params-url"\");")
-	(print "</script>")
+	; 'fetcher' is prevented from entering the global scope because
+	; of the surrounding parenthesis. Meaning, this code won't conflict if
+	; it's listed multiple times on the page. The parenthesis play two roles:
+	; to protect it from entering the global scope, and to call the function.
+	(print (format [text]
+		<div id="%s">&nbsp;</div>
+		<script type="text/javascript">
+			(function fetcher() {
+				$.post("%s", "%s",
+					function (data, status) {
+						$("#%s").html(data);
+						setTimeout(fetcher, %d);
+					}
+				);
+			})();
+		</script>
+		[/text] html-elementid request-url str-params html-elementid timeout)
+	)
 )
 
 (context Dragonfly)

File example-site/dragonfly-framework/plugins-active/dragonfly_nldb.lsp

 
 (context 'Dragonfly)
 
+(constant 'databases-path (string DOCUMENT_ROOT "/databases/"))
+
 ;===============================================================================
 ; !nldb Wrapper for a pure newLISP Database (flat)
 ;===============================================================================

File example-site/includes/css/screen.css

 
 /* Dragonfly User Guide Menu */
 
-#menu {
+.menu {
 		width: 470px;
 		display: block;
 		background: #000000;
 		padding-bottom:10px;
 }
 
-#menu dt {
+.menu dt {
 	font-weight: bold;
 	font-size: 13px;
 	color:#00aeef;
 }
 
-#menu dd {
+.menu dd {
 	padding-left:5px;
 	font-weight: normal;
 	font-size: 11px;
 }
 	
-#menu dt { padding:0; margin:8px 0 0 0;}
-#menu a { color: #ffffff; background: none !important;}
-#menu .L, #menu .R {float: left; width: 50%; margin: 0; padding: 0;}
-#menu .R { float: right; }
+.menu dt { padding:0; margin:8px 0 0 0;}
+.menu a { color: #ffffff; background: none !important;}
+.menu .L, .menu .R {float: left; width: 50%; margin: 0; padding: 0;}
+.menu .R { float: right; }
 
 /* Dragonfly Styles */
 

File example-site/includes/js/dragonfly.js

-/* scrollTo function for iPhone support */
-window.onload = function () {
-		this.scrollTo(0, 1);
-};
-	
-/* toggleMenu function for Dragonfly User Guide Menu */
-function toggleMenu() {
-
-	/* very basic without animation */
-	if ($('#menu').is(':visible')) {
-	    $('#menu').hide();
-	} else {
-	    $('#menu').show();
-	}
-
-}
-
-
-/* simple AJAX Request */
-
-function AjaxRequest(url, completeFunction) {
-	var request = this;
-	var request_url = url;
-	
-	this.callback = completeFunction || function () { };
-	this.post = function(params) {
-		request.http = null;
-		if (window.XMLHttpRequest) {
-			request.http = new XMLHttpRequest();
-		} else {
-			request.http = new ActiveXObject("Microsoft.XMLHTTP");
-		}
-	
-	if (request.http == null) {
+$(document).ready(function () {
+	window.scrollTo(0, 1); // scrollTo function for iPhone support
+	$("a.menu_toggle").click(function () {
+		$(this).parent().siblings().children("div.menu:visible").hide(); // hide the other visible menus
+		$(this).next().toggle(); // toggle our menu
 		return false;
-	} else {
-		request.http.onreadystatechange = function() {
-			if (request.http.readyState == 4 && request.http.status == 200) {
-				request.callback(request.http.responseText, request.http.status, request.http.responseXML);
-				request.http = null;
-			}
-		}
-
-		request.http.open("POST", request_url, true);
-		request.http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
-		request.http.setRequestHeader("Content-Length", params.length);
-		request.http.send(params);
-		return true;
-	}	
-	
-	}
-}
-
-
-
-
+	});
+});

File example-site/views/dragonfly_ajax.html

 		<p class="extract">Dragonfly provides some simple AJAX functions. With AJAX, web applications can retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page. The use of AJAX techniques has led to an increase in interactive or dynamic interfaces on web pages and better quality of Web services due to the asynchronous mode. Data is usually retrieved using the XMLHttpRequest object. (source: wikipedia.org)
 		</p>
 		<h2>Current time</h2>
-		<p><% (ajax-updater "timer" "/dragonfly_ajax-date" "gettime" "1000") %></p>
+		<% (ajax-updater "timer" "/dragonfly_ajax-date" "gettime" 1000) %>
 
 		<h2>Real-time tweets for 'michael jackson'</h2>
-		<p><% (ajax-updater "twitter" "/dragonfly_ajax-twitter" "gettweets" "1000") %></p>
+		<% (ajax-updater "twitter" "/dragonfly_ajax-twitter" "gettweets" 5000) %>
 		
 		<div class="line-dotted"></div>
 

File example-site/views/dragonfly_routes.html

 
 		<p class="config"><b>Configuration</b><br/>Set Your resource directory to whatever You want by changing the constant RESOURCES_PATH in config.lsp. Default is set to "/resources".</p>	
 		
-		
-		<h2>Using views</h2>
-		<p class="extract">A view is simply a web page, or a page fragment, like a header or footer. In fact, views can flexibly be embedded within other views. In that case we call them partials.</p>
-
-		<h3 class="code">How to load a view</h3>
-		<p>Example: open Your favorite text-editor and enter the following:</p>
-		<pre class="code">Hello World</pre>
-		<p>Save the file as "hello" into Your views directory. Now open Your browser and navigate to <a href="http://www.example-site.com/hello">example-site.com/hello</a>. That's it!</p>
-		<p class="info"><b>Information</b><br/>You can put nearly everything into views: (X)HTML, Javascript, newLISP code.</p>
-		<p class="config"><b>Configuration</b><br/>If VIEW_EXTENSION is ".html" for example, then when example-site.com/hello is called Dragonfly will search for a "hello.html" file in the VIEWS_PATH. It also applies to the partials, too.</p>
-
-		<h3 class="code">How to call functions inside a view</h3>
-		<pre class="code">&lt;% (benchmark-result) %&gt;</pre>
-		
-		<p>Put Your function call inside our open and close brackets and there You go! That will display some stats about rendering time and memory consumption.</p>
-		
-		<p class="info"><b>Information</b><br/>You can use all functions from newLISP and Dragonfly. Additionally You may write Your own functions inside a plugin and just put the file into the "plugins-active" directory.</p>
-				
-		<h3 class="code">How to load a partial view</h3>
-		<pre class="code">&lt;% (display-partial "header") %&gt;</pre>
-		
-		<p>This simple argument would load the "header"-partial from the partials directory.</p>
-
-		
 		<div class="line-dotted"></div>
 
 		<% (benchmark-result) %>

File example-site/views/dragonfly_views.html

+<% (display-partial "doctype") %>
+<% (display-partial "header") %>
+
+<body>
+
+<div id="wrap">
+	<div id="header">
+		<% (display-partial "navigation") %>	
+		<div class="clear"></div>
+	</div>
+
+	<div id="content">
+				
+		<div class="title nomargin">
+			<p><% (title "| Dragonfly web framework") %><p>
+		</div>
+		
+		<h1>Using Templates</h1>
+		<p class="extract">A view is simply a web page, or a page fragment, like a header or footer. In fact, views can flexibly be embedded within other views. In that case we call them partials.</p>
+
+		<h3 class="code">How to load a view</h3>
+		<p>Example: open Your favorite text-editor and enter the following:</p>
+		<pre class="code">Hello World</pre>
+		<p>Save the file as "hello" into Your views directory. Now open Your browser and navigate to <a href="http://www.example-site.com/hello">example-site.com/hello</a>. That's it!</p>
+		<p class="info"><b>Information</b><br/>You can put nearly everything into views: (X)HTML, Javascript, newLISP code.</p>
+		<p class="config"><b>Configuration</b><br/>If VIEW_EXTENSION is ".html" for example, then when example-site.com/hello is called Dragonfly will search for a "hello.html" file in the VIEWS_PATH. It also applies to the partials, too.</p>
+
+		<h3 class="code">How to call functions inside a view</h3>
+		<pre class="code">&lt;% (benchmark-result) %&gt;</pre>
+		
+		<p>Put Your function call inside our open and close brackets and there You go! That will display some stats about rendering time and memory consumption.</p>
+		
+		<p class="info"><b>Information</b><br/>You can use all functions from newLISP and Dragonfly. Additionally You may write Your own functions inside a plugin and just put the file into the "plugins-active" directory.</p>
+				
+		<h3 class="code">How to load a partial view</h3>
+		<pre class="code">&lt;% (display-partial "header") %&gt;</pre>
+		
+		<p>This simple argument would load the "header"-partial from the partials directory.</p>
+
+		
+		<div class="line-dotted"></div>
+
+		<% (benchmark-result) %>
+		
+		<div class="line-dotted"></div>
+		
+		
+	</div><!-- END CONTENT -->
+	
+</div><!-- END WRAP -->
+<% (display-partial "footer") %>
+

File example-site/views/dragonfly_welcome.html

 		
 		<p>By "site root" we mean the folder that represents your basic web address,
 		for example if your website is located at:<br/><br/>
-		http://wwww.example-site.com/
+		http://www.example-site.com/
 		<br/><br/>
 		And on your webserver that is represented by this folder (called the "site root"):
 		<br/><br/>
 		<br/><br/>
 		</p>
 		<p class="info"><b>Information</b><br/>If you'd like Dragonfly to live somewhere else inside your site root,
-		see the Example step on this page.</p>
+		click <% (link_to "here" "setup_example") %> for instructions.</p>
 		
 		<h2>Step 2 - Configure Dragonfly</h2>
 		<p>Edit the 'config.lsp' file in dragonfly-framework.<br/><br/>Read through the comments (they begin with a semi-colon) for instructions on what the settings are for.<br/><br/>If you want to prevent .html files from being processed through Dragonfly, open the .htaccess file in the site root and read the comments there for how to disable that behavior.
 		</p>
 
-		<h2>Step 3 - That's it'</h2>
+		<h2>Step 3 - That's it!</h2>
 		<p>You're ready to run Dragonfly!</p>
 		
 		<div class="line-dotted"></div>

File example-site/views/partials/header.html

 	<% (meta "author" "Marc Hildmann, Greg Slepak") %>
 	<% (meta "keywords" "newlisp, framework, dragonfly, web framework") %>
 	<% (css "screen" (web-root "includes/css/screen.css")) %>
+	<% (script (web-root "includes/js/jquery-1.3.2.min.js")) %>
 	<% (script (web-root "includes/js/dragonfly.js")) %>
-	<% (script (web-root "includes/js/jquery-1.3.2.min.js")) %>
 	<% (rss "Dragonfly web framework RSS Feed" (web-root "?dragonfly_rssfeed/xml")) %>
 </head>

File example-site/views/partials/navigation.html

 <ul>
 	<li><% (link_to "Welcome" "welcome") %></li>
 	<li>
-	<a href="#" onclick="toggleMenu(); return false;" id="guidesMenu">User Guide</a>
-	
-	          <div id="menu" class="clearfix" style="display:none;">
-	            <dl class="L">
-	              <dt>Getting started</dt>
-				  <dd><% (link_to  "Welcome" "dragonfly_welcome") %></dd>
+		<a href="#" class="menu_toggle">User Guide</a> 
+		<div class="menu clearfix" style="display:none;">
+			<dl class="L">
+				<dt>Getting started</dt>
+				<dd><% (link_to  "Welcome" "dragonfly_welcome") %></dd>
 
-				  <dt>Using routes in Dragonfly</dt>
-				  <dd><% (link_to  "Default Routes" "dragonfly_routes") %></dd>
+				<dt>Routes</dt>
+				<dd><% (link_to  "Default routes" "dragonfly_routes") %></dd>
+				
+				<dt>Templates</dt>
+				<dd><% (link_to  "Creating templates" "dragonfly_views") %></dd>
+			</dl>
+		</div>
+	</li>
+	<li>
+		<a href="#" class="menu_toggle">Examples</a>
+		<div class="menu clearfix" style="display:none;">
+			<dl class="L">
+				<dt>Tables</dt>
+				<dd><% (link_to "Generate tables from lists" "dragonfly_tables") %></dd>
 
-	              <dt>Tables</dt>
-	              <dd><% (link_to "Generate tables from lists" "dragonfly_tables") %></dd>
+				<dt>AJAX</dt>
+				<dd><% (link_to "Some simple AJAX calls" "dragonfly_ajax") %></dd>
 
-	              <dt>AJAX</dt>
-	              <dd><% (link_to "Some simple AJAX calls" "dragonfly_ajax") %></dd>
-	
-	              <dt>Twitter</dt>
-	              <dd><% (link_to "Using Twitter with Dragonfly" "dragonfly_twitter") %></dd>
+				<dt>Twitter</dt>
+				<dd><% (link_to "Using Twitter with Dragonfly" "dragonfly_twitter") %></dd>
 
-	              <dt>SEO Experiments</dt>
-	              <dd><% (link_to "Experiments in SEO" "dragonfly_seo") %></dd>
-				</dl>
-	
-				<dl class="R">
-	              <dt>Useful information</dt>
-	              <dd><% (link_to  "Dragonfly debugging information" "dragonfly_debug") %></dd>
-				</dl>
-				</div>
+				<dt>SEO Experiments</dt>
+				<dd><% (link_to "Experiments in SEO" "dragonfly_seo") %></dd>
+			</dl>
+
+			<dl class="R">
+				<dt>Useful information</dt>
+				<dd><% (link_to  "Dragonfly debugging information" "dragonfly_debug") %></dd>
+			</dl>
+		</div>
 	</li>
 	<li><% (link_to "Code" "code") %></li>
 	<li><% (link_to "About" "about") %></li>

File example-site/views/setup_example.html

+<% (display-partial "doctype") %>
+<% (display-partial "header") %>
+
+<body>
+
+<div id="wrap">
+	<div id="header">
+		<% (display-partial "navigation") %>	
+		<div class="clear"></div>
+	</div>
+
+	<div id="content">
+				
+		<div class="title nomargin">
+			<p><% (title "| Dragonfly web framework") %><p>
+		</div>
+		
+		<h1>Dragonfly in Non-Root</h1>
+		<p>Say you want to test Dragonfly out by placing the entire
+		directory into the root of your site. As an example the demo site
+		could be located here:</p>
+
+		<pre class="code">/home/user/mysite.com/dragonfly/example-site/</pre>
+
+		<p>And to access it you would use this URL:</p>
+
+		<pre class="code">http://www.mysite.com/dragonfly/example-site/</pre>
+
+		<p>You must make two changes (possible 3) to get it to work with Apache:</p>
+
+		<ol><li>Change this line in .htaccess
+
+			<blockquote>RewriteBase /</blockquote>
+		To:
+			<blockquote>RewriteBase /dragonfly/example-site/</blockquote>
+		</li>
+		<li>Edit config.lsp and change this line:
+
+			<blockquote>(constant (global 'DOCUMENT_ROOT) (env "DOCUMENT_ROOT"))</blockquote>
+		To:
+			<blockquote>(constant (global 'DOCUMENT_ROOT) "/home/user/mysite.com/dragonfly/example-site")</blockquote>
+		</ol>
+
+		<p>A possible third step is required if your newlisp binary is not
+		installed in /usr/bin/newlisp. If it's installed somewhere else
+		(for example: /path/to/bin/newlisp), then you may need to also
+		edit 'index.cgi' file and change the top-line from:</p>
+
+		<blockquote>#!/usr/bin/env newlisp</blockquote>
+		<p>To:</p>
+		<blockquote>#!/path/to/bin/newlisp</blockquote>
+		
+		<div class="line-dotted"></div>
+
+		<% (benchmark-result) %>
+		
+		<div class="line-dotted"></div>
+		
+		
+	</div><!-- END CONTENT -->
+	
+</div><!-- END WRAP -->
+<% (display-partial "footer") %>
+