Skip to content

Commit

Permalink
Introduce hepek-play. Move more stuff to hepek-components. Reorganize…
Browse files Browse the repository at this point in the history
… packages
  • Loading branch information
sake92 committed May 12, 2019
1 parent d8dba7e commit b83c0e6
Show file tree
Hide file tree
Showing 41 changed files with 235 additions and 279 deletions.
12 changes: 10 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ lazy val hepekProject = (project in file("hepek"))
)
.dependsOn(hepekComponents)

// play
lazy val hepekPlay = (project in file("hepek-play"))
.settings(
name := "hepek-play"
)
.dependsOn(hepekComponents)
.enablePlugins(PlayScala)

// docs
lazy val hepekDocs = (project in file("hepek-docs"))
.settings(
skip in publish := true,
skip in publish := true,
hepekTarget := baseDirectory.value / "..",
(hepek in Compile) := {
WebKeys.assets.value
Expand All @@ -70,7 +78,7 @@ lazy val hepekDocs = (project in file("hepek-docs"))
// tests
lazy val hepekTests = (project in file("hepek-tests"))
.settings(
skip in publish := true,
skip in publish := true,
(test in Test) := {
WebKeys.assets.value
(hepek in Compile).value // run hepek before tests
Expand Down
29 changes: 29 additions & 0 deletions hepek-components/src/main/scala/ba/sake/hepek/HepekAliases.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ba.sake.hepek

private[hepek] trait HepekAliases {

val SiteSettings = html.SiteSettings
type SiteSettings = html.SiteSettings

val PageSettings = html.PageSettings
type PageSettings = html.PageSettings

// deps
val Dependency = html.Dependency
type Dependency = html.Dependency

val Dependencies = html.Dependencies
type Dependencies = html.Dependencies

val DependencyProvider = html.DependencyProvider

// grid
val Ratio = html.component.GridComponents.Ratio
type Ratio = html.component.GridComponents.Ratio

val Ratios = html.component.GridComponents.Ratios
type Ratios = html.component.GridComponents.Ratios

val ScreenRatios = html.component.GridComponents.ScreenRatios
type ScreenRatios = html.component.GridComponents.ScreenRatios
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ba.sake.hepek.anchorjs

import ba.sake.hepek.html.structure._
import ba.sake.hepek.html._

/** You need to provide Anchorjs config by yourself.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package ba.sake.hepek.bootstrap3

import ba.sake.hepek.html.Bundle
import ba.sake.hepek.bootstrap3.component.BootstrapComponentsBundle
import ba.sake.hepek.bootstrap3.statik.BootstrapStaticPage

trait BootstrapBundle extends Bundle with BootstrapComponentsBundle {

override type StaticPage = BootstrapStaticPage
override type HtmlPage = BootstrapPage
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ba.sake.hepek.bootstrap3

import ba.sake.hepek.html.structure._
import ba.sake.hepek.html._
import ba.sake.hepek.jquery.JQueryDependencies

trait BootstrapDependencies extends JQueryDependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ba.sake.hepek.bootstrap3

import scalatags.Text.all._
import ba.sake.hepek.html._

trait BootstrapPage extends HtmlPage with BootstrapDependencies {

def bootstrapContainer: String = "container-fluid"

override def bodyContent: Frag =
div(cls := bootstrapContainer)(
)

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ba.sake.hepek.clipboardjs

import ba.sake.hepek.html.structure._
import ba.sake.hepek.html._

trait ClipboardjsDependencies extends PageDependencies {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import ba.sake.hepek.html.component.ComponentsBundle

trait Bundle extends ComponentsBundle {

type StaticPage <: structure.StaticPage
type HtmlPage <: ba.sake.hepek.html.HtmlPage
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ba.sake.hepek.html.structure
package ba.sake.hepek.html

abstract class BaseComponentSettings(
val version: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ba.sake.hepek.html.structure
package ba.sake.hepek.html

case class Dependency(
file: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ba.sake.hepek.html.structure
package ba.sake.hepek.html

trait DependencyProvider {
def depPath(dep: Dependency): String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
package ba.sake.hepek.html.structure
package ba.sake.hepek.html

import ba.sake.hepek.core.Renderable
import ba.sake.hepek.path.ClassPackageRelativePath
import scalatags.Text.all._

trait StaticPage extends Renderable with ClassPackageRelativePath with PageDependencies {
import scalatags.Text.all._
trait HtmlPage extends PageDependencies {

def siteSettings: SiteSettings = SiteSettings()
def pageSettings: PageSettings = PageSettings()

def renderPretty = false
def renderXhtml = false

// <head>
def headContent: Frag =
frag(
meta(charset := "utf-8"),
meta(
attr("http-equiv") := "X-UA-Compatible",
content := "ie=edge"
),
meta(
name := "viewport",
content := "width=device-width, initial-scale=1"
),
pageSettings.description.map { d =>
meta(name := "description", content := d)
},
tag("title")(
pageSettings.title + siteSettings.name.map(n => " - " + n).getOrElse("")
),
siteSettings.faviconNormal.map { fav =>
link(rel := "shortcut icon", href := fav, tpe := "image/x-icon")
}
)

// <body>
def bodyContent: Frag = pageContent

def pageContent: Frag = frag()
def pageSettings: PageSettings = PageSettings()

override def render: String = {
def contents: String = {
// inline css
val compStyleInlines = components.flatMap { _._2.cssDependencies.inlines }
val allStyleInlines = compStyleInlines ++ stylesInline
Expand All @@ -64,7 +32,7 @@ trait StaticPage extends Renderable with ClassPackageRelativePath with PageDepen
val allScriptURLs = compScriptUrls ++ scriptURLs

// CONTENT
val rawContent = "<!DOCTYPE html>" +
"<!DOCTYPE html>" +
html(lang := pageSettings.language)(
head(
headContent,
Expand All @@ -77,51 +45,55 @@ trait StaticPage extends Renderable with ClassPackageRelativePath with PageDepen
allScriptInlines.map(s => script(raw(s)))
)
)
}

// optionally XHTML-ify and pretty-fy
if (renderXhtml || renderPretty) {
val document = org.jsoup.Jsoup.parse(rawContent)
document
.outputSettings()
.prettyPrint(renderPretty)
if (renderXhtml) {
document
.outputSettings()
.syntax(org.jsoup.nodes.Document.OutputSettings.Syntax.xml)
// <head>
def headContent: Frag =
frag(
meta(charset := "utf-8"),
meta(
attr("http-equiv") := "X-UA-Compatible",
content := "ie=edge"
),
meta(
name := "viewport",
content := "width=device-width, initial-scale=1"
),
pageSettings.description.map { d =>
meta(name := "description", content := d)
},
tag("title")(
pageSettings.title + siteSettings.name.map(n => " - " + n).getOrElse("")
),
siteSettings.faviconNormal.map { fav =>
link(rel := "shortcut icon", href := fav, tpe := "image/x-icon")
}
document.html
} else {
rawContent
}
}
)

// <body>
def bodyContent: Frag = pageContent

def pageContent: Frag = frag()

}

/* website setttings */
case class SiteSettings(
name: Option[String] = None,
indexPage: Option[StaticPage] = None,
mainPages: List[StaticPage] = List.empty,
faviconNormal: Option[String] = None,
faviconInverted: Option[String] = None
) {
def withName(n: String) = copy(name = Some(n))
def withName(n: Option[String]) = copy(name = n)
def withIndexPage(ip: StaticPage) = copy(indexPage = Some(ip))
def withIndexPage(ip: Option[StaticPage]) = copy(indexPage = ip)
def withMainPages(mps: List[StaticPage]) = copy(mainPages = mps)
def withMainPages(mps: StaticPage*) = copy(mainPages = mps.toList)
def withFaviconNormal(fav: String) = copy(faviconNormal = Some(fav))
def withFaviconNormal(fav: Option[String]) = copy(faviconNormal = fav)
def withFaviconInverted(fav: String) = copy(faviconInverted = Some(fav))
def withFaviconInverted(fav: Option[String]) = copy(faviconInverted = fav)
}

/* page setttings */
case class PageSettings(
title: String,
label: String,
language: String,
category: Option[String],
description: Option[String]
) {

Expand All @@ -131,8 +103,6 @@ case class PageSettings(
else copy(title = t)
def withLabel(l: String) = copy(label = l)
def withLanguage(l: String) = copy(language = l)
def withCategory(c: String) = copy(category = Some(c))
def withCategory(c: Option[String]) = copy(category = c)
def withDescription(d: String) = copy(description = Some(d))
def withDescription(d: Option[String]) = copy(description = d)
}
Expand All @@ -142,5 +112,5 @@ object PageSettings {
val DefaultLanguage = "en"

def apply(title: String = DefaultTitle): PageSettings =
PageSettings(title, title, DefaultLanguage, None, None)
PageSettings(title, title, DefaultLanguage, None)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ba.sake.hepek.html.structure
package ba.sake.hepek.html

trait PageDependencies {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ba.sake.hepek.jquery

import ba.sake.hepek.html.structure._
import ba.sake.hepek.html._

trait JQueryDependencies extends PageDependencies {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ba.sake.hepek.katex

import ba.sake.hepek.html.structure._
import ba.sake.hepek.html._

trait KatexDependencies extends PageDependencies {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ba.sake.hepek.mathjax

import ba.sake.hepek.html.structure._
import ba.sake.hepek.html._

trait MathjaxDependencies extends PageDependencies {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package ba.sake.hepek.pure

import ba.sake.hepek.html.Bundle
import ba.sake.hepek.pure.component.PureComponentsBundle
import ba.sake.hepek.pure.statik.PureStaticPage

trait PureBundle extends Bundle with PureComponentsBundle {

override type StaticPage = PureStaticPage
override type HtmlPage = PurePage
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ba.sake.hepek.pure

import ba.sake.hepek.html.structure._
import ba.sake.hepek.html._

trait PureDependencies extends PageDependencies {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ba.sake.hepek.pure

import ba.sake.hepek.html.HtmlPage

trait PurePage extends HtmlPage with PureDependencies {}
7 changes: 5 additions & 2 deletions hepek-docs/src/main/scala/templates/HepekDocsPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ trait HepekDocsStaticPage extends StaticPage with AnchorjsDependencies {
override def siteSettings =
super.siteSettings
.withName(Site.name)
.withIndexPage(docs.Index)
.withMainPages(docs.QuickStart)
.withFaviconNormal(images.ico("favicon").ref)
.withFaviconInverted(images.ico("favicon-small").ref)

override def staticSiteSettings =
super.staticSiteSettings
.withIndexPage(docs.Index)
.withMainPages(docs.QuickStart)

// CSS
override def styleURLs = super.styleURLs ++ List(
styles.css("main").ref,
Expand Down
4 changes: 2 additions & 2 deletions hepek-docs/src/main/scala/utils/Imports.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package utils

import ba.sake.hepek.Resources
import ba.sake.hepek.bootstrap3.BootstrapBundle
import ba.sake.hepek.bootstrap3.statik.BootstrapStaticBundle
import ba.sake.hepek.html.component.BasicComponents
import ba.sake.hepek.prismjs.PrismCodeHighlightComponents
import scalatags.Text.all._

object Imports extends BootstrapBundle with BasicComponents {
object Imports extends BootstrapStaticBundle with BasicComponents {

object resources extends Resources {
override def siteRootPath = "docs"
Expand Down
2 changes: 1 addition & 1 deletion hepek-docs/src/main/scala/utils/Site.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package utils

import ba.sake.hepek.html.structure.blog.BlogPostPage
import ba.sake.hepek.html.statik.BlogPostPage
import docs._

object Site {
Expand Down

0 comments on commit b83c0e6

Please sign in to comment.