Skip to content

Commit

Permalink
Bootstrap: Improve NavBarFactory and use it in HyperscalaPage
Browse files Browse the repository at this point in the history
  • Loading branch information
tindzk committed Aug 6, 2015
1 parent 25afb98 commit 3a2529f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ import org.hyperscala.bootstrap.component._
import org.hyperscala.html.constraints.BodyChild

object NavBarFactory {
case class Link(url: String, text: String, active: Boolean = true) {
case class Link(url: String, text: String, active: Boolean = false) {
private val that = this
def li = new ListItem {
contents += new tag.A(href = url, content = text)
active := that.active
contents += new tag.A(href = url, content = text)
}
}

def apply(brand: BodyChild,
theme: NavBarTheme,
links: Seq[NavBarFactory.Link],
dropdown: Option[NavBarDropdown] = None) = {
dropdown: Option[NavBarDropdown] = None,
brandUrl: String = "#") = {
val thatTheme = theme

new NavBar {
theme := thatTheme
top := true

val navigation = new NavBarNav {
pullRight := true

links.foreach { link =>
contents += link.li
}
Expand All @@ -44,7 +47,7 @@ object NavBarFactory {
}

contents += new NavbarBrand {
href := "#"
href := brandUrl
contents += brand
}
}
Expand Down
66 changes: 13 additions & 53 deletions site/src/main/scala/org/hyperscala/site/HyperscalaPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package org.hyperscala.site
import org.hyperscala.BuildInfo
import org.hyperscala.bootstrap.Bootstrap
import org.hyperscala.bootstrap.component._
import org.hyperscala.bootstrap.component.extra.NavBarFactory
import org.hyperscala.css.SelectorStyleSheet
import org.hyperscala.css.attributes._
import org.hyperscala.html._
Expand Down Expand Up @@ -42,59 +43,18 @@ object HyperscalaPage {
paddingBottom := 30.px
}

webpage.body.contents += new NavBar {
theme := NavBarTheme.Light
top := true

val navigation = new NavBarNav {
pullRight := true

contents += new ListItem {
contents += new tag.A(href = HyperscalaSite.siteAbout.link, content = "About")
}

contents += new ListItem {
contents += new tag.A(href = HyperscalaSite.siteExamples.link, content = "Examples")
}

contents += new ListItem {
contents += new tag.A(href = HyperscalaSite.siteGenerator.link, content = "Generator")
}

contents += new ListItem {
contents += new tag.A(href = HyperscalaSite.siteDocumentation.link, content = "Documentation")
}

contents += new ListItem {
contents += new tag.A(href = "https://github.com/darkfrog26/hyperscala/", content = "Project")
}
}

val header = new NavBarHeader {
contents += new NavBarToggle {
contents += new tag.Span(clazz = List("sr-only")) {
contents += "Toggle navigation"
}
contents += new tag.Span(clazz = List("icon-bar"))
contents += new tag.Span(clazz = List("icon-bar"))
contents += new tag.Span(clazz = List("icon-bar"))
}

contents += new NavbarBrand {
href := "/"
contents += new tag.Img(id = "logo", src = "/images/hyperscala.png", alt = "Hyperscala")
}
}

val bar = new NavBarCollapse {
contents += navigation
}

contents += new Container {
contents += header
contents += bar
}
}
webpage.body.contents += NavBarFactory(
new tag.Img(id = "logo", src = "/images/hyperscala.png", alt = "Hyperscala"),
NavBarTheme.Light,
links = Seq(
NavBarFactory.Link(HyperscalaSite.siteAbout.link, "About"),
NavBarFactory.Link(HyperscalaSite.siteExamples.link, "Examples"),
NavBarFactory.Link(HyperscalaSite.siteGenerator.link, "Generator"),
NavBarFactory.Link(HyperscalaSite.siteDocumentation.link, "Documentation"),
NavBarFactory.Link("https://github.com/darkfrog26/hyperscala/", "Project")
),
brandUrl = "/"
)

val main = new tag.Div
val container = new Container {
Expand Down

0 comments on commit 3a2529f

Please sign in to comment.