ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r608542 - in /ant/ivy/site/xooki: antlib.xml xooki.js
Date Thu, 03 Jan 2008 16:16:51 GMT
Author: xavier
Date: Thu Jan  3 08:16:50 2008
New Revision: 608542

URL: http://svn.apache.org/viewvc?rev=608542&view=rev
Log:
add batch mode printer friendly support

Modified:
    ant/ivy/site/xooki/antlib.xml
    ant/ivy/site/xooki/xooki.js

Modified: ant/ivy/site/xooki/antlib.xml
URL: http://svn.apache.org/viewvc/ant/ivy/site/xooki/antlib.xml?rev=608542&r1=608541&r2=608542&view=diff
==============================================================================
--- ant/ivy/site/xooki/antlib.xml (original)
+++ ant/ivy/site/xooki/antlib.xml Thu Jan  3 08:16:50 2008
@@ -4,6 +4,7 @@
         <element name="fileset" type="fileset"/>
         <attribute name="destDir"/>
         <attribute name="checkUpToDate"/>
+        <attribute name="printerFriendly"/>
         <![CDATA[
              importClass(java.io.File);
             
@@ -44,8 +45,51 @@
     	        exec.createArg().setValue(srcDir+"/xooki/xooki.js");
     	        exec.createArg().setValue(filename);
     	        exec.createArg().setValue(attributes.get("destdir")+"/"+filepath);
+    	        if (attributes.get("printerfriendly") == "true") {
+    	        	exec.createArg().setValue("print");
+    	        }
     	        exec.perform();
     		  }
+        ]]>
+    </scriptdef>
+    <scriptdef name="print" language="javascript">
+        <attribute name="src"/>
+        <attribute name="dest"/>
+        <attribute name="checkUpToDate"/>
+        <![CDATA[
+            importClass(java.io.File);
+    	
+	        var file = new File(attributes.get("src"));
+	        var destFile = new File(attributes.get("dest"));
+	        
+			var basedir = file.getParent();
+			var filename = file.getName();
+			
+			var perform = true;
+            
+            if (attributes.get("checkuptodate") == "true") {
+                p = "xooki."+file.getAbsolutePath().replace(' ','_')+".uptodate";
+                upToDate = project.createTask("uptodate");
+                upToDate.setProperty(p);
+                upToDate.setSrcfile(file);
+                upToDate.setTargetFile(destFile);
+                upToDate.perform();
+                if (project.getProperty(p) != null) {
+                    self.log(file+" is up to date", 3);
+                    perform = false;
+                }
+            }
+        
+            if (perform) {
+		        exec = project.createTask("exec");
+		        exec.setDir(new File(basedir));
+		        exec.setExecutable("jrunscript");
+		        exec.createArg().setValue(project.getProperty("basedir")+"/xooki/xooki.js");
+		        exec.createArg().setValue(filename);
+		        exec.createArg().setValue(destFile);
+		        exec.createArg().setValue("print");
+		        exec.perform();
+	        }
         ]]>
     </scriptdef>
 </antlib>

Modified: ant/ivy/site/xooki/xooki.js
URL: http://svn.apache.org/viewvc/ant/ivy/site/xooki/xooki.js?rev=608542&r1=608541&r2=608542&view=diff
==============================================================================
--- ant/ivy/site/xooki/xooki.js (original)
+++ ant/ivy/site/xooki/xooki.js Thu Jan  3 08:16:50 2008
@@ -565,11 +565,8 @@
     	xooki.url.asyncLoadURL(pu(nextPage.id), xooki.render.printerFriendlyAsyncLoader, [root,
nextPage]);
    	}
 };
-xooki.render.printerFriendly = function() {
-    for (var k in xooki.component) {
-        xooki.c[k] = xooki.component[k]();
-    }
-    
+
+xooki.render.printerFriendlyAsync = function() {
 	xooki.c.body = xooki.c.messages
 	+ "<div id='xooki-printerFriendly'></div>" // div where printer friendly content
will be put
     + xooki.c.debugPanel;
@@ -580,6 +577,43 @@
     xooki.url.asyncLoadURL(pu(xooki.page.id), xooki.render.printerFriendlyAsyncLoader, [xooki.page,
xooki.page]);
 };
 
+xooki.render.printerFriendlySync = function() {
+	xooki.c.body = xooki.c.messages
+    + (function (page, level) {
+        var source = xooki.url.loadURL(pu(page.id));
+        if (source == null) {
+            return "";
+        }
+        var beginIndex = source.indexOf('<textarea id="xooki-source">');
+        beginIndex += '<textarea id="xooki-source">'.length;
+        var endIndex = source.lastIndexOf('</textarea>');
+        source = source.substring(beginIndex, endIndex);
+        
+        var printerFriendly = "<div class='toc-title toc-title-"+level+"'>"+page.title+"</div>";
+        printerFriendly += xooki.input.format.main(source);
+        for (var i=0; i <page.children.length; i++) {
+            printerFriendly += "<hr/>";
+            printerFriendly += arguments.callee(page.children[i], level+1);
+        }
+        return printerFriendly;
+    })(xooki.page, 1);
+    
+    xooki.html.setBody(xooki.string.processTemplate(xooki.template.body, xooki.c));
+};
+
+xooki.render.printerFriendly = function() {
+    for (var k in xooki.component) {
+        xooki.c[k] = xooki.component[k]();
+    }
+    
+	if (batchMode) {
+		xooki.render.printerFriendlySync();
+	} else {
+		xooki.render.printerFriendlyAsync();
+	}
+};
+
+
 xooki.render.page = function() {
     // realize all components available
     for (var k in xooki.component) {
@@ -937,6 +971,7 @@
 	    };
     
 	    // action
+	    if (! xooki.c.action) xooki.c.action = 'render';
 	    // TODO: better handle action extraction
 		xooki.c.action = window.location.search == '?action=print'?'print':xooki.c.action;
 	}
@@ -1195,9 +1230,14 @@
 		file = arguments[i];
 		i++;
 	}
-	var generateToDir = "gen";
+	var generateTo = "gen";
+	if (arguments.length > i) {
+		generateTo = arguments[i];
+		i++;
+	}
+	xooki.c.action = 'render';
 	if (arguments.length > i) {
-		generateToDir = arguments[i];
+		xooki.c.action = arguments[i];
 		i++;
 	}
 
@@ -1218,10 +1258,11 @@
         
     	xooki.pageContent = xooki.pageContent.replace(/<script type="text\/javascript" src="[^"]*xooki.js"><\/script>/g,
'');
     	
-    	xooki.render.page();
+    	xooki.render.main();
 
-    	print('generating to '+generateToDir+'/'+file);
-    	xooki.io.saveFile(generateToDir+'/'+file, xooki.pageContent);
+		var dest = generateTo.endsWith(".html") ? generateTo : generateTo+'/'+file;
+    	print('generating to '+dest);
+    	xooki.io.saveFile(dest, xooki.pageContent);
     }
 } else {
 	xooki.pageURL = window.location.toString();



Mime
View raw message