Skip to content
Browse files

Added Designer-Friendly and CSS info

Closes #28 (CSS transforms)
Closes #30 (DFT)
Closes #39 (minor fixes to XMPP section wording)
Closes #40 (minor fix to rewrite example)
  • Loading branch information...
1 parent bc597b5 commit e48ff78bc0319ae5c09b126dc5a225547192e296 @dchenbecker dchenbecker committed
Showing with 1,989 additions and 32 deletions.
  1. +2 −7 chap-lift_architecture.lyx
  2. +30 −4 chap-record_and_mapper.lyx
  3. +1,441 −3 chap-snippets.lyx
  4. +503 −4 chap-template_xhtml.lyx
  5. +13 −14 chap-thirdparty.lyx
View
9 chap-lift_architecture.lyx
@@ -1719,7 +1719,7 @@ name "lst:Complex-rewrite-example"
\begin_layout Plain Layout
-val rewriter : PartialFunction[RewriteRequest,RewriteResponse] = {
+LiftRules.rewrite.append {
\end_layout
\begin_layout Plain Layout
@@ -1744,7 +1744,7 @@ val rewriter : PartialFunction[RewriteRequest,RewriteResponse] = {
\begin_layout Plain Layout
- RewriteResponse(deleteUser :: Nil, Map(username -> username))
+ RewriteResponse(deleteUser :: Nil, Map("username" -> username))
\end_layout
\begin_layout Plain Layout
@@ -1752,11 +1752,6 @@ val rewriter : PartialFunction[RewriteRequest,RewriteResponse] = {
}
\end_layout
-\begin_layout Plain Layout
-
-LiftRules.rewrite.append(rewriter)
-\end_layout
-
\end_inset
View
34 chap-record_and_mapper.lyx
@@ -5427,20 +5427,46 @@ The lifecycle hooks are executed at the main operations in an instance lifecycle
\end_layout
\begin_layout Description
-Create When a new instance is created
+Create When a fresh instance is first saved (corresponding to a table insert).
\end_layout
\begin_layout Description
-Delete When an instance is deleted
+Delete When an instance is deleted.
\end_layout
\begin_layout Description
-Save When a fresh instance is first saved (corresponding to a table insert)
+Save When a new or existing instance is inserted or updated.
+
+\family typewriter
+beforeSave
+\family default
+ is always called before
+\family typewriter
+beforeCreate
+\family default
+ or
+\family typewriter
+beforeUpdate
+\family default
+.
+ Similarly,
+\family typewriter
+afterSave
+\family default
+ is always called after
+\family typewriter
+afterCreate
+\family default
+ or
+\family typewriter
+afterUpdate
+\family default
+.
\end_layout
\begin_layout Description
Update When an instance that already exists in the database is updated (correspo
-nding to a table update)
+nding to a table update).
\end_layout
\begin_layout Description
View
1,444 chap-snippets.lyx
@@ -1,4 +1,4 @@
-#LyX 1.6.5 created this file. For more info see http://www.lyx.org/
+#LyX 1.6.7 created this file. For more info see http://www.lyx.org/
\lyxformat 345
\begin_document
\begin_header
@@ -173,6 +173,18 @@ Usage: <lift:snippet type="snippetName" ...options...
/>
\end_layout
+\begin_layout LyX-Code
+ <div class=
+\begin_inset Quotes erd
+\end_inset
+
+lift:snippetName?opt1=...;opt2=...;opt3=...
+\begin_inset Quotes erd
+\end_inset
+
+ />
+\end_layout
+
\begin_layout Standard
The snippet tag is what you use to tell Lift where and how to invoke a snippet
method on given XML content.
@@ -396,6 +408,128 @@ reference "sub:Eager-Eval"
.
\end_layout
+\begin_layout Standard
+With Lift 2.2's Designer-Friendly Templates (Section
+\begin_inset CommandInset ref
+LatexCommand vref
+reference "sec:Designer-Friendly-Templates"
+
+\end_inset
+
+), you can also specify a snippet tag as part of the class attribute for
+ a given element.
+ Options for snippets invoked in this manner are passed via a slightly modified
+ form of a query string, with a semicolon separating options instead of
+ an ampersand.
+ Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Invoking-Snippets-Via-Class"
+
+\end_inset
+
+ shows an example of how we can use the standard
+\family typewriter
+lift:surround
+\family default
+ processing by modiying the
+\family typewriter
+class
+\family default
+ of our content element.
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Caption
+
+\begin_layout Plain Layout
+
+Invoking Snippets Via the Class Attribute
+\begin_inset CommandInset label
+LatexCommand label
+name "lst:Invoking-Snippets-Via-Class"
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+\end_layout
+
+\begin_layout Plain Layout
+
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <html xmlns="http://www.w3.org/1999/xhtml">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <head>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <title>Not really</title>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </head>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <body class="lift:content_id=real_content">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <div class="lift:surround?with=default;at=content" id="real_content">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <h1>Welcome to your project!</h1>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </div>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </body>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </html>
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
\begin_layout Section
Snippet Dispatch
\begin_inset CommandInset label
@@ -1237,8 +1371,11 @@ reference "lst:Binding-Our-Explicit-snippet"
\family typewriter
<lift:HelloWorld/>
\family default
-, and because our DispatchSnippet uses a simple variable binding for its
-
+, and because our
+\family typewriter
+DispatchSnippet
+\family default
+ uses a simple variable binding for its
\family typewriter
dispatch
\family default
@@ -1267,6 +1404,44 @@ render
\end_inset
, following Lift's normal snippet tag conventions).
+ Noe that if you're setting up a dispatch for a
+\family typewriter
+StatefulSnippet
+\family default
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+StatefulSnippet
+\end_layout
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Snippets ! stateful
+\end_layout
+
+\end_inset
+
+, return a new instance of your
+\family typewriter
+StatefulSnippet
+\family default
+ class.
+
+\family typewriter
+StatefulSnippet
+\family default
+ instances will properly register themselves ahead of the
+\family typewriter
+snippetDispatch
+\family default
+ partial function on each successive request.
\end_layout
\begin_layout Standard
@@ -1321,6 +1496,21 @@ class Boot {
\begin_layout Plain Layout
+ // For StatefulSnippets, return a *new instance*
+\end_layout
+
+\begin_layout Plain Layout
+
+ case "HelloConversation" =>
+\end_layout
+
+\begin_layout Plain Layout
+
+ new com.foo.logic.StatefulHelloWorld
+\end_layout
+
+\begin_layout Plain Layout
+
}
\end_layout
@@ -2136,6 +2326,1254 @@ Attributes ! -%> operator
\end_layout
\begin_layout Subsection
+CSS Selector Transforms
+\begin_inset CommandInset label
+LatexCommand label
+name "sub:CSS-Selector-Transforms"
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+CSS ! selector transforms
+\end_layout
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Binding ! with CSS
+\end_layout
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Snippets ! binding with CSS
+\end_layout
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+CSS Transforms
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+In addition to the binding support detailed in Section
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sub:Binding-Values-in-snippets"
+
+\end_inset
+
+, Lift 2.2 introduces binding via CSS transforms as part of its support for
+ designer friendly templates.
+ These allow you to bind values into template XHTML (or HTML5, see Section
+
+\begin_inset CommandInset ref
+LatexCommand vref
+reference "sec:HTML5-Support"
+
+\end_inset
+
+) by using the attributes on specific elements.
+ Let's start by looking at a basic example, corresponding to the examples
+ in Section
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sub:Binding-Values-in-snippets"
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Standard
+Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:A-Simple-CSS-snippet"
+
+\end_inset
+
+ shows a Designer-Friendly version of Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Snippet-tag-children"
+
+\end_inset
+
+.
+ You can see that we're invoking the
+\family typewriter
+Ledger.balance
+\family default
+ snippet via the class attribute, and we've specified the binding elements
+ as normal
+\family typewriter
+<span/>
+\family default
+ elements with
+\family typewriter
+id
+\family default
+ attributes.
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Caption
+
+\begin_layout Plain Layout
+
+A Simple CSS Snippet
+\begin_inset CommandInset label
+LatexCommand label
+name "lst:A-Simple-CSS-snippet"
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+
+<div class="lift:Ledger.balance">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <span id="balance">$0</span> as of <span id="time">midnight</span>
+\end_layout
+
+\begin_layout Plain Layout
+
+</div>
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Now, we need to perform the CSS transform within our snippet.
+ The binding implicits for CSS transforms are found on the
+\family typewriter
+net.liftweb.util.BindHelpers
+\family default
+ object/trait, so you should import it (in particular, the
+\family typewriter
+strToCssBindPromoter
+\family default
+ method).
+ Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Binding-the-Ledger-with-CSS"
+
+\end_inset
+
+ shows how we modify the snippet in Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Binding-the-ledger-balance"
+
+\end_inset
+
+ to utilize the new CSS transform.
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Caption
+
+\begin_layout Plain Layout
+
+Binding the Ledger Balance with CSS
+\begin_inset CommandInset label
+LatexCommand label
+name "lst:Binding-the-Ledger-with-CSS"
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+
+import net.liftweb.util.BindHelpers._
+\end_layout
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\begin_layout Plain Layout
+
+class Ledger {
+\end_layout
+
+\begin_layout Plain Layout
+
+ def balance = "#balance" #> currentLedger.formattedBalance &
+\end_layout
+
+\begin_layout Plain Layout
+
+ "#time" #> (new java.util.Date).toString
+\end_layout
+
+\begin_layout Plain Layout
+
+}
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+As you can see in this example, CSS transforms are comprised of three parts:
+ the transform selector, the transform operator (
+\family typewriter
+#>
+\family default
+), and the right hand side value.
+ This value can be a number of different things, which we'll cover in Section
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sub:Replacement-Values"
+
+\end_inset
+
+, but in our case we're using a
+\family typewriter
+MappedField
+\family default
+ and a
+\family typewriter
+String
+\family default
+.
+ Additionally, you can chain transforms together with the
+\family typewriter
+&
+\family default
+ operator.
+\end_layout
+
+\begin_layout Subsubsection
+CSS Selector Syntax
+\end_layout
+
+\begin_layout Standard
+The selector syntax is based on a subset of CSS, so if you already know
+ that you're well on your way.
+ The syntax can operate on elements based on id or class, and can also operate
+ on attributes of those elements.
+ Let's look at the basic syntax:
+\end_layout
+
+\begin_layout Itemize
+
+\family typewriter
+#foo
+\family default
+ - Selects the element with an id attribute of
+\begin_inset Quotes eld
+\end_inset
+
+foo
+\begin_inset Quotes erd
+\end_inset
+
+
+\end_layout
+
+\begin_layout Itemize
+
+\family typewriter
+.foo
+\family default
+ - Selects all elements with class of
+\begin_inset Quotes eld
+\end_inset
+
+foo
+\begin_inset Quotes erd
+\end_inset
+
+
+\end_layout
+
+\begin_layout Itemize
+
+\family typewriter
+attrName=attrValue
+\family default
+ - Selects all elements with an attribute of
+\begin_inset Quotes eld
+\end_inset
+
+attrName
+\begin_inset Quotes erd
+\end_inset
+
+ equal to
+\begin_inset Quotes eld
+\end_inset
+
+attrValue
+\begin_inset Quotes erd
+\end_inset
+
+
+\end_layout
+
+\begin_layout Itemize
+
+\family typewriter
+element
+\family default
+ - Selects all
+\begin_inset Quotes eld
+\end_inset
+
+element
+\begin_inset Quotes erd
+\end_inset
+
+ elements (e.g.
+ span, h1, etc.)
+\end_layout
+
+\begin_layout Itemize
+
+\family typewriter
+*
+\family default
+ - Selects all elements
+\end_layout
+
+\begin_layout Standard
+The element matching the selector is replaced by the result of processing
+ the replacement.
+ That means that in the example of Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:A-Simple-CSS-snippet"
+
+\end_inset
+
+ the
+\family typewriter
+span
+\family default
+ elements will be replaced with straight Text elements, resulting in the
+ markup shown in Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Sample-CSS-Transform-result"
+
+\end_inset
+
+ (in other words, no remaining markup).
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "language=XML,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Caption
+
+\begin_layout Plain Layout
+
+Sample CSS Transform Result
+\begin_inset CommandInset label
+LatexCommand label
+name "lst:Sample-CSS-Transform-result"
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+
+$12.42 as of Fri Jan 14 08:29:50 MST 2011
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+You can further refine the replacement with an optional qualifier.
+ We've already seen how omitting the qualifer results in wholesale replacement
+ of the matching element, but there are a few additional options:
+\end_layout
+
+\begin_layout Itemize
+
+\family typewriter
+*
+\family default
+ - Replaces the children of the selected element.
+ For example, if we changed our selector in Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Binding-the-Ledger-with-CSS"
+
+\end_inset
+
+ from
+\family typewriter
+
+\begin_inset Quotes eld
+\end_inset
+
+#balance
+\begin_inset Quotes erd
+\end_inset
+
+
+\family default
+ to
+\family typewriter
+
+\begin_inset Quotes eld
+\end_inset
+
+#balance *
+\begin_inset Quotes erd
+\end_inset
+
+
+\family default
+, we would be replacing the text node child (
+\begin_inset Quotes eld
+\end_inset
+
+$0
+\begin_inset Quotes erd
+\end_inset
+
+), with the resulting markup:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,language=HTML,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+<span id="balance">$12.42</span> as of Fri Jan 14 08:29:50 MST 2011
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Note that when we perform child replacement, the parent's attributes
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+CSS Transforms ! attribute copying
+\end_layout
+
+\end_inset
+
+ are carried over to the resulting element.
+ There is an exception to this in the case of iterated replacements, which
+ we'll cover in Section
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sub:Replacement-Values"
+
+\end_inset
+
+.
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+
+\family typewriter
+[name]
+\family default
+ -
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+CSS Transforms ! attribute replacement
+\end_layout
+
+\end_inset
+
+Sets the value of the
+\family typewriter
+
+\begin_inset Quotes erd
+\end_inset
+
+name
+\begin_inset Quotes erd
+\end_inset
+
+
+\family default
+ attribute on the selected element.
+ If the attribute already exists on the selected element, its value is replaced,
+ otherwise the attribute is added.
+ For example, if we wanted to replace both the link text and
+\family typewriter
+href
+\family default
+ of a link via CSS transform for the template
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,language=HTML,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+<a href=
+\begin_inset Quotes erd
+\end_inset
+
+#
+\begin_inset Quotes erd
+\end_inset
+
+>ReplaceMe</a>
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+We could perform this by chaining two selections together, one for the child
+ element (link text) and one for the
+\family typewriter
+href
+\family default
+ attribute:
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Quotes eld
+\end_inset
+
+a *
+\begin_inset Quotes erd
+\end_inset
+
+ #>
+\begin_inset Quotes eld
+\end_inset
+
+This is the link text
+\begin_inset Quotes erd
+\end_inset
+
+ &
+\begin_inset Quotes eld
+\end_inset
+
+a [href]
+\begin_inset Quotes erd
+\end_inset
+
+ #>
+\begin_inset Quotes eld
+\end_inset
+
+http://foo.com/bar
+\begin_inset Quotes erd
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Note that the order of the selections is not important.
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+
+\family typewriter
+[name+]
+\family default
+ - Appends a value to the attribute on the selected element.
+ If the attribute doesn't already exist on the element then this behaves
+ the same as the
+\family typewriter
+[name]
+\family default
+ qualifier.
+ One example would be adding to the
+\family typewriter
+class
+\family default
+ attribute for a given element:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Quotes eld
+\end_inset
+
+tr [class+]
+\begin_inset Quotes erd
+\end_inset
+
+ #> (if (index % 2)
+\begin_inset Quotes eld
+\end_inset
+
+odd
+\begin_inset Quotes erd
+\end_inset
+
+ else
+\begin_inset Quotes eld
+\end_inset
+
+even
+\begin_inset Quotes erd
+\end_inset
+
+)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+
+\family typewriter
+^^
+\family default
+ - Makes the selected element the root of the returned elements.
+ This can be used to select a particular element from a template, similar
+ to
+\family typewriter
+BindHelpers.chooseTemplate
+\family default
+.
+ The right hand side for the selected element is ignored, but you can chain
+ further transforms to modify the returned element.
+ For example, if we decided to only output the balance in Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:A-Simple-CSS-snippet"
+
+\end_inset
+
+, we could do so by changing our snippet code to:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+def balance =
+\begin_inset Quotes eld
+\end_inset
+
+#balance ^^
+\begin_inset Quotes erd
+\end_inset
+
+ #>
+\begin_inset Quotes eld
+\end_inset
+
+ignore
+\begin_inset Quotes erd
+\end_inset
+
+ &
+\end_layout
+
+\begin_layout Plain Layout
+
+
+\begin_inset Quotes eld
+\end_inset
+
+#balance
+\begin_inset Quotes erd
+\end_inset
+
+ #> currentLedger.formattedBalance
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Subsubsection
+Right Hand Side Values
+\begin_inset CommandInset label
+LatexCommand label
+name "sub:Replacement-Values"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+The right hand side of a CSS transform operates on the selected element
+ to either transform or replace it.
+ It can be one of:
+\end_layout
+
+\begin_layout Itemize
+
+\family typewriter
+String
+\family default
+ constant - returns a Text node for the
+\family typewriter
+String
+\family default
+.
+ For example, in Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Binding-the-Ledger-with-CSS"
+
+\end_inset
+
+:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+"#time" #> (new java.util.Date).toString
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+A
+\family typewriter
+NodeSeq
+\family default
+ constant - returns the
+\family typewriter
+NodeSeq
+\family default
+ itself.
+ In Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Binding-the-Ledger-with-CSS"
+
+\end_inset
+
+ we could have done this instead:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+"#time" #> Text((new java.util.Date).toString)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+\begin_inset Formula $NodeSeq\Rightarrow NodeSeq$
+\end_inset
+
+ - a function that transforms the selected element.
+ Note that CSS transforms extend
+\begin_inset Formula $NodeSeq\Rightarrow NodeSeq$
+\end_inset
+
+, so you can nest transforms like
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+// Select the element with id "entry" and then bind its
+\end_layout
+
+\begin_layout Plain Layout
+
+// nested "name" element
+\end_layout
+
+\begin_layout Plain Layout
+
+"#entry" #> { "#name" #> account.name }
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+
+\family typewriter
+net.liftweb.util.Bindable
+\family default
+ - Instances that implement the
+\family typewriter
+Bindable
+\family default
+ trait will be automatically converted into a
+\family typewriter
+NodeSeq
+\family default
+.
+ Among other things,
+\family typewriter
+MappedField
+\family default
+ and
+\family typewriter
+Record.Field
+\family default
+ support this, which allows us to use instances directly:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+"#description" #> account.description
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+
+\family typewriter
+Boolean
+\family default
+,
+\family typewriter
+Int
+\family default
+,
+\family typewriter
+Long
+\family default
+ or
+\family typewriter
+Symbol
+\family default
+ - These are automatically promoted to a
+\family typewriter
+String
+\family default
+ via the
+\family typewriter
+net.liftweb.util.StringPromotable
+\family default
+ trait and implicits on its companion object
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+"#viewperm" #> account.isViewableBy(someUser)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+A
+\family typewriter
+Box
+\family default
+,
+\family typewriter
+Option
+\family default
+ or
+\family typewriter
+Seq
+\family default
+ of
+\family typewriter
+String
+\family default
+,
+\family typewriter
+NodeSeq
+\family default
+,
+\family typewriter
+Bindable
+\family default
+ or values convertable by
+\family typewriter
+StringPromotable
+\family default
+ - These will be converted into a
+\family typewriter
+net.liftweb.util.IterableConst
+\family default
+, which is used to compute a
+\family typewriter
+Seq[NodeSeq]
+\family default
+.
+ If your selector replaces the children of the selected element (*), the
+
+\family typewriter
+IterableConst
+\family default
+ is applied to the selected element once for each item in the
+\family typewriter
+Seq
+\family default
+.
+ In other words, you get a copy of the selected element for each original
+ input.
+ For example, given the template:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,language=HTML,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+<h2>Account names:</h2>
+\end_layout
+
+\begin_layout Plain Layout
+
+<ul>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <li id="item">Account</li>
+\end_layout
+
+\begin_layout Plain Layout
+
+</ul>
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+We can iterate over a list of accounts with the CSS transform:
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+"#item *" #> accounts.map(_.name.toString)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Which, assuming a set of accounts named
+\begin_inset Quotes eld
+\end_inset
+
+A
+\begin_inset Quotes erd
+\end_inset
+
+,
+\begin_inset Quotes eld
+\end_inset
+
+B
+\begin_inset Quotes erd
+\end_inset
+
+, and
+\begin_inset Quotes eld
+\end_inset
+
+C
+\begin_inset Quotes erd
+\end_inset
+
+, results in:
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "frame=none,language=HTML,numbers=none"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+<h2>Account names:</h2>
+\end_layout
+
+\begin_layout Plain Layout
+
+<ul>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <li id="item">A</li>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <li>B</li>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <li>C</li>
+\end_layout
+
+\begin_layout Plain Layout
+
+</ul>
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+\begin_inset Box Shadowbox
+position "t"
+hor_pos "c"
+has_inner_box 1
+inner_pos "t"
+use_parbox 0
+width "80col%"
+special "none"
+height "1in"
+height_special "totalheight"
+status open
+
+\begin_layout Plain Layout
+Note that the
+\family typewriter
+id
+\family default
+ attribute is only placed on the first transformed element.
+ Subsequent replacements strip the
+\family typewriter
+id
+\family default
+ attribute so that it remains unique on the page.
+ This special handling applies only to the
+\family typewriter
+id
+\family default
+ attribute; other attributes, such as
+\family typewriter
+class
+\family default
+, are not similarly stripped.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+A
+\family typewriter
+Box
+\family default
+,
+\family typewriter
+Option
+\family default
+ or
+\family typewriter
+Seq
+\family default
+ of
+\begin_inset Formula $NodeSeq\Rightarrow NodeSeq$
+\end_inset
+
+ - These will be converted into a
+\family typewriter
+net.liftweb.util.IterableFunc
+\family default
+, and follow the same rules for replacement as
+\family typewriter
+IterableConst
+\family default
+ (e.g.
+ child replacement repetition).
+\end_layout
+
+\begin_layout Subsection
Stateless versus Stateful Snippets
\begin_inset CommandInset label
LatexCommand label
View
507 chap-template_xhtml.lyx
@@ -72,8 +72,38 @@ XML
files, but also from methods that can programmaticaly generate template
XML.
- In this chapter we'll discuss the template XML capabilities and syntax,
- including XML tags provided by Lift that perform special template processing
+ Additionally, Lift 2.2
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Lift 2.2
+\end_layout
+
+\end_inset
+
+ brings designer-friendly templates (Section
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sec:Designer-Friendly-Templates"
+
+\end_inset
+
+) and HTML5 support (Section
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sec:HTML5-Support"
+
+\end_inset
+
+).
+ Designer-friendly templates, in particular, can simplify working with a
+ designer because they allow templates to be fully valid XHTML or HTML5.
+\end_layout
+
+\begin_layout Standard
+In this chapter we'll discuss template capabilities and syntax, including
+ built-in tags provided by Lift that perform special template processing
(Section
\begin_inset CommandInset ref
LatexCommand ref
@@ -1019,6 +1049,441 @@ y if you assemble your templates using the surround and embed tags.
\end_layout
\begin_layout Section
+Designer-Friendly Templates
+\begin_inset CommandInset label
+LatexCommand label
+name "sec:Designer-Friendly-Templates"
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Templates ! Designer-friendly
+\end_layout
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Designer-friendly templates
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+New in Lift 2.2 is the ability to use fully valid XHTML (or HTML5, which
+ we'll discuss in Section
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sec:HTML5-Support"
+
+\end_inset
+
+) for your templates.
+ There are a number of features involved in designer-friendly templates
+ (or DFTs for short), so let's go through each one.
+\end_layout
+
+\begin_layout Subsection
+Determining the Content Element
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Templates ! content element
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+In XML-based templates, the entire XML file is considered to hold the contents
+ of the template.
+ In DFTs, we want to be able to include the full XHTML or HTML5 markup,
+ including tags like
+\family typewriter
+<DOCTYPE>
+\family default
+,
+\family typewriter
+<html/>
+\family default
+, etc.
+ without necessarily including all of that in the output of the template
+ (for example, in an embedded template).
+ Lift supports choosing a child element of the template to represent the
+ actual contents via the use of one of two related mechanisms.
+\end_layout
+
+\begin_layout Standard
+The first mechanism is to put a
+\family typewriter
+lift:content_id
+\family default
+ attribute on the HTML element, as shown in Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Assigning-a-Content-ID-HTML"
+
+\end_inset
+
+.
+ The drawback to this approach is that you have to specify the
+\begin_inset Quotes eld
+\end_inset
+
+lift
+\begin_inset Quotes erd
+\end_inset
+
+ namespace in the html tag or you might get validation errors.
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "language=HTML"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Caption
+
+\begin_layout Plain Layout
+
+Assigning a Content ID on the HTML element
+\begin_inset CommandInset label
+LatexCommand label
+name "lst:Assigning-a-Content-ID-HTML"
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+\end_layout
+
+\begin_layout Plain Layout
+
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <html xmlns="http://www.w3.org/1999/xhtml"
+\end_layout
+
+\begin_layout Plain Layout
+
+ xmlns:lift="http://liftweb.net"
+\end_layout
+
+\begin_layout Plain Layout
+
+ lift:content_id="real_content">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <head>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <title>Not really</title>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </head>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <body>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <div id="real_content">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <h1>Welcome to your project!</h1>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </div>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </body>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </html>
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+The second, safer approach, is to specific the
+\family typewriter
+lift:content_id
+\family default
+ marker as part of the body element's
+\family typewriter
+class
+\family default
+ attribute, as shown in Listing
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "lst:Assigning-a-Content-ID-Body"
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "language=HTML"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Caption
+
+\begin_layout Plain Layout
+
+Assigning a Content ID in the Body class
+\begin_inset CommandInset label
+LatexCommand label
+name "lst:Assigning-a-Content-ID-Body"
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+\end_layout
+
+\begin_layout Plain Layout
+
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <html xmlns="http://www.w3.org/1999/xhtml">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <head>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <title>Not really</title>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </head>
+\end_layout
+
+\begin_layout Plain Layout
+
+ <body class="lift:content_id=real_content">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <div id="real_content">
+\end_layout
+
+\begin_layout Plain Layout
+
+ <h1>Welcome to your project!</h1>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </div>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </body>
+\end_layout
+
+\begin_layout Plain Layout
+
+ </html>
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Subsection
+Invoking Snippets Via the Class Attribute
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Snippets ! invoking via class attributes
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+In XML-based templates, Lift looks for tags with the
+\begin_inset Quotes eld
+\end_inset
+
+lift
+\begin_inset Quotes erd
+\end_inset
+
+ prefix to process.
+ In DFTs, the
+\family typewriter
+class
+\family default
+ attribute is used instead for invocation.
+ This form of invocation is discussed in more detail in Section
+\begin_inset CommandInset ref
+LatexCommand vref
+reference "sec:The-Snippet-Tag"
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Subsection
+Binding via CSS transforms
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Binding ! with CSS
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Lift 2.2 introduces a new feature for binding values into snippet markup
+ by using CSS id and class attributes instead of prefixed XML elements.
+ This support is detailed in Section
+\begin_inset CommandInset ref
+LatexCommand vref
+reference "sub:CSS-Selector-Transforms"
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Section
+HTML5 Support
+\begin_inset CommandInset label
+LatexCommand label
+name "sec:HTML5-Support"
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+HTML5
+\end_layout
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+HTML ! Version 5
+\end_layout
+
+\end_inset
+
+
+\begin_inset Index
+status open
+
+\begin_layout Plain Layout
+Templates ! HTML5
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+\begin_inset Note Note
+status open
+
+\begin_layout Plain Layout
+TODO: Fill me in!
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Section
Views
\begin_inset CommandInset label
LatexCommand label
@@ -2296,7 +2761,7 @@ The
\family typewriter
<lift:CSS/>
\family default
- tag is used to insert either the blueprint
+ tag is used to insert the blueprint
\begin_inset Foot
status open
@@ -2316,7 +2781,27 @@ http://www.blueprintcss.org/
\end_inset
- or fancy
+ and (optionally) fancyType
+\begin_inset Foot
+status open
+
+\begin_layout Plain Layout
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://anthonygthomas.com/2010/02/15/blueprint-optional-fancy-type-plugin/
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+ CSS stylesheets
\end_layout
\begin_layout Subsection
@@ -2453,6 +2938,20 @@ loc
Menu
\end_layout
+\begin_layout Standard
+\begin_inset Note Note
+status open
+
+\begin_layout Plain Layout
+Add a note about naming Menus for Menu.item when using the DSL (e.g.
+ Menu.i or explicit name)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
\begin_layout Subsection
Msgs
\end_layout
View
27 chap-thirdparty.lyx
@@ -1,4 +1,4 @@
-#LyX 1.6.0 created this file. For more info see http://www.lyx.org/
+#LyX 1.6.7 created this file. For more info see http://www.lyx.org/
\lyxformat 345
\begin_document
\begin_header
@@ -957,8 +957,8 @@ class ExampleStringAMQPListener {
\begin_layout Plain Layout
- case msg@AMQPMessage(contents: String) => println("received: " + msg);
- act
+ case msg@AMQPMessage(contents: String) => println("received: " +
+ msg); act
\end_layout
\begin_layout Plain Layout
@@ -1002,7 +1002,7 @@ class ExampleStringAMQPListener {
\end_layout
\begin_layout Standard
-First of all don't get scarred about this.
+First of all don't get scared about this.
The above classes are already existent so you can just reuse them.
However the point of showing them here is to understand how to use a AMQP
consumer, how to configure it to match the client settings from the Listing
@@ -1506,7 +1506,7 @@ http://xmpp.org/
\end_inset
- stand for e
+ stands for e
\series bold
X
\series default
@@ -1523,9 +1523,10 @@ resence
P
\series default
rotocol.
- It is an XML based protocol presence and realtime communication such as
- instance messaging.
- It is developer by Jabber
+ It is an XML-based protocol used for presence and realtime communication
+ such as instant messaging (Jabber and GoogleTalk being two of the more
+ famous users).
+ It is developed by the Jabber
\begin_inset Foot
status open
@@ -1536,9 +1537,9 @@ http://xmpp.org/about/jabber.shtml
\end_inset
open-source community.
- Lift provides an XMPP dispatcher implementation that you application can
+ Lift provides an XMPP dispatcher implementation that your application can
use to receive instant messages, manage rosters etc.
- This support realies on Smack
+ This support relies on the Smack
\begin_inset Foot
status open
@@ -1548,7 +1549,7 @@ http://www.igniterealtime.org/downloads/index.jsp
\end_inset
- XMPP client library and Scala actors as the actors model fits like a glove.
+ XMPP client library and utilizes Scala actors for the interface.
Here is an example:
\end_layout
@@ -2085,8 +2086,6 @@ ConsoleChatHelper.run(userName, password);
\begin_layout Standard
The above is an example how you can integrate your application with an XMPP
server and how messages are pocessed.
- We won;t be detailing each line of code in this example as it is pretty
- much self explanatory and straight forward.
\end_layout
\begin_layout Section
@@ -2104,7 +2103,7 @@ width "100col%"
special "none"
height "1in"
height_special "totalheight"
-status collapsed
+status open
\begin_layout Plain Layout
This chapter is still under active development.

0 comments on commit e48ff78

Please sign in to comment.
Something went wrong with that request. Please try again.