Skip to content

Example application based on this wrapper; Closes #7 #8

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

Merged
merged 1 commit into from
Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: scala

scala:
- 2.11.7
- 2.11.8

script:
- sbt ++$TRAVIS_SCALA_VERSION test
- sbt ++$TRAVIS_SCALA_VERSION test
- cd example && sbt ++$TRAVIS_SCALA_VERSION compile
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name := "udash-jquery"

version := "1.0.0-SNAPSHOT"
version := "1.0.0-rc.2"
organization := "io.udash"
scalaVersion := "2.11.7"
scalaVersion := "2.11.8"
scalacOptions in ThisBuild ++= Seq(
"-feature",
"-deprecation",
Expand All @@ -22,7 +22,7 @@ libraryDependencies ++= Seq(
)

jsDependencies +=
"org.webjars" % "jquery" % "2.2.0" / "2.2.0/jquery.js" minified "2.2.0/jquery.min.js"
"org.webjars" % "jquery" % "2.2.3" / "2.2.3/jquery.js" minified "2.2.3/jquery.min.js"

requiresDOM in Test := true
persistLauncher in Test := false
Expand Down
132 changes: 132 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Created by .ignore support plugin (hsz.mobi)
### Eclipse template
*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath

# Eclipse Core
.project

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Java annotation processor (APT)
.factorypath

# PDT-specific
.buildpath

# sbteclipse plugin
.target

# TeXlipse plugin
.texlipse
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
### Java template
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Scala template
*.class
*.log

# sbt specific
.cache
.history
.lib/
dist/*
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/

# Scala-IDE specific
.scala_dependencies
.worksheet


generated/
54 changes: 54 additions & 0 deletions example/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name := "jquery-demo"

version in ThisBuild := "1.0.0-SNAPSHOT"
scalaVersion in ThisBuild := "2.11.8"
organization in ThisBuild := "io.udash"
crossPaths in ThisBuild := false
scalacOptions in ThisBuild ++= Seq(
"-feature",
"-deprecation",
"-unchecked",
"-language:implicitConversions",
"-language:existentials",
"-language:dynamics",
"-Xfuture",
"-Xfatal-warnings",
"-Xlint:_,-missing-interpolator,-adapted-args"
)

//TODO: remove it after scala-js-jquery 1.0 release
externalResolvers in ThisBuild := Seq(
DefaultMavenRepository,
Resolver.file("local", file(System.getProperty("user.home") + "/.ivy2/local"))(Resolver.ivyStylePatterns)
)

val generatedDir = file("generated")
val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin)
.settings(
libraryDependencies ++= deps.value,
persistLauncher in Compile := true,

/* move these files out of target/. */
crossTarget in (Compile, fullOptJS) := generatedDir,
crossTarget in (Compile, fastOptJS) := generatedDir,
crossTarget in (Compile, packageJSDependencies) := generatedDir,
crossTarget in (Compile, packageScalaJSLauncher) := generatedDir,
crossTarget in (Compile, packageMinifiedJSDependencies) := generatedDir,

compile <<= (compile in Compile).dependsOn(compileStatics),
compileStatics := {
compileStaticsForRelease.value
(crossTarget.value / StaticFilesDir).***.get
},

artifactPath in(Compile, fastOptJS) :=
(crossTarget in(Compile, fastOptJS)).value / StaticFilesDir / WebContent / "scripts" / "frontend-impl-fast.js",
artifactPath in(Compile, fullOptJS) :=
(crossTarget in(Compile, fullOptJS)).value / StaticFilesDir / WebContent / "scripts" / "frontend-impl.js",
artifactPath in(Compile, packageJSDependencies) :=
(crossTarget in(Compile, packageJSDependencies)).value / StaticFilesDir / WebContent / "scripts" / "frontend-deps-fast.js",
artifactPath in(Compile, packageMinifiedJSDependencies) :=
(crossTarget in(Compile, packageMinifiedJSDependencies)).value / StaticFilesDir / WebContent / "scripts" / "frontend-deps.js",
artifactPath in(Compile, packageScalaJSLauncher) :=
(crossTarget in(Compile, packageScalaJSLauncher)).value / StaticFilesDir / WebContent / "scripts" / "frontend-init.js"
)
15 changes: 15 additions & 0 deletions example/project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import sbt._

object Dependencies extends Build {
val udashCoreVersion = "0.1.1"
val udashJQueryVersion = "1.0.0-rc.1"

val deps = Def.setting(Seq[ModuleID](
"io.udash" %%% "udash-core-frontend" % udashCoreVersion,
"io.udash" %%% "udash-jquery" % udashJQueryVersion
))

val depsJS = Def.setting(Seq[org.scalajs.sbtplugin.JSModuleID](
))
}
36 changes: 36 additions & 0 deletions example/project/UdashBuild.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import org.scalajs.sbtplugin.ScalaJSPlugin.AutoImport._
import sbt.Keys._
import sbt._

object UdashBuild extends Build {
val StaticFilesDir = "UdashStatic"
val WebContent = "WebContent"

def copyIndex(file: File, to: File) = {
val newFile = Path(to.toPath.toString + "/index.html")
IO.copyFile(file, newFile.asFile)
}

val compileStatics = taskKey[Seq[File]]("Frontend static files manager.")

val compileStaticsForRelease = Def.taskDyn {
def outDir(target: File) = target / StaticFilesDir / WebContent
if (!isSnapshot.value) {
Def.task {
val indexFile = sourceDirectory.value / "main/assets/index.prod.html"
copyIndex(indexFile, outDir((crossTarget in (Compile, fullOptJS)).value))
(fullOptJS in Compile).value
(packageMinifiedJSDependencies in Compile).value
(packageScalaJSLauncher in Compile).value
}
} else {
Def.task {
val indexFile = sourceDirectory.value / "main/assets/index.dev.html"
copyIndex(indexFile, outDir((crossTarget in (Compile, fastOptJS)).value))
(fastOptJS in Compile).value
(packageJSDependencies in Compile).value
(packageScalaJSLauncher in Compile).value
}
}
}
}
1 change: 1 addition & 0 deletions example/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 0.13.11
2 changes: 2 additions & 0 deletions example/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
logLevel := Level.Warn
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.8")
15 changes: 15 additions & 0 deletions example/src/main/assets/index.dev.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>jquery-demo - development</title>

<script src="scripts/frontend-deps-fast.js"></script>
<script src="scripts/frontend-impl-fast.js"></script>
<script src="scripts/frontend-init.js"></script>

</head>
<body>
<div id="application"></div>
</body>
</html>
15 changes: 15 additions & 0 deletions example/src/main/assets/index.prod.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>jquery-demo</title>

<script src="scripts/frontend-deps.js"></script>
<script src="scripts/frontend-impl.js"></script>
<script src="scripts/frontend-init.js"></script>

</head>
<body>
<div id="application"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.udash.demos.jquery

import io.udash._
import io.udash.utils.Bidirectional

class RoutingRegistryDef extends RoutingRegistry[RoutingState] {
def matchUrl(url: Url): RoutingState =
url2State.applyOrElse(url.value.stripSuffix("/"), (x: String) => ErrorState)

def matchState(state: RoutingState): Url =
Url(state2Url.apply(state))

private val (url2State, state2Url) = Bidirectional[String, RoutingState] {
case "" => IndexState
case "/add" => AddState
case "/addBack" => AddBackState
case "/after" => AfterBeforeState
case "/animate" => AnimateState
case "/append" => AppendPrependState
case "/attr" => AttrState
case "/callbacks" => CallbacksState
case "/children" => ChildrenState
case "/data" => DataState
case "/deferred" => DeferredState
case "/each" => EachState
case "/hide" => HideShowState
case "/offset" => OffsetPositionState
case "/on" => OnOneOffState
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.udash.demos.jquery

import io.udash._
import io.udash.demos.jquery.views.functions._
import io.udash.demos.jquery.views.{ErrorViewPresenter, IndexViewPresenter, RootViewPresenter}

class StatesToViewPresenterDef extends ViewPresenterRegistry[RoutingState] {
def matchStateToResolver(state: RoutingState): ViewPresenter[_ <: RoutingState] = state match {
case RootState => RootViewPresenter
case IndexState => IndexViewPresenter
case AddState => AddViewPresenter
case AddBackState => AddBackViewPresenter
case AfterBeforeState => AfterBeforeViewPresenter
case AnimateState => AnimateViewPresenter
case AppendPrependState => AppendPrependViewPresenter
case AttrState => AttrViewPresenter
case CallbacksState => CallbacksViewPresenter
case ChildrenState => ChildrenViewPresenter
case DataState => DataViewPresenter
case DeferredState => DeferredViewPresenter
case EachState => EachViewPresenter
case HideShowState => HideShowViewPresenter
case OnOneOffState => OnOneOffViewPresenter
case OffsetPositionState => OffsetPositionViewPresenter
case _ => ErrorViewPresenter
}
}
Loading