Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
weird bug, not sure why this didn't cause problems before
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Mar 29, 2017
1 parent 6fb67dc commit 876e165
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.github.sanity'
version '0.1.0'
version '0.1.1'

buildscript {
ext.kotlin_version = '1.1.1'
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/github/sanity/kweb/Kweb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ class Kweb(val port: Int,
for (plugin in plugins) {
applyPlugin(plugin = plugin, appliedPlugins = mutableAppliedPlugins, endHeadBuilder = endHeadBuilder, startHeadBuilder = startHeadBuilder, routeHandler = this)
}

val bootstrapHtmlTemplate = IOUtils.toString(javaClass.getResourceAsStream("kweb_bootstrap.html"), Charsets.UTF_8)

val resourceStream = Kweb::class.java.getResourceAsStream("kweb_bootstrap.html")
val bootstrapHtmlTemplate = IOUtils.toString(resourceStream, Charsets.UTF_8)
.replace("<!-- START HEADER PLACEHOLDER -->", startHeadBuilder.toString())
.replace("<!-- END HEADER PLACEHOLDER -->", endHeadBuilder.toString())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.sanity.kweb.plugins.foundation

import com.github.sanity.kweb.dom.element.Element
import com.github.sanity.kweb.dom.element.creation.ElementCreator
import com.github.sanity.kweb.plugins.KWebPlugin

/**
Expand All @@ -13,4 +15,11 @@ class FoundationPlugin : KWebPlugin() {
endHead.appendln("""<script src="https://cdn.jsdelivr.net/foundation/6.2.4/foundation.min.js"></script>""")
endHead.appendln("""<link rel="stylesheet" href="https://cdn.jsdelivr.net/foundation/6.2.4/foundation.min.css">""")
}
}
}

val <ET : Element> ElementCreator<ET>.foundation : ElementCreator<FoundationElement<ET>> get() {
require(FoundationPlugin::class)
return ElementCreator(FoundationElement<ET>(this.parent))
}

open class FoundationElement<out PARENT_TYPE : Element>(val parent : PARENT_TYPE) : Element(parent)
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,15 @@ import com.github.sanity.kweb.dom.element.Element
import com.github.sanity.kweb.dom.element.creation.ElementCreator
import com.github.sanity.kweb.dom.element.creation.tags.DivElement
import com.github.sanity.kweb.dom.element.creation.tags.div
import com.github.sanity.kweb.plugins.foundation.FoundationElement

/**
* Created by ian on 3/24/17.
*/
open class FRowElement(parent: DivElement) : DivElement(parent)

val Element.foundation : FoundationElement get() {
require(com.github.sanity.kweb.plugins.foundation.foundation::class)
return FoundationElement(this)
}

open class FoundationElement(parent : Element) : Element(parent)

open class FRowElement(parent: DivElement) : FoundationElement(parent)

fun ElementCreator<FoundationElement>.row(expanded : Boolean = false, attributes: Map<String, Any> = attr)
fun ElementCreator<FoundationElement<Element>>.row(expanded : Boolean = false, attributes: Map<String, Any> = attr)
= FRowElement(div(attributes = attributes.classes("row").classes("expanded", onlyIf = expanded)))


open class FColumnElement(parent: DivElement) : FoundationElement(parent)
open class FColumnElement(parent: DivElement) : DivElement(parent)

fun ElementCreator<FRowElement>.column(small : Int? = null, medium : Int? = null, large : Int? = null) : FColumnElement {
assert(small != null || medium != null || large != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.github.sanity.kweb.plugins.foundation.navigation

import com.github.sanity.kweb.Kweb
import com.github.sanity.kweb.dom.attributes.attr
import com.github.sanity.kweb.dom.attributes.classes
import com.github.sanity.kweb.dom.attributes.set
import com.github.sanity.kweb.dom.element.Element
import com.github.sanity.kweb.dom.element.creation.ElementCreator
import com.github.sanity.kweb.dom.element.creation.tags.*
import com.github.sanity.kweb.dom.element.modification.text
import com.github.sanity.kweb.dom.element.new
import com.github.sanity.kweb.plugins.foundation.FoundationElement
import com.github.sanity.kweb.plugins.foundation.foundation

/**
* Created by ian on 3/28/17.
*/

open class FoundationTopBarElement(parent: DivElement) : FoundationElement<DivElement>(parent)
fun ElementCreator<FoundationElement<Element>>.topBar(attributes: Map<String, Any> = attr) = FoundationTopBarElement(div(attributes.classes("top-bar")))

open class FoundationTopBarLeftElement(parent: DivElement) : FoundationElement<DivElement>(parent)
fun ElementCreator<FoundationElement<FoundationTopBarElement>>.topBarLeft(attributes: Map<String, Any> = attr) = FoundationTopBarLeftElement(div(attributes.classes("top-bar-left")))

open class FoundationMenuElement(parent: ULElement) : ULElement(parent)
fun ElementCreator<FoundationElement<Element>>.menu(dropdown : Boolean? = null, attributes: Map<String, Any> = attr)
= FoundationMenuElement(ul(attributes.classes("menu").classes("dropdown", onlyIf = dropdown ?: false).set("data-drop-down", dropdown)))

fun main(args: Array<String>) {
foundation_menu_sample()
}

private fun foundation_menu_sample() {
Kweb(port = 1234, plugins = listOf(foundation)) {
doc.body.new {
foundation.menu().new {
li().new().a(href = "#").text("Item 1")
li().new().a(href = "#").text("Item 2")
li().new().a(href = "#").text("Item 3")
li().new().a(href = "#").text("Item 4")
}
}
}
}

0 comments on commit 876e165

Please sign in to comment.