Foundation classes for text / jsdom backends. Base definitions (of pure-* classes)
authorTomas Zeman <tzeman@volny.cz>
Thu, 14 Dec 2017 12:17:36 +0100
changeset 3 dbc25b272bdc
parent 2 d75548c8d394
child 4 84cc462b85d4
Foundation classes for text / jsdom backends. Base definitions (of pure-* classes)
js/src/main/scala/purecss/jsdom/PureAlert.scala
js/src/main/scala/purecss/jsdom/PureCss.scala
shared/src/main/scala/purecss/generic/PureAlert.scala
shared/src/main/scala/purecss/generic/PureCls.scala
shared/src/main/scala/purecss/generic/PureCssGeneric.scala
shared/src/main/scala/purecss/text/PureAlert.scala
shared/src/main/scala/purecss/text/PureCss.scala
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/js/src/main/scala/purecss/jsdom/PureAlert.scala	Thu Dec 14 12:17:36 2017 +0100
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2017 Tomas Zeman <tzeman@volny.cz>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package purecss.jsdom
+
+object PureAlert extends purecss.generic.PureAlert(PureCss)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/js/src/main/scala/purecss/jsdom/PureCss.scala	Thu Dec 14 12:17:36 2017 +0100
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017 Tomas Zeman <tzeman@volny.cz>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package purecss.jsdom
+
+import purecss.generic.PureCssGeneric
+
+object PureCss extends PureCssGeneric(scalatags.JsDom)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shared/src/main/scala/purecss/generic/PureAlert.scala	Thu Dec 14 12:17:36 2017 +0100
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017 Tomas Zeman <tzeman@volny.cz>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package purecss.generic
+
+abstract class PureAlert[Builder, Output <: FragT, FragT](
+  val pureCss: PureCssGeneric[Builder, Output, FragT]) {
+
+  type C = PureCls[Builder, Output, FragT]
+
+  val primary: C = pureCss.pure_alert
+
+  sealed abstract class Alert(val secondary: C) {
+    def toCls: C = PureCls(primary.css, secondary :: Nil)
+  }
+
+  case object Error extends Alert(pureCss.pure_alert_error)
+  case object Warning extends Alert(pureCss.pure_alert_warning)
+  case object Success extends Alert(pureCss.pure_alert_success)
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shared/src/main/scala/purecss/generic/PureCls.scala	Thu Dec 14 12:17:36 2017 +0100
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017 Tomas Zeman <tzeman@volny.cz>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package purecss.generic
+
+import scalatags.generic.{Bundle, Modifier}
+
+case class PureCls[Builder, Output <: FragT, FragT](
+  css: String,
+  chain: List[PureCls[Builder, Output, FragT]] = Nil
+) {
+
+  type Self = PureCls[Builder, Output, FragT]
+
+  def & (next: Self): Self = copy(chain = next :: chain)
+  def & (next: String): Self = this & PureCls[Builder, Output, FragT](next)
+
+  def apply()(implicit bundle: Bundle[Builder, Output, FragT]):
+  Modifier[Builder] = {
+    import bundle.all._
+    cls:=((this :: chain.reverse) map(_.css) mkString " ")
+  }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shared/src/main/scala/purecss/generic/PureCssGeneric.scala	Thu Dec 14 12:17:36 2017 +0100
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2017 Tomas Zeman <tzeman@volny.cz>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package purecss.generic
+
+import scala.language.implicitConversions
+import scalatags.generic.Bundle
+
+class PureCssGeneric[Builder, Output <: FragT, FragT](
+  val bun: Bundle[Builder, Output, FragT]) {
+
+  import bun.all._
+
+  type C = PureCls[Builder, Output, FragT]
+
+  implicit val bundle: Bundle[Builder, Output, FragT] = bun
+
+  implicit def cls2mod(v: C): Modifier = v()
+  //implicit def alert2cls(a: PureAlert.Alert): PureCls = a.toCls
+  //implicit def alert2mod(a: PureAlert.Alert): Modifier = a.toCls.apply()
+
+  private def pc(c: String): C = PureCls(c)
+
+  // grid
+  val pure_g: C = pc("pure-g")
+  val pure_u_1: C = pc("pure-u-1")
+
+  // 5ths-based
+  val pure_u_1_5: C = pc("pure-u-1-5")
+  val pure_u_2_5: C = pc("pure-u-2-5")
+  val pure_u_3_5: C = pc("pure-u-3-5")
+  val pure_u_4_5: C = pc("pure-u-4-5")
+
+  // 24ths-based
+  val pure_u_1_24: C = pc("pure-u-1-24")
+  val pure_u_1_12: C = pc("pure-u-1-12")
+  val pure_u_2_24: C = pc("pure-u-2-24")
+  val pure_u_3_24: C = pc("pure-u-3-24")
+  val pure_u_1_8: C = pc("pure-u-1-8")
+  val pure_u_4_24: C = pc("pure-u-4-24")
+  val pure_u_1_6: C = pc("pure-u-1-6")
+  val pure_u_5_24: C = pc("pure-u-5-24")
+  val pure_u_1_4: C = pc("pure-u-1-4")
+  val pure_u_6_24: C = pc("pure-u-6-24")
+  val pure_u_7_24: C = pc("pure-u-7-24")
+  val pure_u_1_3: C = pc("pure-u-1-3")
+  val pure_u_8_24: C = pc("pure-u-8-24")
+  val pure_u_3_8: C = pc("pure-u-3-8")
+  val pure_u_9_24: C = pc("pure-u-9-24")
+  val pure_u_5_12: C = pc("pure-u-5-12")
+  val pure_u_10_24: C = pc("pure-u-10-24")
+  val pure_u_11_24: C = pc("pure-u-11-24")
+  val pure_u_1_2: C = pc("pure-u-1-2")
+  val pure_u_13_24: C = pc("pure-u-13-24")
+  val pure_u_7_12: C = pc("pure-u-7-12")
+  val pure_u_14_24: C = pc("pure-u-14-24")
+  val pure_u_5_8: C = pc("pure-u-5-8")
+  val pure_u_15_24: C = pc("pure-u-15-24")
+  val pure_u_2_3: C = pc("pure-u-2-3")
+  val pure_u_16_24: C = pc("pure-u-16-24")
+  val pure_u_17_24: C = pc("pure-u-17-24")
+  val pure_u_3_4: C = pc("pure-u-3-4")
+  val pure_u_18_24: C = pc("pure-u-18-24")
+  val pure_u_19_24: C = pc("pure-u-19-24")
+  val pure_u_5_6: C = pc("pure-u-5-6")
+  val pure_u_20_24: C = pc("pure-u-20-24")
+  val pure_u_7_8: C = pc("pure-u-7-8")
+  val pure_u_21_24: C = pc("pure-u-21-24")
+  val pure_u_11_12: C = pc("pure-u-11-12")
+  val pure_u_22_24: C = pc("pure-u-22-24")
+  val pure_u_23_24: C = pc("pure-u-23-24")
+
+  // generic
+  val pull_right: C = pc("pull-right")
+
+  // tables
+  val pure_table: C = pc("pure-table")
+  val pure_table_bordered: C = pc("pure-table-bordered")
+  val pure_table_horizontal: C = pc("pure-table-horizontal")
+  val pure_table_striped: C = pc("pure-table-striped")
+
+  // alerts
+  val pure_alert: C = pc("pure-alert")
+  val pure_alert_error: C = pc("pure-alert-error")
+  val pure_alert_warning: C = pc("pure-alert-warning")
+  val pure_alert_success: C = pc("pure-alert-success")
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shared/src/main/scala/purecss/text/PureAlert.scala	Thu Dec 14 12:17:36 2017 +0100
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2017 Tomas Zeman <tzeman@volny.cz>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package purecss.text
+
+object PureAlert extends purecss.generic.PureAlert(PureCss)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shared/src/main/scala/purecss/text/PureCss.scala	Thu Dec 14 12:17:36 2017 +0100
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017 Tomas Zeman <tzeman@volny.cz>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package purecss.text
+
+import purecss.generic.PureCssGeneric
+
+object PureCss extends PureCssGeneric(scalatags.Text)