Offline Maven 2

22 02 2008

Ever tried to run maven 2 with no network and Snapshots, after midnight…. its hard because it likes to check for updates of snapshots. The following in ~/.m2/settings.xml might help.

<?xml version="1.0"?>
  <settings>
   <profiles>
     <profile>
       <repositories>
         <repository>
           <id>local-repository</id>
           <url>file:////Users/ieb/.m2/repository</url>
         </repository>
       </repositories>
       <id>local-offline</id>
     </profile>
   </profiles>

   <activeProfiles>
     <activeProfile>local-offline</activeProfile>
   </activeProfiles>
</settings>





Embedding Nasty Templates, Trick

22 02 2008

If you have a template that, becuase of its nature/strucutre/purpose is not valid XML… yes it does happen… (sherlog search snippets), you can insert them into a comment and then a CDATA and retrieve them from the DOM. Yes, HTML comments are in the DOM.

   render : function(templateName,contextObject)  {
  			if ( ! Template.templateCache[templateName] ) {
  			 var templateNode = document.getElementById(templateName);
  				 var firstNode = templateNode.firstChild;
  				 if ( firstNode && ( firstNode.nodeType == 8 || firstNode.nodeType == 4)) {
  				 	template = templateNode.firstChild.data.toString();

  				 } else {
  				 	template = templateNode.innerHTML.toString();
  				 }
  				 Template.templateCache[templateName] = TrimPath.parseTemplate(template,templateName);
  			}
  			return Template.templateCache[templateName].process(contextObject);
  	},

 

nodeType 4 is CDATA, and nodeType 8 is a comment. However, IE5 doesn’t support the node.data property… so I could just do some regex to strip the CDATA or comment tags from converting the element to text.

Using the approach makes it possible to have valid XHTML even with templates for other formats embedded inside the document





Javascript Templates

22 02 2008

There are 2 main ways of generating markup from within javascript. Either you perform DOM manipulation, as string injection or direct DOM manipulation. Or you can use templates.

For the java developer, DOM manipulation and string injection is rather like hard coding strings into you java code. templates are more like using jsp, velocity or freemarker.

So I started to look at writing a multi file upload that gave progress feedback, and rapidly found that many of the off the shelf components that did this, didn’t expose the markup, so I had to accept the results as they were, or as I could manipulate them with css. If the markup was wrong, I had to dig deep, sometimes very, into the javascript code.

Then I found TrimPath http://code.google.com/p/trimpath/wiki/JavaScriptTemplates , on Google Code. A templating language for Javascript. It looks a bit like Smarty templating from PHP and has some similarities to Velocity. It works by processing a template, either as a string or as a element from the HTML DOM and merging it with a Tree of javascript objects, just like Smarty and Velocity do.

The result is all the markup is now in the html page, and so can be designed and edited. You can see the results by looking at the code at https://saffron.caret.cam.ac.uk/svn/projects/MyCamToolsAlpha/trunk/files/widgets/DropBox/index2.html

This actually runs from SVN, although some versions of FireFox don’t recognize the CSS files as apache isn’t configured quite right…. Oh… and its trunk, so its going to change as I work on it. (no need to deploy any more, just run Sakai direct from SVN 🙂 )