Permalink
Browse files

Enabling style-able vertical and horizontal menu section dividers.

  • Loading branch information...
1 parent b20b182 commit 7758268ecad4ade17fb1decd9edc21df7136122f @karma4u101 committed Jul 28, 2012
Showing with 35 additions and 15 deletions.
  1. +29 −14 src/main/scala/org/hoisted/lib/BaseSnippets.scala
  2. +6 −1 src/main/scala/org/hoisted/lib/MetadataKey.scala
@@ -79,37 +79,52 @@ object BaseSnippets extends LazyLoggable {
(a.findData(OrderKey).flatMap(_.asInt) openOr 0) <
(b.findData(OrderKey).flatMap(_.asInt) openOr 0)
)
-
- def buildLink(p: ParsedFile): NodeSeq =
+
+ def buildLink(p: ParsedFile): NodeSeq = {
+ def buildIconLink(ls: List[String]): NodeSeq = {
+ def buildIconLeftLink: NodeSeq = <span>{icon}{env.computeLinkText(p)}</span>
+ def buildIconRightLink: NodeSeq = <span>{env.computeLinkText(p)}{icon}</span>
+ def icon = <i class={ls.mkString(" ")}></i>
+ p.findData(MenuIconPlacementKey).flatMap(_.asString).map(_.toLowerCase()) match {
+ case Full("right") => buildIconRightLink
+ case _ => buildIconLeftLink
+ }
+ }
+ def builTextdLink: NodeSeq = Text(env.computeLinkText(p))
p.findData(MenuIconKey).map(_.forceListString) match {
- case Full(ls) =>
- def icon = <i class={ls.mkString(" ")}></i>
- p.findData(MenuIconPlacementKey).flatMap(_.asString).map(_.toLowerCase()) match {
- case Full("right") => <span>{env.computeLinkText(p)}{icon}</span>
- case _ => <span>{icon}{env.computeLinkText(p)}</span>
- }
- case _ => Text(env.computeLinkText(p))
+ case Full(ls) => buildIconLink(ls)
+ case _ => builTextdLink
}
-
+ }
+
+ def buildMenuDivider(p: ParsedFile): NodeSeq = {
+ def buildWithMenuDivider(ls: List[String]): NodeSeq = <li class={ls.mkString(" ")}></li>
+ p.findData(MenuDividerKey).map(_.forceListString) match {
+ case Full(ls) => buildWithMenuDivider(ls)
+ case _ => NodeSeq.Empty
+ }
+ }
+
if ((ns \\ "item").filter {
case e: Elem => e.prefix == "menu"
case _ => false
}.isDefined) {
- sorted.flatMap(fr =>
- bind("menu", ns, "item" -> buildLink(fr),
+ sorted.flatMap(fr =>
+ bind("menu", ns, "item" -> buildLink(fr), "divider" -> buildMenuDivider(fr),
FuncAttrOptionBindParam("class", (value: NodeSeq) =>
if (fr eq CurrentFile.value) Some(value) else None, "class"),
AttrBindParam("href", env.computeLink(fr), "href"))
- )
+ )
} else {
("*" #> sorted.map(fr =>
+ "@divider *" #> buildMenuDivider(fr) &
"a [href]" #> env.computeLink(fr) &
"a *" #> buildLink(fr) andThen
(if (fr eq CurrentFile.value)
("* [class+]" #> activeClass)
else
PassThru))).apply(ns)
- }
+ }
}
def doTitle(ns: NodeSeq): NodeSeq = <head><title>{
@@ -245,6 +245,11 @@ case object DateFormatKey extends MetadataKey {
def key = "date-format"
}
+case object MenuDividerKey extends MetadataKey {
+ def global = false
+ def key = "menu-divider"
+}
+
object MetadataKey {
lazy val knownKeys = List(OrderKey, OutputPathKey, TemplateURLKey, SiteNameKey, LinkKey,
TitleKey, TemplateKey, ServeKey,
@@ -254,7 +259,7 @@ object MetadataKey {
HasBlogKey, TagsKey, AliasKey, HTagBodyKey,
ValidFromKey, ValidToKey, EventKey, PostKey, LayoutKey, RedirectKey,
MenuLocGroupKey, MenuIconKey, MenuIconPlacementKey,
- ShowIfKey, HideIfKey, DateFormatKey)
+ ShowIfKey, HideIfKey, DateFormatKey, MenuDividerKey)
def apply(s: String): MetadataKey = {
val (_s, top) = if (s.startsWith("!")) (s.substring(1), true) else (s, false)

0 comments on commit 7758268

Please sign in to comment.