Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'guillaume_master' into v0.3.2.1
Closes #56 * guillaume_master: demo: New demo page layout, CodeMirror syntax highlighting demo: New `navigable` surround template for doc pages demo: Boot.scala: def boot -> boot() demo: Bootstrap navigation; hero unit on index.html demo: Remove SyntaxHighlighter, old menu.css demo: templates-hidden/default: move some scripts from head to end of body demo: templates-hidden/default: move some inline css to new style/doc.css demo: Convert buttons to links demo: templates-hidden/default: install 3rd part assets demo: Add 3rd part web assets demo: Switch to HTML5
- Loading branch information
Showing
61 changed files
with
13,968 additions
and
2,757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
reactive-web-demo/src/main/scala/com/damianhelme/tbutils/snippet/TBNav.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package com.damianhelme.tbutils.snippet | ||
|
||
// found here: | ||
// https://github.com/dph01/lift-TBUtils | ||
// FIXME: to lazy to add in dependency | ||
|
||
import scala.xml._ | ||
import net.liftweb.util.Helpers._ | ||
import scala.xml.transform._ | ||
import net.liftweb.common.Logger | ||
|
||
object TBNav extends Logger { | ||
|
||
/* Transforms the XML produced by Menu.build such that any menus defined as: | ||
Menu("Test") / "test" >> LocGroup("test") >> PlaceHolder submenus ( | ||
Menu("Test 2") / "test2", | ||
Menu("Test 3") / "test3" | ||
), | ||
or | ||
Menu("Test") / "test" >> LocGroup("test") >> submenus ( | ||
Menu("Test 2") / "test2", | ||
Menu("Test 3") / "test3" | ||
), | ||
will be transformed into Twitter Bootstrap dropdown menus | ||
*/ | ||
|
||
|
||
|
||
def menuToTBNav( in: NodeSeq ) : NodeSeq = { | ||
|
||
object t1 extends RewriteRule { | ||
override def transform(n: Node): Seq[Node] = n match { | ||
|
||
// removes the white space which appears between elements | ||
case Text(text) if ( text.matches("\\s+") ) => NodeSeq.Empty | ||
|
||
/* matches xml of the format: | ||
*<li> | ||
<span>Test</span> | ||
<ul> | ||
<li> | ||
<a href="/test2">Test 2</a> | ||
</li> | ||
<li> | ||
<a href="/test3">Test 3</a> | ||
</li> | ||
</ul> | ||
</li> | ||
and transforms it to: | ||
<li class="dropdown" > | ||
<a class="dropdown-toggle" data-toggle="dropdown" >Test<b class="caret"></b></a> | ||
<ul class="dropdown-menu"> | ||
<li> | ||
<a href="/test2">Test 2</a> | ||
</li> | ||
<li> | ||
<a href="/test3">Test 3</a> | ||
</li> | ||
</ul> | ||
</li> | ||
*/ | ||
case li @ Elem(liPrefix, "li", liAttribs, liScope, | ||
span @ Elem(spanPrefix,"span",spanAttribs,spanScope,spanChildren @ _*), | ||
ul @ Elem(ulPrefix,"ul",ulAttribs,ulScope,ulChildren @ _*), | ||
other @ _* ) => { | ||
|
||
// create a new node seq with modified attributes | ||
Elem(liPrefix,"li",newLiAttribs(liAttribs),liScope, | ||
Elem(spanPrefix, "a", newAAttribs(spanAttribs), spanScope, newAChildren(spanChildren): _*) ++ | ||
Elem(ulPrefix, "ul", newUlAttribs(ulAttribs), ulScope, ulChildren: _*) ++ | ||
other: _*) | ||
} | ||
|
||
/* matches xml of the format: | ||
*<li> | ||
<a href="/test">Test</a> | ||
<ul> | ||
<li> | ||
<a href="/test2">Test 2</a> | ||
</li> | ||
<li> | ||
<a href="/test3">Test 3</a> | ||
</li> | ||
</ul> | ||
</li> | ||
and transforms it to: | ||
<li class="dropdown" > | ||
<a class="dropdown-toggle" data-toggle="dropdown" >Test<b class="caret"></b></a> | ||
<ul class="dropdown-menu"> | ||
<li> | ||
<a href="/test2">Test 2</a> | ||
</li> | ||
<li> | ||
<a href="/test3">Test 3</a> | ||
</li> | ||
</ul> | ||
</li> | ||
*/ | ||
case li @ Elem(liPrefix, "li", liAttribs, liScope, | ||
a @ Elem(aPrefix,"a",aAttribs,aScope,aChildren @ _*), | ||
ul @ Elem(ulPrefix,"ul",ulAttribs,ulScope,ulChildren @ _*), | ||
other @ _* ) => { | ||
|
||
// create a new node seq with modified attributes | ||
Elem(liPrefix,"li",newLiAttribs(liAttribs),liScope, | ||
Elem(aPrefix, "a", newAAttribs(aAttribs), aScope, newAChildren(aChildren): _*) ++ | ||
Elem(ulPrefix, "ul", newUlAttribs(ulAttribs), ulScope, ulChildren: _*) ++ | ||
other: _*) | ||
} | ||
case other @ _ => other | ||
} | ||
} | ||
|
||
// debug("menuToTBNav received: " + new PrettyPrinter(80,3).formatNodes(in)) | ||
object rt1 extends RuleTransformer(t1) | ||
val out = rt1.transform(in) | ||
// debug("menuToTBNav out: " + new PrettyPrinter(80,3).formatNodes(out)) | ||
out | ||
} | ||
|
||
/* | ||
* an attempt at using CSS selectors rather than XML Transform - TBC | ||
def menuToTBNav(in: NodeSeq) : NodeSeq = { | ||
def testNode(ns: NodeSeq, cssSel: String): Boolean = { | ||
var ret = false // does the NodeSeq have any nodes that match the CSS Selector | ||
(cssSel #> ((ignore: NodeSeq) => {ret = true; NodeSeq.Empty}))(ns) | ||
ret | ||
} | ||
def childHasUI(ns: NodeSeq) : Boolean = { | ||
true | ||
} | ||
val f = "li [class+]" #> | ||
(((ns: NodeSeq) => Some("dropdown").filter(ignore => childHasUI(ns))): IterableFunc ) | ||
f(in) | ||
} | ||
*/ | ||
|
||
// utility methods to add the Bootstrap classes to existing attributes | ||
def newLiAttribs(oldAttribs: MetaData) = appendToClass(oldAttribs,"dropdown") | ||
def newAAttribs(oldAttribs: MetaData) = appendToClass(oldAttribs,"dropdown-toggle") | ||
.append("data-toggle" -> "dropdown") | ||
def newUlAttribs(oldAttribs: MetaData) = appendToClass(oldAttribs,"dropdown-menu") | ||
def newAChildren(oldChildren: NodeSeq) = oldChildren ++ <b class="caret"></b> | ||
|
||
|
||
|
||
// append a new value to the class attribute if one already exists, otherwise create a new class | ||
// with the given value | ||
def appendToClass(attribs: MetaData, newClass: String ) : MetaData = { | ||
// Note that MetaData.get("class") returns a Option[Seq[Node]] , not Option[Node] as might be expected | ||
// for an explanation of why see the scala-xml book: | ||
val oldClass : Option[String] = attribs.get("class").map(_.mkString).filterNot(_ == "") | ||
val resultingClass = oldClass.map( _.trim + " ").getOrElse("") + newClass | ||
attribs.append("class" -> resultingClass) | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
reactive-web-demo/src/main/scala/net/liftweb/doc/snippet/CodeInjection.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package net.liftweb.doc.snippet | ||
|
||
|
||
/* | ||
once again to lazy to add depedency | ||
https://github.com/MasseGuillaume/lift-doc | ||
*/ | ||
|
||
import net.liftweb.util.Helpers._ | ||
import net.liftweb.http.LiftRules | ||
import net.liftweb.common.{ Failure, Full } | ||
|
||
import xml.{NodeSeq, Elem} | ||
import net.liftweb.util.Helpers | ||
|
||
|
||
object CodeInjection | ||
{ | ||
|
||
def render( path: String ) = { | ||
|
||
for { | ||
( code, fileName, fileExtension ) <- openTemplate( path ) | ||
out = ( | ||
fileExtension match { | ||
case "scala" => renderCodeMirror( code, fileName, fileExtension ) | ||
case "html" => renderCodeMirror( code, fileName, fileExtension ) | ||
case _ => <pre> { code } </pre> | ||
} | ||
) | ||
} yield out | ||
} | ||
|
||
def openTemplate( path: String ) = | ||
{ | ||
for { | ||
fileName <- Full( path.split('/').last ) ?~ ( "cannot parse a filename: " + path ) | ||
fileExtension <- Full( fileName.split('.').last ) ?~ ( "cannot parse a file extension: " + fileName ) | ||
code <- LiftRules.loadResourceAsString( path ) ?~ ( "template: " + path + " not found" ) | ||
} yield ( code, fileName, fileExtension ) | ||
} | ||
|
||
def renderCodeMirror( code:String, fileName:String, fileExtension:String ) : Elem = { | ||
|
||
val guid = Helpers.nextFuncName | ||
|
||
val mode = fileExtension match { | ||
case "scala" => "text/x-scala" | ||
case "html" => "text/html" | ||
} | ||
|
||
<lift:children> | ||
<textarea id={guid}>{code}</textarea> | ||
<script> | ||
$(function(){{ | ||
CodeMirror.fromTextArea( document.getElementById("{guid}"), {{ | ||
lineNumbers: true, | ||
readOnly: true, | ||
mode: "{mode}", | ||
theme: "solarized-dark" | ||
}}) | ||
}}) | ||
</script> | ||
<label for={guid}>{ fileName }</label> | ||
</lift:children> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.