-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/custom colors in interactions #420
base: develop
Are you sure you want to change the base?
Changes from all commits
963d70f
22acdea
483d188
a537998
c01e263
5756494
cd49b58
90eb6e2
fa33240
9c728a3
883ef03
25725e5
769eea5
089ea95
e2f280c
5957b6d
b28b1da
fed3625
fb95d67
2d69b53
88591b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
background-color: red; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package org.corespring.container.client | ||
|
||
import javax.xml.bind.DatatypeConverter | ||
|
||
import org.corespring.container.client.controllers.DefaultComponentSets | ||
import org.corespring.container.client.processing.{ CssMinifier, Gzipper, JsMinifier } | ||
import org.corespring.container.logging.ContainerLogger | ||
import play.api.Configuration | ||
import play.api.http.ContentTypes | ||
import play.api.libs.json.{ JsObject, Json } | ||
import play.api.mvc.{ Action, EssentialAction, RequestHeader, Result } | ||
|
||
trait CompressedAndMinifiedComponentSets extends DefaultComponentSets | ||
|
@@ -43,13 +46,32 @@ trait CompressedAndMinifiedComponentSets extends DefaultComponentSets | |
} | ||
} | ||
|
||
private def tokenToJson(token: String): JsObject = { | ||
val decodedColorString = DatatypeConverter.parseBase64Binary(token).map(_.toChar).mkString | ||
try { | ||
Json.parse(decodedColorString).as[JsObject] | ||
} catch { | ||
case _ => Json.obj() | ||
} | ||
} | ||
|
||
override def singleResource[A >: EssentialAction](context: String, componentType: String, suffix: String): A = Action { implicit request => | ||
val (body, ct) = generate(context, allComponents.find(_.matchesType(componentType)).toSeq, suffix) | ||
val resourceToken = request.queryString.get("resourceToken") | ||
val paramsJson = resourceToken match { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplication? line 65? |
||
case Some(token) if (token.length > 0) => tokenToJson(token(0)) | ||
case _ => Json.obj() | ||
} | ||
val (body, ct) = generate(context, allComponents.find(_.matchesType(componentType)).toSeq, suffix, paramsJson) | ||
process(body, ct) | ||
} | ||
|
||
override def resource[A >: EssentialAction](context: String, directive: String, suffix: String) = Action { implicit request => | ||
val (body, ct) = generateBodyAndContentType(context, directive, suffix) | ||
val resourceToken = request.queryString.get("resourceToken") | ||
val paramsJson = resourceToken match { | ||
case Some(token) if (token.length > 0) => tokenToJson(token(0)) | ||
case _ => Json.obj() | ||
} | ||
val (body, ct) = generateBodyAndContentType(context, directive, suffix, paramsJson) | ||
process(body, ct) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ import org.corespring.container.client.views.txt.js.{ ComponentServerWrapper, Co | |
import org.corespring.container.components.model._ | ||
import org.corespring.container.components.model.dependencies.ComponentTypeFilter | ||
import org.corespring.container.components.model.packaging.ClientSideDependency | ||
import play.api.libs.json.JsObject | ||
import play.api.libs.json.{ Json, JsValue, JsObject } | ||
import org.apache.commons.io.IOUtils | ||
|
||
object SourceGenerator { | ||
object Keys { | ||
|
@@ -26,6 +27,8 @@ trait SourceGenerator | |
|
||
def css(components: Seq[Component]): String | ||
|
||
def less(components: Seq[Component], customColors: JsObject = Json.obj()): String | ||
|
||
protected def wrapComponent(moduleName: String, directiveName: String, src: String) = { | ||
ComponentWrapper(moduleName, directiveName, src).toString | ||
} | ||
|
@@ -119,6 +122,30 @@ abstract class BaseGenerator | |
""".stripMargin | ||
} | ||
|
||
override def less(components: Seq[Component], customColors: JsObject = Json.obj()): String = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it alot of this is static content - try and isolate it and generate it once There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you mean? |
||
val inputStream = this.getClass().getResourceAsStream("/public/components-common.less") | ||
val commonLessSource = IOUtils.toString(inputStream) | ||
inputStream.close | ||
val commonLess = commonLessSource.mkString | ||
val (libraries, uiComps, layoutComps, widgets) = splitComponents(components) | ||
val uiLess = uiComps.map(_.client.less.getOrElse("")).mkString("\n") | ||
val widgetLess = widgets.map(_.client.less.getOrElse("")).mkString("\n") | ||
val layoutLess = layoutComps.map(_.less.getOrElse("")).mkString("\n") | ||
val libraryLess = libraries.map(_.less.getOrElse("")).mkString("\n") | ||
val dynamicColors = customColors.asOpt[Map[String, String]] match { | ||
case Some(cols) => cols.map { case (a, b) => s"@$a: $b;" }.mkString("\n") | ||
case _ => "" | ||
} | ||
s""" | ||
|$commonLess | ||
|$dynamicColors | ||
|$uiLess | ||
|$widgetLess | ||
|$layoutLess | ||
|$libraryLess | ||
""".stripMargin | ||
} | ||
|
||
override def js(components: Seq[Component]): String = { | ||
val (libs, uiComps, layoutComps, widgets) = splitComponents(components) | ||
val uiJs = uiComps.map(interactionToJs).mkString("\n") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplication w/ line 69?