Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

inital import

  • Loading branch information...
commit 7f6f702dc177d797ea6c419aaa956fd7e49e6b68 0 parents
@joscha authored
10 .classpath
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/scala"/>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=play-jsonminify&amp;ivyXmlPath=ivy.xml&amp;confs=*"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
3  .gitignore
@@ -0,0 +1,3 @@
+target
+project/target
+lib
25 .project
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>play-jsonminify</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.scala-ide.sdt.core.scalabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.scala-ide.sdt.core.scalanature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.apache.ivyde.eclipse.ivynature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ </natures>
+</projectDescription>
2  .settings/org.apache.ivyde.eclipse.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+org.apache.ivyde.eclipse.standaloneretrieve=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><setuplist/>
7 .settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
4 .settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <installed facet="java" version="1.6"/>
+</faceted-project>
94 .settings/org.scala-ide.sdt.core.prefs
@@ -0,0 +1,94 @@
+eclipse.preferences.version=1
+formatter.alignParameters=false
+formatter.alignSingleLineCaseStatements=false
+formatter.alignSingleLineCaseStatements.maxArrowIndent=40
+formatter.compactControlReadability=false
+formatter.compactStringConcatenation=false
+formatter.doubleIndentClassDeclaration=false
+formatter.formatXml=true
+formatter.indentLocalDefs=false
+formatter.indentPackageBlocks=true
+formatter.indentSpaces=2
+formatter.indentWithTabs=false
+formatter.multilineScaladocCommentsStartOnFirstLine=false
+formatter.placeScaladocAsterisksBeneathSecondAsterisk=false
+formatter.preserveDanglingCloseParenthesis=false
+formatter.preserveSpaceBeforeArguments=false
+formatter.rewriteArrowSymbols=false
+formatter.spaceBeforeColon=false
+formatter.spaceInsideBrackets=false
+formatter.spaceInsideParentheses=false
+formatter.spacesWithinPatternBinders=true
+organizeimports.expandcollapse=expand
+organizeimports.groups=java$scala$org$com
+organizeimports.wildcards=scalaz$scalaz.Scalaz
+syntaxColouring.bracket.bold=false
+syntaxColouring.bracket.colour=0,0,0
+syntaxColouring.bracket.italic=false
+syntaxColouring.bracket.strikethrough=false
+syntaxColouring.bracket.underline=false
+syntaxColouring.default.bold=false
+syntaxColouring.default.colour=0,0,0
+syntaxColouring.default.italic=false
+syntaxColouring.default.strikethrough=false
+syntaxColouring.default.underline=false
+syntaxColouring.keyword.bold=true
+syntaxColouring.keyword.colour=127,0,85
+syntaxColouring.keyword.italic=false
+syntaxColouring.keyword.strikethrough=false
+syntaxColouring.keyword.underline=false
+syntaxColouring.operator.bold=false
+syntaxColouring.operator.colour=0,0,0
+syntaxColouring.operator.italic=false
+syntaxColouring.operator.strikethrough=false
+syntaxColouring.operator.underline=false
+syntaxColouring.scaladoc.bold=false
+syntaxColouring.scaladoc.colour=63,95,191
+syntaxColouring.scaladoc.italic=false
+syntaxColouring.scaladoc.strikethrough=false
+syntaxColouring.scaladoc.underline=false
+syntaxColouring.singleLineComment.bold=false
+syntaxColouring.singleLineComment.colour=63,127,95
+syntaxColouring.singleLineComment.italic=false
+syntaxColouring.singleLineComment.strikethrough=false
+syntaxColouring.singleLineComment.underline=false
+syntaxColouring.string.bold=false
+syntaxColouring.string.colour=42,0,255
+syntaxColouring.string.italic=false
+syntaxColouring.string.strikethrough=false
+syntaxColouring.string.underline=false
+syntaxColouring.xml.attributeName.bold=false
+syntaxColouring.xml.attributeName.colour=127,0,127
+syntaxColouring.xml.attributeName.italic=false
+syntaxColouring.xml.attributeName.strikethrough=false
+syntaxColouring.xml.attributeName.underline=false
+syntaxColouring.xml.attributeValue.bold=false
+syntaxColouring.xml.attributeValue.colour=42,0,255
+syntaxColouring.xml.attributeValue.italic=true
+syntaxColouring.xml.attributeValue.strikethrough=false
+syntaxColouring.xml.attributeValue.underline=false
+syntaxColouring.xml.comment.bold=false
+syntaxColouring.xml.comment.colour=63,85,191
+syntaxColouring.xml.comment.italic=false
+syntaxColouring.xml.comment.strikethrough=false
+syntaxColouring.xml.comment.underline=false
+syntaxColouring.xml.equals.bold=false
+syntaxColouring.xml.equals.colour=0,0,0
+syntaxColouring.xml.equals.italic=false
+syntaxColouring.xml.equals.strikethrough=false
+syntaxColouring.xml.equals.underline=false
+syntaxColouring.xml.processingInstruction.bold=false
+syntaxColouring.xml.processingInstruction.colour=0,128,128
+syntaxColouring.xml.processingInstruction.italic=false
+syntaxColouring.xml.processingInstruction.strikethrough=false
+syntaxColouring.xml.processingInstruction.underline=false
+syntaxColouring.xml.tagDelimiter.bold=false
+syntaxColouring.xml.tagDelimiter.colour=0,128,128
+syntaxColouring.xml.tagDelimiter.italic=false
+syntaxColouring.xml.tagDelimiter.strikethrough=false
+syntaxColouring.xml.tagDelimiter.underline=false
+syntaxColouring.xml.tagName.bold=false
+syntaxColouring.xml.tagName.colour=63,127,127
+syntaxColouring.xml.tagName.italic=false
+syntaxColouring.xml.tagName.strikethrough=false
+syntaxColouring.xml.tagName.underline=false
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (C) 2012 Joscha Feth
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
71 README.md
@@ -0,0 +1,71 @@
+# play-jsonminify - JSON minification compiler for Play 2.0
+
+## About
+
+This plugin is initially based on [Ray][] and [play-stylus][].
+
+play-jsonminify is a [JSON][] 'compiled asset plugin' for Play 2.0 based on [JSON.simple][].
+It is similar to the other built-in compilers. JSON files placed under
+`app/assets` will be transformed into a pretty-printed and a compressed version.
+
+For example, JSON in `app/assets/javascripts/xyz.json`
+
+![](http://f.cl.ly/items/2Q2v3A1a451c3V1z1p0f/raw_json.png)
+
+will be automatically compiled into a pretty-printed version, when requested via
+`public/javascripts/xyz.json`:
+
+![](http://f.cl.ly/items/0M29060g0u3M2v1L0Z2H/pretty_json.png)
+
+and a compressed version when requested via `public/javascripts/xyz.min.json`:
+
+![](http://f.cl.ly/items/3808183U3F1F0C0c243d/compressed_json.png)
+
+Compile time errors (such as unclosed brackets or unexpected characters) will cause a nice
+Play error page:
+
+![](http://f.cl.ly/items/0V2Z0i0A0Z0y181K3j1g/play-jsonminify.png)
+
+As you can see on line 3, leaving out commas is not necessarily breaking the compiler.
+As well as unnecessary trailing commas will be stripped automatically.
+(thanks to [JSON.simple][]).
+
+
+## Installation
+
+First you must publish the plugin to your Play 2.0 repository. You
+will have to specify your top level play directory and the version:
+
+ sbt -Dplay.path=../play-2.0.1 -Dplay.version=2.0.1 publish
+
+Then add the plugin to your application's `project/plugins.sbt`:
+
+ addSbtPlugin("com.feth" % "play-jsonminify" % "0.1.0")
+
+This adds the JSON asset compiler to your Play project. `*.json` files beneath `app/assets`
+will then be automatically compiled to `*.json` and `*.min.json` files. Files starting with
+`_`-character will be left out from compilation as per Play convention.
+
+### Settings
+
+To override the default settings, you can add the following lines to the `settings` call
+in your `Build.scala` (examples):
+
+this would for example also process JSON files starting with the `_`-character:
+
+ jsonminifyEntryPoints <<= (sourceDirectory in Compile)(base => base / "assets" ** "*.json")
+
+## Versions
+
+* *0.1.0* [2012-05-18] Initial release
+
+## License
+
+Copyright (c) 2012 Joscha Feth
+
+MIT-style license, see details from LICENSE file.
+
+[Ray]: http://github.com/pufuwozu/ray
+[play-stylus]: http://raw.github.com/knuton/play-stylus
+[JSON]: http://www.json.org
+[JSON.simple]: http://code.google.com/p/json-simple/
1  _0112_20.sh
@@ -0,0 +1 @@
+sbt -Dplay.path=~/play-2.0 -Dplay.version=2.0 publish
1  _0113_21.sh
@@ -0,0 +1 @@
+sbt0113 -Dplay.path=../play20 -Dplay.version=2.1-SNAPSHOT publish
BIN  bin/com/feth/play/plugin/jsonminify/IndentationWriter.class
Binary file not shown
28 build.sbt
@@ -0,0 +1,28 @@
+sbtPlugin := true
+
+name := projectId
+
+organization := "com.feth"
+
+version := "0.1.0"
+
+description := "SBT plugin for handling JSON minification in Play 2.x"
+
+resolvers += playRepository
+
+resolvers += typesafeRepository
+
+addSbtPlugin("play" % "sbt-plugin" % playVersion)
+
+libraryDependencies += "com.googlecode.json-simple" % "json-simple" % "1.1.1"
+
+publishTo := Some(playRepository)
+
+publishMavenStyle := false
+
+
+//for upload to github
+
+//publishTo := Some(Resolver.file("Github Pages", Path.userHome / "github.com" / "repo" asFile))
+
+//publishMavenStyle := true
12 ivy.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<ivy-module version="2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
+ <info organisation="com.feth" module="play-jsonminify" status="integration">
+ </info>
+ <dependencies>
+ <dependency org="com.googlecode.json-simple" name="json-simple"
+ rev="1.1.1">
+ </dependency>
+ </dependencies>
+</ivy-module>
13 project/Build.scala
@@ -0,0 +1,13 @@
+import sbt._
+import Keys._
+
+object PluginBuild extends Build {
+ val playPath = Option(System.getProperty("play.path")).getOrElse("../play-2.0.1")
+ val playVersion = Option(System.getProperty("play.version")).getOrElse("2.0.1")
+
+ val playRepository = Resolver.file("Local Play Repository", file(new File(playPath, "repository/local").getPath))(Resolver.ivyStylePatterns)
+
+ val typesafeRepository = Resolver.url("Typesafe repository", url("http://repo.typesafe.com/typesafe/releases/"))(Resolver.ivyStylePatterns)
+ val projectId = "play-jsonminify"
+ lazy val root = Project(id = projectId, base = file("."))
+}
42 src/main/java/com/feth/play/plugin/jsonminify/IndentationWriter.java
@@ -0,0 +1,42 @@
+package com.feth.play.plugin.jsonminify;
+
+import java.io.StringWriter;
+
+public class IndentationWriter extends StringWriter {
+
+ /**
+ * The indentation level we are currently in
+ */
+ int level = 0;
+
+ /**
+ * The newline character
+ */
+ final static char NEWLINE = '\n';
+
+ @Override
+ public void write(int c) {
+ switch (c) {
+ case '{':
+ case '[':
+ level++;
+ case ',':
+ super.write(c);
+ super.write(NEWLINE);
+ indent();
+ break;
+ case '}':
+ case ']':
+ super.write(NEWLINE);
+ level--;
+ indent();
+ default:
+ super.write(c);
+ break;
+ }
+ }
+
+ private void indent() {
+ super.write(String.format("%" + (level * 4) + "s", ""));
+ }
+}
47 src/main/scala/JsonCompiler.scala
@@ -0,0 +1,47 @@
+package com.feth.play.plugin.jsonminify
+
+import sbt.PlayExceptions.AssetCompilationException
+import org.json.simple.JSONValue
+import org.json.simple.parser.JSONParser
+import org.json.simple.parser.ParseException
+import scala.io.Source
+
+import java.io.File
+
+object StylusCompiler {
+
+ def compile(file: File, options: Seq[String]): (String, Option[String], Seq[File]) = {
+ val data = Source.fromFile(file) mkString
+
+ var pretty: String = null
+ var minified: String = null
+
+ try {
+ val p = new JSONParser()
+ val o = p.parse(data);
+ minified = o.toString()
+ val w = new IndentationWriter()
+
+ JSONValue.writeJSONString(o, w);
+ pretty = w.getBuffer().toString()
+ } catch {
+ case pe: ParseException => {
+ val lines = data.substring(0, pe.getPosition()).split("\\r?\\n")
+ val line = lines.length
+ val pos = lines(line - 1).length
+ throw AssetCompilationException(Some(file),
+ "JSON minifier: "+pe.toString() + " (counted from begin of file)",
+ line,
+ pos)
+ }
+ case e: Exception => {
+ throw AssetCompilationException(Some(file),
+ e.getMessage(),
+ 0,
+ 0)
+ }
+ }
+
+ (pretty, Option(minified), Seq(file))
+ }
+}
28 src/main/scala/JsonPlugin.scala
@@ -0,0 +1,28 @@
+package com.feth.play.plugin.jsonminify
+
+import sbt._
+import sbt.Keys._
+import PlayProject._
+
+// initially based on https://github.com/pufuwozu/ray
+// and https://raw.github.com/knuton/play-stylus
+object JsonPlugin extends Plugin {
+ val id = "play-jsonminify"
+ val jsonminifyEntryPoints = SettingKey[PathFinder](id+"-entry-points")
+ val jsonminifyOptions = SettingKey[Seq[String]](id+"-options")
+
+ val JsonWatcher = PlayProject.AssetsCompiler(id,
+ (_ ** "*.json"),
+ jsonminifyEntryPoints in Compile,
+ { (name, min) => name.replace(".json", if (min) ".min.json" else ".json") },
+ { StylusCompiler.compile _ },
+ jsonminifyOptions in Compile
+ )
+
+ override val settings = Seq(
+ jsonminifyEntryPoints <<= (sourceDirectory in Compile).apply(base => ((base / "assets" ** "*.json") --- base / "assets" ** "_*")),
+ jsonminifyOptions := Seq.empty[String],
+ resourceGenerators in Compile <+= JsonWatcher
+ )
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.