GitHub PullRequestReviewCommentEvent at 2014-05-22 00:18:04
Repository: sbt-rjs
Actor: jroper
Payload: {"comment":{"url":"https://api.github.com/repos/sbt/sbt-rjs/pulls/comments/12930226","id":12930226,"diff_hunk":"@@ -17,17 +17,68 @@ object Import {\n   object RjsKeys {\n     val appBuildProfile = TaskKey[String](\"rjs-app-build-profile\", \"The project build profile contents.\")\n     val appDir = SettingKey[File](\"rjs-app-dir\", \"The top level directory that contains your app js files.\")\n-    val buildWriter = TaskKey[String](\"rjs-build-writer\", \"The project build writer JS that is responsible for writing out source files in rjs.\")\n+    val baseUrl = TaskKey[String](\"rjs-base-url\", \"\"\"The dir relative to the assets folder where js files are housed. Will default to \"js\", \"javascripts\" or \".\" with the latter if the other two cannot be found.\"\"\")\n+    val buildProfile = TaskKey[Map[String, RjsJs.JS]](\"rjs-build-profile\", \"Build profile key -> value settings in addition to the defaults supplied by appBuildProfile. Any settings in here will also replace any defaults.\")\n+    val buildWriter = TaskKey[RjsJs.JS](\"rjs-build-writer\", \"The project build writer JS that is responsible for writing out source files in rjs.\")\n     val dir = SettingKey[File](\"rjs-dir\", \"By default, all modules are located relative to this path.\")\n-    val paths = TaskKey[Set[(String, String)]](\"rjs-paths\", \"A set of RequireJS path mappings. By default all WebJar libraries are made available from a CDN and their mappings can be found here (unless the cdn is set to None).\")\n+    val generateSourceMaps = SettingKey[Boolean](\"rjs-generate-source-maps\", \"By default, source maps are generated.\")\n+    val mainModule = SettingKey[String](\"rjs-main-module\", \"By default, 'main' is used as the module.\")\n+    val modules = SettingKey[Seq[Map[String, RjsJs.JS]]](\"rjs-modules\", \"The json array of modules.\")\n+    val optimize = SettingKey[String](\"rjs-optimize\", \"The name of the optimizer, defaults to uglify2.\")\n+    val paths = TaskKey[Map[String, String]](\"rjs-paths\", \"A set of RequireJS path mappings. By default all WebJar libraries are made available from a CDN and their mappings can be found here (unless the cdn is set to None).\")\n+    val preserveLicenseComments = SettingKey[Boolean](\"rjs-preserve-license-comments\", \"Whether to preserve comments or not. Defaults to false given source maps (see http://requirejs.org/docs/errors.html#sourcemapcomments).\")\n     val webjarCdn = SettingKey[Option[String]](\"rjs-webjar-cdn\", \"A CDN to be used for locating WebJars. By default jsdelivr is used.\")\n     val webJarModuleIds = TaskKey[Set[String]](\"rjs-webjar-module-ids\", \"A sequence of webjar module ids to be used.\")\n   }\n \n-  object RjsJson {\n-    def toJsonObj(entries: Set[(String, String)]): String = entries.map {\n-      case (key, value) => s\"\"\"\"$key\":\"$value\" \"\"\"\n-    }.mkString(\"{\", \",\", \"}\")\n+  /**\n+   * JavaScript utilities\n+   */\n+  object RjsJs {\n+\n+    import scala.language.implicitConversions\n+\n+    /**\n+     * Represents a JS value in order to force the user to be explicit about the declaration of its value in order\n+     * to avoid mistakes.\n+     * @param v the stringified representation of the value.\n+     */\n+    case class JS(v: String)\n+\n+    object JS {\n+      def apply(v: Boolean): JS = new JS(v.toString)\n+    }\n+\n+    /**\n+     * A string interpolator to conveniently quote strings and return a JS object.\n+     * From http://stackoverflow.com/questions/21086263/how-to-insert-double-quotes-into-string-with-interpolation-in-scala\n+     */\n+    implicit class `string quoter`(val sc: StringContext) {\n+      def j(args: Any*): JS = JS(\"\\\"\" + sc.s(args: _*) + \"\\\"\")\n+    }\n+\n+    /**\n+     * Convert arrays to JS. To use:\n+     * {{{Seq(j\"propValue\").toJS}}}\n+     */\n+    class JsArrayConverter(v: Seq[JS]) {\n+      def toJS: JS = JS(v.map(_.v).mkString(\"[\", \",\", \"]\"))\n+    }\n+\n+    implicit def toJsArray(v: Seq[JS]) = new JsArrayConverter(v)","path":"src/main/scala/com/typesafe/sbt/rjs/SbtRjs.scala","position":58,"original_position":58,"commit_id":"bf499750a80bb0faea4a8268758d59af26432342","original_commit_id":"bf499750a80bb0faea4a8268758d59af26432342","user":{"login":"jroper","id":105833,"avatar_url":"https://avatars.githubusercontent.com/u/105833?","gravatar_id":"dd48848f9904bdce25eb2a2824842f50","url":"https://api.github.com/users/jroper","html_url":"https://github.com/jroper","followers_url":"https://api.github.com/users/jroper/followers","following_url":"https://api.github.com/users/jroper/following{/other_user}","gists_url":"https://api.github.com/users/jroper/gists{/gist_id}","starred_url":"https://api.github.com/users/jroper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jroper/subscriptions","organizations_url":"https://api.github.com/users/jroper/orgs","repos_url":"https://api.github.com/users/jroper/repos","events_url":"https://api.github.com/users/jroper/events{/privacy}","received_events_url":"https://api.github.com/users/jroper/received_events","type":"User","site_admin":false},"body":"```scala\r\nimplicit class JsArrayConverter(...) {...}\r\n```\r\n\r\nis shorthand for defining a normal class + an implicit method - essentially the constructor of the class becomes the implicit method.","created_at":"2014-05-22T00:18:04Z","updated_at":"2014-05-22T00:18:04Z","html_url":"https://github.com/sbt/sbt-rjs/pull/6#discussion_r12930226","pull_request_url":"https://api.github.com/repos/sbt/sbt-rjs/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/sbt/sbt-rjs/pulls/comments/12930226"},"html":{"href":"https://github.com/sbt/sbt-rjs/pull/6#discussion_r12930226"},"pull_request":{"href":"https://api.github.com/repos/sbt/sbt-rjs/pulls/6"}}}}