From 4fc612b38583d167b381a4c1977b6fbbbe3073e0 Mon Sep 17 00:00:00 2001 From: Franklin Hu Date: Tue, 14 Aug 2012 09:58:00 -0700 Subject: [PATCH] Improve local js,css development Making changes to js,css can be painful with a packaged jar since a compilation is needed to repackage any new changes. This change allows for the paths to the static resources to be configured at runtime. While developing locally, you can then set the prefix to bypass the jar and the browser will resolve it on your local filesystem. Author: @franklinhu Fixes #112 URL: https://github.com/twitter/zipkin/pull/112 --- zipkin-finatra/config/web-dev.scala | 17 ++++++- .../templates/layouts/application.mustache | 36 +++---------- .../com/twitter/zipkin/config/CssConfig.scala | 31 ++++++++++++ .../com/twitter/zipkin/config/JsConfig.scala | 50 +++++++++++++++++++ .../zipkin/config/StaticResourceConfig.scala | 31 ++++++++++++ .../zipkin/config/ZipkinWebConfig.scala | 3 ++ .../scala/com/twitter/zipkin/web/App.scala | 2 + 7 files changed, 139 insertions(+), 31 deletions(-) create mode 100644 zipkin-finatra/src/main/scala/com/twitter/zipkin/config/CssConfig.scala create mode 100644 zipkin-finatra/src/main/scala/com/twitter/zipkin/config/JsConfig.scala create mode 100644 zipkin-finatra/src/main/scala/com/twitter/zipkin/config/StaticResourceConfig.scala diff --git a/zipkin-finatra/config/web-dev.scala b/zipkin-finatra/config/web-dev.scala index 054b123356a..b0df47fee8b 100644 --- a/zipkin-finatra/config/web-dev.scala +++ b/zipkin-finatra/config/web-dev.scala @@ -14,13 +14,28 @@ * limitations under the License. */ -import com.twitter.zipkin.config.ZipkinWebConfig +import com.twitter.zipkin.config.{CssConfig, JsConfig, ZipkinWebConfig} import com.twitter.zipkin.config.zookeeper.ZooKeeperConfig import java.net.InetSocketAddress new ZipkinWebConfig { rootUrl = "http://localhost:" + serverPort + "/" + /** + * Making changes to js/css can be painful with a packaged jar since a compilation is needed to + * repackage any new changes. `resourcePathPrefix` can be hacked to point to the directory + * on your local file system so the browser resolves it outside of the jar. Example: + * + * `val resourcePathPrefix = "file:///Users/username/path/to/zipkin-finatra/src/main/resources/public"` + */ + val resourcePathPrefix = "/public" + jsConfig = new JsConfig { + override val pathPrefix = resourcePathPrefix + } + cssConfig = new CssConfig { + override val pathPrefix = resourcePathPrefix + } + def zkConfig = new ZooKeeperConfig { servers = List("localhost:3003") } diff --git a/zipkin-finatra/src/main/resources/templates/layouts/application.mustache b/zipkin-finatra/src/main/resources/templates/layouts/application.mustache index d52094f9069..b8ec992a244 100644 --- a/zipkin-finatra/src/main/resources/templates/layouts/application.mustache +++ b/zipkin-finatra/src/main/resources/templates/layouts/application.mustache @@ -1,38 +1,14 @@ - - - - - + {{#stylesheets}} + + {{/stylesheets}} - - + {{#javascripts}} + + {{/javascripts}} - - - - - - - - - - - - - - - - - - - - - - - diff --git a/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/CssConfig.scala b/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/CssConfig.scala new file mode 100644 index 00000000000..4ae748f39c6 --- /dev/null +++ b/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/CssConfig.scala @@ -0,0 +1,31 @@ +/* +* Copyright 2012 Twitter Inc. +* +* 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 com.twitter.zipkin.config + +class CssConfig extends StaticResourceConfig { + val resourceType = "css" + + val remoteResources = Seq( + "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/ui-lightness/jquery-ui.css" + ) + + val localResources = Seq( + "bootstrap.css", + "bootstrap-responsive.css", + "datepicker.css", + "application.css" + ) +} diff --git a/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/JsConfig.scala b/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/JsConfig.scala new file mode 100644 index 00000000000..0e657039514 --- /dev/null +++ b/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/JsConfig.scala @@ -0,0 +1,50 @@ +/* +* Copyright 2012 Twitter Inc. +* +* 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 com.twitter.zipkin.config + +class JsConfig extends StaticResourceConfig { + val resourceType = "js" + + lazy val remoteResources = Seq( + "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js", + "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js" + ) + + lazy val localResources = Seq( + "bootstrap.js", + "datepicker.js", + "d3-2.9.1.js", + "hogan-2.0.0.js", + + "zipkin.js", + "zipkin-node.js", + "zipkin-span.js", + "zipkin-tree.js", + "zipkin-annotation.js", + "zipkin-config.js", + "zipkin-filter-span.js", + "zipkin-kv-annotation.js", + "zipkin-lazy-tree.js", + "zipkin-onebox.js", + "zipkin-trace-dependency.js", + "zipkin-trace-summary.js", + + "application.js", + "application-index.js", + "application-show.js", + "application-static.js" + ) +} diff --git a/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/StaticResourceConfig.scala b/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/StaticResourceConfig.scala new file mode 100644 index 00000000000..7183cd74904 --- /dev/null +++ b/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/StaticResourceConfig.scala @@ -0,0 +1,31 @@ +/* +* Copyright 2012 Twitter Inc. +* +* 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 com.twitter.zipkin.config + +trait StaticResourceConfig { + val pathPrefix: String = "/public" + + val resourceType: String + + val remoteResources: Seq[String] + + val localResources: Seq[String] + + lazy val resources = remoteResources ++ + localResources.map { r => + "%s/%s/%s".format(pathPrefix, resourceType, r) + } +} diff --git a/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/ZipkinWebConfig.scala b/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/ZipkinWebConfig.scala index c537fa80332..c0e3ff92d89 100644 --- a/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/ZipkinWebConfig.scala +++ b/zipkin-finatra/src/main/scala/com/twitter/zipkin/config/ZipkinWebConfig.scala @@ -29,6 +29,9 @@ trait ZipkinWebConfig extends ZipkinConfig[ZipkinWeb] { "templates" -> "text/plain" ) + var jsConfig = new JsConfig + var cssConfig = new CssConfig + def zkConfig: ZooKeeperConfig def zkClientConfig = new ZooKeeperClientConfig { diff --git a/zipkin-finatra/src/main/scala/com/twitter/zipkin/web/App.scala b/zipkin-finatra/src/main/scala/com/twitter/zipkin/web/App.scala index ad2cfb41257..31dd420bfe7 100644 --- a/zipkin-finatra/src/main/scala/com/twitter/zipkin/web/App.scala +++ b/zipkin-finatra/src/main/scala/com/twitter/zipkin/web/App.scala @@ -262,6 +262,8 @@ class App(config: ZipkinWebConfig, client: gen.ZipkinQuery.FinagledClient) exten val template = "templates/layouts/application.mustache" val rootUrl = config.rootUrl val innerView: View = v + val javascripts = config.jsConfig.resources + val stylesheets = config.cssConfig.resources lazy val body = innerView.render } }