diff --git a/build.gradle b/build.gradle index fa96124391..049ce76023 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'com.github.sanity' -version '0.1.0' +version '0.1.1' buildscript { ext.kotlin_version = '1.1.1' diff --git a/src/main/kotlin/com/github/sanity/kweb/Kweb.kt b/src/main/kotlin/com/github/sanity/kweb/Kweb.kt index 4f4fa36bce..94b9980f48 100644 --- a/src/main/kotlin/com/github/sanity/kweb/Kweb.kt +++ b/src/main/kotlin/com/github/sanity/kweb/Kweb.kt @@ -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("", startHeadBuilder.toString()) .replace("", endHeadBuilder.toString()) diff --git a/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/FoundationPlugin.kt b/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/FoundationPlugin.kt index d14c5619cc..f53813d1aa 100644 --- a/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/FoundationPlugin.kt +++ b/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/FoundationPlugin.kt @@ -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 /** @@ -13,4 +15,11 @@ class FoundationPlugin : KWebPlugin() { endHead.appendln("""""") endHead.appendln("""""") } -} \ No newline at end of file +} + +val ElementCreator.foundation : ElementCreator> get() { + require(FoundationPlugin::class) + return ElementCreator(FoundationElement(this.parent)) +} + +open class FoundationElement(val parent : PARENT_TYPE) : Element(parent) \ No newline at end of file diff --git a/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/grid/grid.kt b/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/grid/grid.kt index 298a9de55a..1360f641bf 100644 --- a/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/grid/grid.kt +++ b/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/grid/grid.kt @@ -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.row(expanded : Boolean = false, attributes: Map = attr) +fun ElementCreator>.row(expanded : Boolean = false, attributes: Map = 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.column(small : Int? = null, medium : Int? = null, large : Int? = null) : FColumnElement { assert(small != null || medium != null || large != null) diff --git a/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/navigation/menu.kt b/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/navigation/menu.kt new file mode 100644 index 0000000000..ba42c8ac51 --- /dev/null +++ b/src/main/kotlin/com/github/sanity/kweb/plugins/foundation/navigation/menu.kt @@ -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(parent) +fun ElementCreator>.topBar(attributes: Map = attr) = FoundationTopBarElement(div(attributes.classes("top-bar"))) + +open class FoundationTopBarLeftElement(parent: DivElement) : FoundationElement(parent) +fun ElementCreator>.topBarLeft(attributes: Map = attr) = FoundationTopBarLeftElement(div(attributes.classes("top-bar-left"))) + +open class FoundationMenuElement(parent: ULElement) : ULElement(parent) +fun ElementCreator>.menu(dropdown : Boolean? = null, attributes: Map = attr) + = FoundationMenuElement(ul(attributes.classes("menu").classes("dropdown", onlyIf = dropdown ?: false).set("data-drop-down", dropdown))) + +fun main(args: Array) { + 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") + } + } + } +} \ No newline at end of file