Skip to content

Commit c21fc49

Browse files
committed
Merge pull request #8 from UdashFramework/example
Example application based on this wrapper; Closes #7
2 parents 614e1c6 + 95a5cbd commit c21fc49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1185
-67
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
language: scala
22

33
scala:
4-
- 2.11.7
4+
- 2.11.8
55

66
script:
7-
- sbt ++$TRAVIS_SCALA_VERSION test
7+
- sbt ++$TRAVIS_SCALA_VERSION test
8+
- cd example && sbt ++$TRAVIS_SCALA_VERSION compile

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name := "udash-jquery"
22

3-
version := "1.0.0-SNAPSHOT"
3+
version := "1.0.0-rc.2"
44
organization := "io.udash"
5-
scalaVersion := "2.11.7"
5+
scalaVersion := "2.11.8"
66
scalacOptions in ThisBuild ++= Seq(
77
"-feature",
88
"-deprecation",
@@ -22,7 +22,7 @@ libraryDependencies ++= Seq(
2222
)
2323

2424
jsDependencies +=
25-
"org.webjars" % "jquery" % "2.2.0" / "2.2.0/jquery.js" minified "2.2.0/jquery.min.js"
25+
"org.webjars" % "jquery" % "2.2.3" / "2.2.3/jquery.js" minified "2.2.3/jquery.min.js"
2626

2727
requiresDOM in Test := true
2828
persistLauncher in Test := false

example/.gitignore

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Eclipse template
3+
*.pydevproject
4+
.metadata
5+
.gradle
6+
bin/
7+
tmp/
8+
*.tmp
9+
*.bak
10+
*.swp
11+
*~.nib
12+
local.properties
13+
.settings/
14+
.loadpath
15+
16+
# Eclipse Core
17+
.project
18+
19+
# External tool builders
20+
.externalToolBuilders/
21+
22+
# Locally stored "Eclipse launch configurations"
23+
*.launch
24+
25+
# CDT-specific
26+
.cproject
27+
28+
# JDT-specific (Eclipse Java Development Tools)
29+
.classpath
30+
31+
# Java annotation processor (APT)
32+
.factorypath
33+
34+
# PDT-specific
35+
.buildpath
36+
37+
# sbteclipse plugin
38+
.target
39+
40+
# TeXlipse plugin
41+
.texlipse
42+
### Maven template
43+
target/
44+
pom.xml.tag
45+
pom.xml.releaseBackup
46+
pom.xml.versionsBackup
47+
pom.xml.next
48+
release.properties
49+
dependency-reduced-pom.xml
50+
buildNumber.properties
51+
.mvn/timing.properties
52+
### JetBrains template
53+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
54+
55+
*.iml
56+
57+
## Directory-based project format:
58+
.idea/
59+
# if you remove the above rule, at least ignore the following:
60+
61+
# User-specific stuff:
62+
# .idea/workspace.xml
63+
# .idea/tasks.xml
64+
# .idea/dictionaries
65+
66+
# Sensitive or high-churn files:
67+
# .idea/dataSources.ids
68+
# .idea/dataSources.xml
69+
# .idea/sqlDataSources.xml
70+
# .idea/dynamic.xml
71+
# .idea/uiDesigner.xml
72+
73+
# Gradle:
74+
# .idea/gradle.xml
75+
# .idea/libraries
76+
77+
# Mongo Explorer plugin:
78+
# .idea/mongoSettings.xml
79+
80+
## File-based project format:
81+
*.ipr
82+
*.iws
83+
84+
## Plugin-specific files:
85+
86+
# IntelliJ
87+
/out/
88+
89+
# mpeltonen/sbt-idea plugin
90+
.idea_modules/
91+
92+
# JIRA plugin
93+
atlassian-ide-plugin.xml
94+
95+
# Crashlytics plugin (for Android Studio and IntelliJ)
96+
com_crashlytics_export_strings.xml
97+
crashlytics.properties
98+
crashlytics-build.properties
99+
### Java template
100+
*.class
101+
102+
# Mobile Tools for Java (J2ME)
103+
.mtj.tmp/
104+
105+
# Package Files #
106+
*.jar
107+
*.war
108+
*.ear
109+
110+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
111+
hs_err_pid*
112+
### Scala template
113+
*.class
114+
*.log
115+
116+
# sbt specific
117+
.cache
118+
.history
119+
.lib/
120+
dist/*
121+
target/
122+
lib_managed/
123+
src_managed/
124+
project/boot/
125+
project/plugins/project/
126+
127+
# Scala-IDE specific
128+
.scala_dependencies
129+
.worksheet
130+
131+
132+
generated/

example/build.sbt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name := "jquery-demo"
2+
3+
version in ThisBuild := "1.0.0-SNAPSHOT"
4+
scalaVersion in ThisBuild := "2.11.8"
5+
organization in ThisBuild := "io.udash"
6+
crossPaths in ThisBuild := false
7+
scalacOptions in ThisBuild ++= Seq(
8+
"-feature",
9+
"-deprecation",
10+
"-unchecked",
11+
"-language:implicitConversions",
12+
"-language:existentials",
13+
"-language:dynamics",
14+
"-Xfuture",
15+
"-Xfatal-warnings",
16+
"-Xlint:_,-missing-interpolator,-adapted-args"
17+
)
18+
19+
//TODO: remove it after scala-js-jquery 1.0 release
20+
externalResolvers in ThisBuild := Seq(
21+
DefaultMavenRepository,
22+
Resolver.file("local", file(System.getProperty("user.home") + "/.ivy2/local"))(Resolver.ivyStylePatterns)
23+
)
24+
25+
val generatedDir = file("generated")
26+
val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin)
27+
.settings(
28+
libraryDependencies ++= deps.value,
29+
persistLauncher in Compile := true,
30+
31+
/* move these files out of target/. */
32+
crossTarget in (Compile, fullOptJS) := generatedDir,
33+
crossTarget in (Compile, fastOptJS) := generatedDir,
34+
crossTarget in (Compile, packageJSDependencies) := generatedDir,
35+
crossTarget in (Compile, packageScalaJSLauncher) := generatedDir,
36+
crossTarget in (Compile, packageMinifiedJSDependencies) := generatedDir,
37+
38+
compile <<= (compile in Compile).dependsOn(compileStatics),
39+
compileStatics := {
40+
compileStaticsForRelease.value
41+
(crossTarget.value / StaticFilesDir).***.get
42+
},
43+
44+
artifactPath in(Compile, fastOptJS) :=
45+
(crossTarget in(Compile, fastOptJS)).value / StaticFilesDir / WebContent / "scripts" / "frontend-impl-fast.js",
46+
artifactPath in(Compile, fullOptJS) :=
47+
(crossTarget in(Compile, fullOptJS)).value / StaticFilesDir / WebContent / "scripts" / "frontend-impl.js",
48+
artifactPath in(Compile, packageJSDependencies) :=
49+
(crossTarget in(Compile, packageJSDependencies)).value / StaticFilesDir / WebContent / "scripts" / "frontend-deps-fast.js",
50+
artifactPath in(Compile, packageMinifiedJSDependencies) :=
51+
(crossTarget in(Compile, packageMinifiedJSDependencies)).value / StaticFilesDir / WebContent / "scripts" / "frontend-deps.js",
52+
artifactPath in(Compile, packageScalaJSLauncher) :=
53+
(crossTarget in(Compile, packageScalaJSLauncher)).value / StaticFilesDir / WebContent / "scripts" / "frontend-init.js"
54+
)

example/project/Dependencies.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
2+
import sbt._
3+
4+
object Dependencies extends Build {
5+
val udashCoreVersion = "0.1.1"
6+
val udashJQueryVersion = "1.0.0-rc.1"
7+
8+
val deps = Def.setting(Seq[ModuleID](
9+
"io.udash" %%% "udash-core-frontend" % udashCoreVersion,
10+
"io.udash" %%% "udash-jquery" % udashJQueryVersion
11+
))
12+
13+
val depsJS = Def.setting(Seq[org.scalajs.sbtplugin.JSModuleID](
14+
))
15+
}

example/project/UdashBuild.scala

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import org.scalajs.sbtplugin.ScalaJSPlugin.AutoImport._
2+
import sbt.Keys._
3+
import sbt._
4+
5+
object UdashBuild extends Build {
6+
val StaticFilesDir = "UdashStatic"
7+
val WebContent = "WebContent"
8+
9+
def copyIndex(file: File, to: File) = {
10+
val newFile = Path(to.toPath.toString + "/index.html")
11+
IO.copyFile(file, newFile.asFile)
12+
}
13+
14+
val compileStatics = taskKey[Seq[File]]("Frontend static files manager.")
15+
16+
val compileStaticsForRelease = Def.taskDyn {
17+
def outDir(target: File) = target / StaticFilesDir / WebContent
18+
if (!isSnapshot.value) {
19+
Def.task {
20+
val indexFile = sourceDirectory.value / "main/assets/index.prod.html"
21+
copyIndex(indexFile, outDir((crossTarget in (Compile, fullOptJS)).value))
22+
(fullOptJS in Compile).value
23+
(packageMinifiedJSDependencies in Compile).value
24+
(packageScalaJSLauncher in Compile).value
25+
}
26+
} else {
27+
Def.task {
28+
val indexFile = sourceDirectory.value / "main/assets/index.dev.html"
29+
copyIndex(indexFile, outDir((crossTarget in (Compile, fastOptJS)).value))
30+
(fastOptJS in Compile).value
31+
(packageJSDependencies in Compile).value
32+
(packageScalaJSLauncher in Compile).value
33+
}
34+
}
35+
}
36+
}

example/project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version = 0.13.11

example/project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
logLevel := Level.Warn
2+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.8")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head lang="en">
4+
<meta charset="UTF-8">
5+
<title>jquery-demo - development</title>
6+
7+
<script src="scripts/frontend-deps-fast.js"></script>
8+
<script src="scripts/frontend-impl-fast.js"></script>
9+
<script src="scripts/frontend-init.js"></script>
10+
11+
</head>
12+
<body>
13+
<div id="application"></div>
14+
</body>
15+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head lang="en">
4+
<meta charset="UTF-8">
5+
<title>jquery-demo</title>
6+
7+
<script src="scripts/frontend-deps.js"></script>
8+
<script src="scripts/frontend-impl.js"></script>
9+
<script src="scripts/frontend-init.js"></script>
10+
11+
</head>
12+
<body>
13+
<div id="application"></div>
14+
</body>
15+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.udash.demos.jquery
2+
3+
import io.udash._
4+
import io.udash.utils.Bidirectional
5+
6+
class RoutingRegistryDef extends RoutingRegistry[RoutingState] {
7+
def matchUrl(url: Url): RoutingState =
8+
url2State.applyOrElse(url.value.stripSuffix("/"), (x: String) => ErrorState)
9+
10+
def matchState(state: RoutingState): Url =
11+
Url(state2Url.apply(state))
12+
13+
private val (url2State, state2Url) = Bidirectional[String, RoutingState] {
14+
case "" => IndexState
15+
case "/add" => AddState
16+
case "/addBack" => AddBackState
17+
case "/after" => AfterBeforeState
18+
case "/animate" => AnimateState
19+
case "/append" => AppendPrependState
20+
case "/attr" => AttrState
21+
case "/callbacks" => CallbacksState
22+
case "/children" => ChildrenState
23+
case "/data" => DataState
24+
case "/deferred" => DeferredState
25+
case "/each" => EachState
26+
case "/hide" => HideShowState
27+
case "/offset" => OffsetPositionState
28+
case "/on" => OnOneOffState
29+
}
30+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.udash.demos.jquery
2+
3+
import io.udash._
4+
import io.udash.demos.jquery.views.functions._
5+
import io.udash.demos.jquery.views.{ErrorViewPresenter, IndexViewPresenter, RootViewPresenter}
6+
7+
class StatesToViewPresenterDef extends ViewPresenterRegistry[RoutingState] {
8+
def matchStateToResolver(state: RoutingState): ViewPresenter[_ <: RoutingState] = state match {
9+
case RootState => RootViewPresenter
10+
case IndexState => IndexViewPresenter
11+
case AddState => AddViewPresenter
12+
case AddBackState => AddBackViewPresenter
13+
case AfterBeforeState => AfterBeforeViewPresenter
14+
case AnimateState => AnimateViewPresenter
15+
case AppendPrependState => AppendPrependViewPresenter
16+
case AttrState => AttrViewPresenter
17+
case CallbacksState => CallbacksViewPresenter
18+
case ChildrenState => ChildrenViewPresenter
19+
case DataState => DataViewPresenter
20+
case DeferredState => DeferredViewPresenter
21+
case EachState => EachViewPresenter
22+
case HideShowState => HideShowViewPresenter
23+
case OnOneOffState => OnOneOffViewPresenter
24+
case OffsetPositionState => OffsetPositionViewPresenter
25+
case _ => ErrorViewPresenter
26+
}
27+
}

0 commit comments

Comments
 (0)