« Return to Thread: [gatewiki-commits] SF.net SVN: gatewiki:[1463] trunk/cow

[gatewiki-commits] SF.net SVN: gatewiki:[1463] trunk/cow

by hcunningham-2 :: Rate this Message:

Reply to Author | View in Thread

Revision: 1463
          http://gatewiki.svn.sourceforge.net/gatewiki/?rev=1463&view=rev
Author:   hcunningham
Date:     2009-07-06 19:40:51 +0000 (Mon, 06 Jul 2009)

Log Message:
-----------
added a method for setting the contents of DIVs in BODY to support
tree-specific navigation (code from Niraj), plus a test

Modified Paths:
--------------
    trunk/cow/bin/scratch.groovy
    trunk/cow/doc/cow-backlog.html
    trunk/cow/doc/cow-backlog.yam
    trunk/cow/grails-app/conf/Config.groovy
    trunk/cow/grails-app/utils/gate/util/FileUtils.groovy
    trunk/cow/grails-app/views/layouts/cowpage.gsp
    trunk/cow/test/unit/FileUtilsTests.groovy
    trunk/cow/web-app/css/page.css

Modified: trunk/cow/bin/scratch.groovy
===================================================================
--- trunk/cow/bin/scratch.groovy 2009-07-06 16:12:09 UTC (rev 1462)
+++ trunk/cow/bin/scratch.groovy 2009-07-06 19:40:51 UTC (rev 1463)
@@ -1,298 +1,489 @@
 // scratch.groovy
 
-Map params = [ a : 1, b : 2 ]
-params.remove('a')
-println params
+/*
+String xml = """
+<html>
+ <body>
+  <div id="top">
+   <div id="a">
+     <p>somehting</p>
+   </div>
+   <div id="b">
+     <p>somehting1</p>
+   </div>
+  </div>
+ </body>
+</html>
+"""
 
+XmlParser parser = new XmlParser()
+def html = parser.parseText (xml)
 
-System.exit(0)
-////////////////////////////////////////////////////////////
+//assuming div occurs under body
+html.body.div.each { processDiv(it) }
 
+def writer = new StringWriter()
+new XmlNodePrinter(new PrintWriter(writer)).print(html)
+def result = writer.toString()
 
-def x = """
-${id}
-<br/>
-${pagePath}
+print "$result"
 
-<ul>
-<g:each in="${pageScope.variables}" var="item">
-<li><pre> ${item} </pre> </li>
-</g:each>
-</ul>
-
-
-<cow:hasPermission actions="update,create,edit,list,show" wiki="${thisPage.wiki}" pagePathDir="${thisPage.pagePathDir}">
-<cow:canRead wiki="${thisPage.wiki}" pagePathDir="${thisPage.pagePathDir}">
-<cow:canReadOrWrite wiki="${thisPage.wiki}" pagePathDir="${thisPage.pagePathDir}">
-"""
-
-Map m = [ a: 1, b: 2, c: 3 ]
-println m
-String javaView = ((m as java.util.LinkedHashMap).toString())
-println javaView
-println jMap2GMap(javaView)
-
-/**
- * Takes a Java string view of a map ({a=1, b=2, c=3}) and returns the
- * equivalent Groovy map (["a":"1", "b":"2", "c":"3"]).
- */
-Map jMap2GMap(String javaMapView) {
-  Map m = [:]
-  javaMapView[1..-2].split(',').each {
-    List entry = it.trim().split('=')
-    m.put(entry[0], entry[1])
+void processDiv(div) {
+  def atts = div.attributes()
+  if(atts.id.equals("a")) {
+   div.value = "New Text Here"
   }
-  return m
-} // jMap2GMap(String)
 
-
-System.exit(0)
-////////////////////////////////////////////////////////////
-
-
-URL gateUrl = new URL("http://gate.ac.uk/")
-// println gateUrl.text
-
-println """"here is "${gateUrl}" """
-
-System.exit(0)
-////////////////////////////////////////////////////////////
-
-
-/*
-File cwd = new File(".")
-List fileNames = []
-cwd.eachFileRecurse { file ->
-  if(
-    file.path.startsWith("./plugins") ||
-    file.path.startsWith("./doc") ||
-    file.path.startsWith("./web-app") ||
-    file.path.startsWith("./bin") ||
-    file.path.startsWith("./src/java/gate/yam/parse/") ||
-    file.path.startsWith("./src/templates/scaffolding") ||
-    file.path.startsWith("./grails-app/taglib/FckEditorTagLib.groovy") ||
-    file.path.startsWith("./grails-app/services/EmailerService.groovy") ||
-    file.path.startsWith("./test/unit/org/tmatesoft") ||
-    file.path.startsWith("./src/java/gate/wiki/antlr") ||
-    file.path.startsWith("./src/java/gate/yam/convert/JSPWikiMarkupParser.")
-  )
-    return
-  if(file.name.endsWith(".groovy") || file.name.endsWith(".java"))
-    fileNames.add(file.path)
+ // if div is not exactly under the body tag but somewhere down the hierarchy
+ div.div.each {processDiv(it)}
 }
-//fileNames.each { println it }
-//System.exit(0)
+*/
 
-//fileNames = ['grails-app/controllers/PageController.groovy']
-//fileNames = ['src/java/gate/yam/translate/AbstractTranslator.java']
-
-for(path in fileNames) {
-  println path
-  boolean inLicence = false
-  String licence = \
+println "================================"
+String pageString = '''
+<body>
+  <div id="topBar"> </div>
+  <div id="leftBar"> </div>
+  <div id="footer"> </div>
+</body>
 '''
- *
- *  This code is from the GATE project (http://gate.ac.uk/) and is free
- *  software licenced under the GNU General Public License version 3. It is
- *  distributed without any warranty. For more details see COPYING.txt in the
- *  top level directory (or at http://gatewiki.sf.net/COPYING.txt).'''
+String text = "new text!"
+String divId = "leftBar"
 
-  File f = new File(path)
-  File t = File.createTempFile("scratch-", "", cwd)
-  t.withWriter { writer ->
-    String previous = ""
-    f.eachLine { line ->
-      if(line.startsWith(' *  Copyright (c) 1998')) {
-        t << "${line}${licence}\n"
-        inLicence = true
-      } else if(inLicence) {
-        if(line.startsWith(' *            /')) {
-          if(previous.contains("Hamish")) // old style author note
-            t << " *  \n${previous}\n"
-          t << line + "\n"
-          inLicence = false
-        }
-      } else if(line == " *") {
-      } else {
-        t << line + "\n"
-      }
-      previous = line
-    }
-  }
-  t.renameTo(f)
+XmlParser pageParser = new XmlParser()
+def parseTree = pageParser.parseText(pageString)
+parseTree.div.each {
+  if(it.attributes().id.equals(divId))
+    it.value = text
 }
+def treeWriter = new StringWriter()
+new XmlNodePrinter(new PrintWriter(treeWriter)).print(parseTree)
+def newTreeString = treeWriter.toString()
 
+print "$newTreeString"
 
-System.exit(0)
-////////////////////////////////////////////////////////////
 
-*/
-
-
-/*
-
-import org.springframework.core.io.FileSystemResource
-
-CowFileSystemResource fsr = new CowFileSystemResource("/a/b/c.html")
-println fsr.fsr
-println fsr.fsr.file.name
-File serializationFile = new File("test.ser")
-FileOutputStream fos = new FileOutputStream(serializationFile)
-ObjectOutputStream oos = new ObjectOutputStream(fos)
-oos.writeObject(fsr)
-oos.close()
-
-FileInputStream fis = new FileInputStream("test.ser");
-ObjectInputStream ois = new ObjectInputStream(fis);
-CowFileSystemResource fsr2 = (CowFileSystemResource) ois.readObject();
-ois.close();
-println fsr2.fsr
-println fsr2.fsr.file.name
-
 System.exit(0)
 ////////////////////////////////////////////////////////////
 
 
-
-class Thing {
-  String a = "A"
-  String b = "B"
-  boolean c = true
-
-  Map toMap() {
-    return this.properties.findAll {
-      it.key != "metaClass" && it.key != "class"
-    }
-  }
-}
-
-class OtherThing {
-  Map doSomething() {
-    Thing t = new Thing()
-    return t.toMap()
-  }
-}
-
-OtherThing t = new OtherThing()
-println t.doSomething()
-assert t.doSomething() == ["b":"B", "a":"A", "c":true]
-
-
-
-System.exit(0)
-////////////////////////////////////////////////////////////
-
-
-URI u = new URI("/x/y/z")
-println u.resolve("a.html")
-println u.resolve("a.html?d=1")
-println u.resolve("?d=1")
-
-
-
-
-Map m = [ a : 2 ]
-println m
-m + [ b : 3, c : 4 ]
-println m
-m += [ b : 3, c : 4 ]
-println m
-
-Map thing() {
-  [ a : 26 ]
-}
-println(thing())
-
-System.exit(0)
-
-
-
-conf = new ConfigSlurper().parse('''
-gate {
-  cow {
-    version     = props."app.version"
-    mode        = "workstation"
-    user.home   = System.getProperty("user.home")
-    data        = "${user.home}/${dot}cowrc.d/${version}"
-    dbs         = "${data}/dbs"
-    sandboxes   = "${data}/sandboxes"
-    svnrep      = "${data}/svnrep"
-    help.wiki   = "${sandboxes}/help"
-    main.wiki   = "${sandboxes}/main"
-    page {
-      thing = "another thing"
-      thing3 = "yet another"
-    }
-  }
-}
-''')
-
-println( conf.gate.cow.mode == "workstation" )
-
-String path = "cow.mode"
-println( evaluate("conf.gate.${path}") == conf.gate.cow.mode )
-
-
-System.exit(0)
-
-
-// Flatten a ConfigObject adding a prefix to the keys
-Map flattenConf(String prefix, Map conf) {
-  Map result = [ : ]
-  for(k in conf.keySet()) {
-    def val = conf.get(k)
-    def dot = prefix ? "." : ""
-    def key = "${prefix}${dot}${k}"
-    if(val instanceof Map)
-      result.putAll( flattenConf(key, val) )
-    else {
-      result.put( (key), val )
-    }
-  }
-  return result
-} // flattenConf(String, Map)
-
-println flattenConf("gate", [ 'a' : [ 'b' : [ 'c' : 'x', 'd' : 'y' ] ] ])
-
-
-
-
-[ 'a' : [ 'b' : [ 'c' : 'x', 'd' : 'y' ] ], e : 'z' ].each {
-  println "${it}"
-}
-
-// print the dependency tree for the build targets
-def buildxml = new XmlSlurper().parse("build.xml")
-List targets = []
-buildxml.target.each { targets << it }
-for(t in targets) {
-  printTarget(t, targets)
-}
-
-void printTarget(t, targets) {
-  printTarget(t, "", targets)
-  return
-
-  print t.@name
-  print "  "
-  List dependencies = t.@...().split(",").collect { it.trim() }
-  print dependencies
-  println ""
-}
-void printTarget(t2, String indent, targets) {
-  if(indent == "                              ")
-    return
-  print indent
-  print t2.@name
-  println ""
-  List dependencies = t2.@...().split(",").collect { it.trim() }
-  for(child in dependencies) {
-    for(x in targets) {
-      println x.class
-      if(x && x.@name && x.@name == child)
-        printTarget(x, "$indent  ")
-    }
-  }
-}
-*/
-
+//
+// def parseTree = new XmlParser().parseText('''
+// <body>
+// <div id="leftBar"> </div>
+// </body>
+// ''')
+// def input1 = '''
+// <shopping>
+//     <category type="groceries">
+//         <item>Chocolate</item>
+//         <item>Coffee</item>
+//     </category>
+//     <category type="supplies">
+//         <item>Paper</item>
+//         <item quantity="4">Pens</item>
+//     </category>
+//     <div id="leftBar"> </div>
+//     <category type="present">
+//         <item when="Aug 10">Kathryn's Birthday</item>
+//     </category>
+// </shopping>
+// '''
+// println parseTree.body.value
+// println parseTree.body.value.find { it.@id == 'leftBar' }
+// //println parseTree.body.find { it.@id == 'leftBar' }.value = "ahhooba"
+//
+// parseTree = new XmlParser().parseText(input1)
+//
+// //parseTree.html.body.find { it.@id == 'leftBar' }.value = "ahhooba"
+// println parseTree
+// println parseTree.category
+// println parseTree.find { it.@id == 'leftBar' }
+// println ""
+//
+// def stringWriter = new StringWriter()
+// new XmlNodePrinter(new PrintWriter(stringWriter)).print(parseTree)
+// def updatedDoc = stringWriter.toString()
+// println updatedDoc
+//
+//
+// System.exit(0)
+// ////////////////////////////////////////////////////////////
+//
+//
+//
+// def input = '''
+// <shopping>
+//     <category type="groceries">
+//         <item>Chocolate</item>
+//         <item>Coffee</item>
+//     </category>
+//     <category type="supplies">
+//         <item>Paper</item>
+//         <item quantity="4">Pens</item>
+//     </category>
+//     <div id="topBar"> </div>
+//     <category type="present">
+//         <item when="Aug 10">Kathryn's Birthday</item>
+//     </category>
+// </shopping>
+// '''
+//
+// def expectedResult = '''
+// <shopping>
+//   <category type="groceries">
+//     <item>Luxury Chocolate</item>
+//     <item>Luxury Coffee</item>
+//   </category>
+//   <category type="supplies">
+//     <item>Paper</item>
+//     <item quantity="6" when="Urgent">Pens</item>
+//   </category>
+//   <category type="present">
+//     <item>Mum's Birthday</item>
+//     <item when="Oct 15">Monica's Birthday</item>
+//   </category>
+// </shopping>
+// '''
+//
+// def root = new XmlParser().parseText(input)
+// println root.findAll { it.@id == 'topBar' }
+// println root.find { it.@id == 'topBar' }
+// println root.category.item[0]
+// println ""
+// root.find { it.@id == 'topBar' }.value = "ahhooba"
+// println root
+// println ""
+//
+// def writer = new StringWriter()
+// new XmlNodePrinter(new PrintWriter(writer)).print(root)
+// def result = writer.toString()
+// println result
+//
+//
+// // modify groceries: quality items please
+// def groceries = root.category.findAll{ it.@type == 'groceries' }.item[0]
+// groceries.each { g ->
+//     g.value = 'Luxury ' + g.text()
+// }
+//
+// // modify supplies: we need extra pens
+// def supplies = root.category.findAll{ it.@type == 'supplies' }.item[0]
+// supplies.findAll{ it.text() == 'Pens' }.each { s ->
+//     s.@quantity = s.@...() + 2
+//     s.@when = 'Urgent'
+// }
+//
+// // modify presents: August has come and gone
+// def presentCategory = root.category.find{ it.@type == 'present' }
+// presentCategory.children().clear()
+// presentCategory.appendNode('item', "Mum's Birthday")
+// presentCategory.appendNode('item', [when:'Oct 15'], "Monica's Birthday")
+//
+// // check the when attributes
+// def removeNulls(list) { list.grep{it} }
+// assert removeNulls(root.'**'.item.@when) == ["Urgent", "Oct 15"]
+//
+//
+//
+//
+// System.exit(0)
+// ////////////////////////////////////////////////////////////
+//
+//
+// Map params = [ a : 1, b : 2 ]
+// params.remove('a')
+// println params
+//
+//
+// System.exit(0)
+// ////////////////////////////////////////////////////////////
+//
+//
+// def x = """
+// ${id}
+// <br/>
+// ${pagePath}
+//
+// <ul>
+// <g:each in="${pageScope.variables}" var="item">
+// <li><pre> ${item} </pre> </li>
+// </g:each>
+// </ul>
+//
+//
+// <cow:hasPermission actions="update,create,edit,list,show" wiki="${thisPage.wiki}" pagePathDir="${thisPage.pagePathDir}">
+// <cow:canRead wiki="${thisPage.wiki}" pagePathDir="${thisPage.pagePathDir}">
+// <cow:canReadOrWrite wiki="${thisPage.wiki}" pagePathDir="${thisPage.pagePathDir}">
+// """
+//
+// Map m = [ a: 1, b: 2, c: 3 ]
+// println m
+// String javaView = ((m as java.util.LinkedHashMap).toString())
+// println javaView
+// println jMap2GMap(javaView)
+//
+// /**
+//  * Takes a Java string view of a map ({a=1, b=2, c=3}) and returns the
+//  * equivalent Groovy map (["a":"1", "b":"2", "c":"3"]).
+//  */
+// Map jMap2GMap(String javaMapView) {
+//   Map m = [:]
+//   javaMapView[1..-2].split(',').each {
+//     List entry = it.trim().split('=')
+//     m.put(entry[0], entry[1])
+//   }
+//   return m
+// } // jMap2GMap(String)
+//
+//
+// System.exit(0)
+// ////////////////////////////////////////////////////////////
+//
+//
+// URL gateUrl = new URL("http://gate.ac.uk/")
+// // println gateUrl.text
+//
+// println """"here is "${gateUrl}" """
+//
+// System.exit(0)
+// ////////////////////////////////////////////////////////////
+//
+//
+// /*
+// File cwd = new File(".")
+// List fileNames = []
+// cwd.eachFileRecurse { file ->
+//   if(
+//     file.path.startsWith("./plugins") ||
+//     file.path.startsWith("./doc") ||
+//     file.path.startsWith("./web-app") ||
+//     file.path.startsWith("./bin") ||
+//     file.path.startsWith("./src/java/gate/yam/parse/") ||
+//     file.path.startsWith("./src/templates/scaffolding") ||
+//     file.path.startsWith("./grails-app/taglib/FckEditorTagLib.groovy") ||
+//     file.path.startsWith("./grails-app/services/EmailerService.groovy") ||
+//     file.path.startsWith("./test/unit/org/tmatesoft") ||
+//     file.path.startsWith("./src/java/gate/wiki/antlr") ||
+//     file.path.startsWith("./src/java/gate/yam/convert/JSPWikiMarkupParser.")
+//   )
+//     return
+//   if(file.name.endsWith(".groovy") || file.name.endsWith(".java"))
+//     fileNames.add(file.path)
+// }
+// //fileNames.each { println it }
+// //System.exit(0)
+//
+// //fileNames = ['grails-app/controllers/PageController.groovy']
+// //fileNames = ['src/java/gate/yam/translate/AbstractTranslator.java']
+//
+// for(path in fileNames) {
+//   println path
+//   boolean inLicence = false
+//   String licence = \
+// '''
+//  *
+//  *  This code is from the GATE project (http://gate.ac.uk/) and is free
+//  *  software licenced under the GNU General Public License version 3. It is
+//  *  distributed without any warranty. For more details see COPYING.txt in the
+//  *  top level directory (or at http://gatewiki.sf.net/COPYING.txt).'''
+//
+//   File f = new File(path)
+//   File t = File.createTempFile("scratch-", "", cwd)
+//   t.withWriter { writer ->
+//     String previous = ""
+//     f.eachLine { line ->
+//       if(line.startsWith(' *  Copyright (c) 1998')) {
+//         t << "${line}${licence}\n"
+//         inLicence = true
+//       } else if(inLicence) {
+//         if(line.startsWith(' *            /')) {
+//           if(previous.contains("Hamish")) // old style author note
+//             t << " *  \n${previous}\n"
+//           t << line + "\n"
+//           inLicence = false
+//         }
+//       } else if(line == " *") {
+//       } else {
+//         t << line + "\n"
+//       }
+//       previous = line
+//     }
+//   }
+//   t.renameTo(f)
+// }
+//
+//
+// System.exit(0)
+// ////////////////////////////////////////////////////////////
+//
+// */
+//
+//
+// /*
+//
+// import org.springframework.core.io.FileSystemResource
+//
+// CowFileSystemResource fsr = new CowFileSystemResource("/a/b/c.html")
+// println fsr.fsr
+// println fsr.fsr.file.name
+// File serializationFile = new File("test.ser")
+// FileOutputStream fos = new FileOutputStream(serializationFile)
+// ObjectOutputStream oos = new ObjectOutputStream(fos)
+// oos.writeObject(fsr)
+// oos.close()
+//
+// FileInputStream fis = new FileInputStream("test.ser");
+// ObjectInputStream ois = new ObjectInputStream(fis);
+// CowFileSystemResource fsr2 = (CowFileSystemResource) ois.readObject();
+// ois.close();
+// println fsr2.fsr
+// println fsr2.fsr.file.name
+//
+// System.exit(0)
+// ////////////////////////////////////////////////////////////
+//
+//
+//
+// class Thing {
+//   String a = "A"
+//   String b = "B"
+//   boolean c = true
+//
+//   Map toMap() {
+//     return this.properties.findAll {
+//       it.key != "metaClass" && it.key != "class"
+//     }
+//   }
+// }
+//
+// class OtherThing {
+//   Map doSomething() {
+//     Thing t = new Thing()
+//     return t.toMap()
+//   }
+// }
+//
+// OtherThing t = new OtherThing()
+// println t.doSomething()
+// assert t.doSomething() == ["b":"B", "a":"A", "c":true]
+//  
+//
+//
+// System.exit(0)
+// ////////////////////////////////////////////////////////////
+//
+//
+// URI u = new URI("/x/y/z")
+// println u.resolve("a.html")
+// println u.resolve("a.html?d=1")
+// println u.resolve("?d=1")
+//
+//
+//
+//
+// Map m = [ a : 2 ]
+// println m
+// m + [ b : 3, c : 4 ]
+// println m
+// m += [ b : 3, c : 4 ]
+// println m
+//
+// Map thing() {
+//   [ a : 26 ]
+// }
+// println(thing())
+//
+// System.exit(0)
+//
+//
+//
+// conf = new ConfigSlurper().parse('''
+// gate {
+//   cow {
+//     version     = props."app.version"
+//     mode        = "workstation"
+//     user.home   = System.getProperty("user.home")
+//     data        = "${user.home}/${dot}cowrc.d/${version}"
+//     dbs         = "${data}/dbs"
+//     sandboxes   = "${data}/sandboxes"
+//     svnrep      = "${data}/svnrep"
+//     help.wiki   = "${sandboxes}/help"
+//     main.wiki   = "${sandboxes}/main"
+//     page {
+//       thing = "another thing"
+//       thing3 = "yet another"
+//     }
+//   }
+// }
+// ''')
+//
+// println( conf.gate.cow.mode == "workstation" )
+//
+// String path = "cow.mode"
+// println( evaluate("conf.gate.${path}") == conf.gate.cow.mode )
+//
+//
+// System.exit(0)
+//
+//
+// // Flatten a ConfigObject adding a prefix to the keys
+// Map flattenConf(String prefix, Map conf) {
+//   Map result = [ : ]
+//   for(k in conf.keySet()) {
+//     def val = conf.get(k)
+//     def dot = prefix ? "." : ""
+//     def key = "${prefix}${dot}${k}"
+//     if(val instanceof Map)
+//       result.putAll( flattenConf(key, val) )
+//     else {
+//       result.put( (key), val )
+//     }
+//   }
+//   return result
+// } // flattenConf(String, Map)
+//
+// println flattenConf("gate", [ 'a' : [ 'b' : [ 'c' : 'x', 'd' : 'y' ] ] ])
+//
+//
+//
+//
+// [ 'a' : [ 'b' : [ 'c' : 'x', 'd' : 'y' ] ], e : 'z' ].each {
+//   println "${it}"
+// }
+//
+// // print the dependency tree for the build targets
+// def buildxml = new XmlSlurper().parse("build.xml")
+// List targets = []
+// buildxml.target.each { targets << it }
+// for(t in targets) {
+//   printTarget(t, targets)
+// }
+//
+// void printTarget(t, targets) {
+//   printTarget(t, "", targets)
+//   return
+//
+//   print t.@name
+//   print "  "
+//   List dependencies = t.@...().split(",").collect { it.trim() }
+//   print dependencies
+//   println ""
+// }
+// void printTarget(t2, String indent, targets) {
+//   if(indent == "                              ")
+//     return
+//   print indent
+//   print t2.@name
+//   println ""
+//   List dependencies = t2.@...().split(",").collect { it.trim() }
+//   for(child in dependencies) {
+//     for(x in targets) {
+//       println x.class
+//       if(x && x.@name && x.@name == child)
+//         printTarget(x, "$indent  ")
+//     }
+//   }
+// }
+// */
+//

Modified: trunk/cow/doc/cow-backlog.html
===================================================================
--- trunk/cow/doc/cow-backlog.html 2009-07-06 16:12:09 UTC (rev 1462)
+++ trunk/cow/doc/cow-backlog.html 2009-07-06 19:40:51 UTC (rev 1463)
@@ -69,9 +69,19 @@
 <li>add layouts capabilities appropriate for gate.ac.uk and the lifesci work
   [NA, HC]</li>
   <ul>
-  <li>design: we're providing navigation (sets of links) that can be tailored on
-    a per-area or per-directory basis, plus layout (css, header structure,
-    etc.) on a per-site or per-area basis</li>
+  <li>add to gatewiki.html: Customising CoW Layout and Navigation. CoW provides
+    navigation (sets of links to parts of a site) that can be tailored on a
+    per-area or per-directory basis, plus layout (CSS styling, page structure,
+    etc.) that can be tailored on a per-site or per-area basis. Adding
+    navigation to a directory tree involves adding YAM files to the top of the
+    tree that contain the links for whichever of various screen areas that you
+    want to contain them (e.g. top bar, left bar, right bar, footer). These
+    files have to be named after the corresponding DIV elements of the main
+    layout (in the default CoW layout, they are called topBar, leftBar,
+    rightBar and footer; in a CoW running a custom layout they may have
+    different names). (Note to layout writers: the DIVs that get replaced with
+    custom navigation must be at the top level of the BODY element in your
+    layout.)</li>
   <li>navigation for specific directory trees [HC]</li>
     <ul>
     <li>this should all be dealt with at rendering time. otherwise we lose the
@@ -82,17 +92,17 @@
     <li>PC.show, line 90:</li>
       <ul>
       <li>pageBody = FileUtils.getBody(pageFile)</li>
-      <li>change this to be PageService.getBody(pageFile, wiki)</li>
+      <li>change this to be PageService.getBody(pageFileDir, wiki.path)</li>
         <ul>
-        <li>this then does an FU.getBody on the page itself and adds in
-          FU.getBody called over any available layout info from the wiki</li>
+        <li>this first does an FU.getBody on the page itself, then:</li>
         <li>for each layout file in conf.navigation.files</li>
           <ul>
           <li>find the nearest one to current dir, up the tree to wiki top</li>
+          <li>get its body</li>
+          <li>place into the div with the id of the same name</li>
           </ul>
         </ul>
       </ul>
-    <li>names: cow:top-bar.yam, cow:left-bar.yam ?</li>
     </ul>
   <li>layouts for whole wiki-areas [NA]</li>
     <ul>

Modified: trunk/cow/doc/cow-backlog.yam
===================================================================
--- trunk/cow/doc/cow-backlog.yam 2009-07-06 16:12:09 UTC (rev 1462)
+++ trunk/cow/doc/cow-backlog.yam 2009-07-06 19:40:51 UTC (rev 1463)
@@ -13,9 +13,19 @@
 
 - add layouts capabilities appropriate for gate.ac.uk and the lifesci work
   [NA, HC]
-  - design: we're providing navigation (sets of links) that can be tailored on
-    a per-area or per-directory basis, plus layout (css, header structure,
-    etc.) on a per-site or per-area basis
+  - add to gatewiki.html: Customising CoW Layout and Navigation. CoW provides
+    navigation (sets of links to parts of a site) that can be tailored on a
+    per-area or per-directory basis, plus layout (CSS styling, page structure,
+    etc.) that can be tailored on a per-site or per-area basis. Adding
+    navigation to a directory tree involves adding YAM files to the top of the
+    tree that contain the links for whichever of various screen areas that you
+    want to contain them (e.g. top bar, left bar, right bar, footer). These
+    files have to be named after the corresponding DIV elements of the main
+    layout (in the default CoW layout, they are called topBar, leftBar,
+    rightBar and footer; in a CoW running a custom layout they may have
+    different names). (Note to layout writers: the DIVs that get replaced with
+    custom navigation must be at the top level of the BODY element in your
+    layout.)
   - navigation for specific directory trees [HC]
     - this should all be dealt with at rendering time. otherwise we lose the
       ability to work with YAM files outside of CoW. so at the place where CoW
@@ -24,12 +34,12 @@
       (implicit), and then it should step up the tree looking for the layouts
     - PC.show, line 90:
       - pageBody = FileUtils.getBody(pageFile)
-      - change this to be PageService.getBody(pageFile, wiki)
-        - this then does an FU.getBody on the page itself and adds in
-          FU.getBody called over any available layout info from the wiki
+      - change this to be PageService.getBody(pageFileDir, wiki.path)
+        - this first does an FU.getBody on the page itself, then:
         - for each layout file in conf.navigation.files
           - find the nearest one to current dir, up the tree to wiki top
-    - names: cow:top-bar.yam, cow:left-bar.yam ?
+          - get its body
+          - place into the div with the id of the same name
   - layouts for whole wiki-areas [NA]
     - add a "areaLayoutName" to Wiki, which would reference a layout GSP in
       the site-specific plugin; PageLinkTabLib would then use this for the

Modified: trunk/cow/grails-app/conf/Config.groovy
===================================================================
--- trunk/cow/grails-app/conf/Config.groovy 2009-07-06 16:12:09 UTC (rev 1462)
+++ trunk/cow/grails-app/conf/Config.groovy 2009-07-06 19:40:51 UTC (rev 1463)
@@ -106,7 +106,9 @@
       controller        = "gate.cow.GuestLayoutController"
     }
     navigation {
-      files             = [ "cow:nav.html" ]
+      // default options: topBar.html leftBar.html rightBar.html footer.html
+      // *note* that these names need to match the div ids in the layout
+      files             = [ "leftBar.html" ] // becomes content of leftBar div
     }
     page { // note: this has to be serialisable to support the edit flow
       bibURI            = "http://gate.ac.uk/sale/bib/main.html"

Modified: trunk/cow/grails-app/utils/gate/util/FileUtils.groovy
===================================================================
--- trunk/cow/grails-app/utils/gate/util/FileUtils.groovy 2009-07-06 16:12:09 UTC (rev 1462)
+++ trunk/cow/grails-app/utils/gate/util/FileUtils.groovy 2009-07-06 19:40:51 UTC (rev 1463)
@@ -47,6 +47,24 @@
   } // findFileInTree
 
   /**
+   * Set the value (content) of a DIV occuring in the BODY string of an HTML
+   * file according to its ID.
+   */
+  static String setBodyDiv(String pageString, String divId, String text) {
+    XmlParser pageParser = new XmlParser()
+    def parseTree = pageParser.parseText(pageString)
+    parseTree.div.each {
+      if(it.attributes().id.equals(divId))
+        it.value = text
+    }
+
+    def treeWriter = new StringWriter()
+    new XmlNodePrinter(new PrintWriter(treeWriter)).print(parseTree)
+
+    return treeWriter.toString()
+  } // setBodyDiv(String, String, String)
+
+  /**
    * Get the body of an HTML file. Tries to use Sitemesh (HTMLPageParser);
    * if that fails uses some imperfect string matching on body tags.
    */
@@ -91,7 +109,6 @@
     if(start == -1)
       start = text.indexOf("<BODY")
     if(start == -1) {
-                                                                                                      
       log.debug "didn't find a body start tag"
       return null
     }

Modified: trunk/cow/grails-app/views/layouts/cowpage.gsp
===================================================================
--- trunk/cow/grails-app/views/layouts/cowpage.gsp 2009-07-06 16:12:09 UTC (rev 1462)
+++ trunk/cow/grails-app/views/layouts/cowpage.gsp 2009-07-06 19:40:51 UTC (rev 1463)
@@ -93,9 +93,9 @@
 
     </div>
 
+    <div id="topBar"></div>
     <div id="topSeparator"></div>
-
-    <div id="leftBar"><span style="padding: 20px;"> </span> </div>
+    <div id="leftBar"></div>
     <g:layoutBody />    
     <div id="rightBar"> </div>
     <div id="footer"> </div>

Modified: trunk/cow/test/unit/FileUtilsTests.groovy
===================================================================
--- trunk/cow/test/unit/FileUtilsTests.groovy 2009-07-06 16:12:09 UTC (rev 1462)
+++ trunk/cow/test/unit/FileUtilsTests.groovy 2009-07-06 19:40:51 UTC (rev 1463)
@@ -22,6 +22,34 @@
     // this.getClass().classLoader.rootLoader.URLs.each{ println it }
   }
 
+  void testSetBodyDiv() {
+    log.debug("doing testSetBodyDiv")
+
+    String pageString = '''
+<body>
+  <div id="topBar"> </div>
+  <div id="leftBar"> </div>
+  <div id="footer"> </div>
+</body>
+'''
+    String expected = '''<body>
+  <div id="topBar"/>
+  <div id="leftBar">
+    new text!
+  </div>
+  <div id="footer"/>
+</body>
+'''.replace(' ', 'X').replace('\n', 'Y').replace('\t', 'Z')
+    String text = "new text!"
+    String divId = "leftBar"
+
+    String result = FileUtils.setBodyDiv(pageString, divId, text)
+      .replace(' ', 'X').replace('\n', 'Y').replace('\t', 'Z')
+    assertEquals( "result wrong:\n${result}\n${expected}", result, expected )
+
+    log.debug("finished doing testSetBodyDiv")
+  } // testSetBodyDiv()
+
   void testFindFileInTree() {
     log.debug("doing testFileFileInTree")
 

Modified: trunk/cow/web-app/css/page.css
===================================================================
--- trunk/cow/web-app/css/page.css 2009-07-06 16:12:09 UTC (rev 1462)
+++ trunk/cow/web-app/css/page.css 2009-07-06 19:40:51 UTC (rev 1463)
@@ -50,6 +50,7 @@
 #leftBar {
   float: left;
   margin-right: 20px;
+  padding: 20px;
 }
 #main {
   float: left;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
gatewiki-commits mailing list
gatewiki-commits@...
https://lists.sourceforge.net/lists/listinfo/gatewiki-commits

 « Return to Thread: [gatewiki-commits] SF.net SVN: gatewiki:[1463] trunk/cow