Skip to content

Commit

Permalink
update to 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chandu0101 committed May 29, 2016
1 parent c7f303e commit 7a65657
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 82 deletions.
13 changes: 10 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ enablePlugins(ScalaJSPlugin)

name := "sri-web-template"

scalaVersion := "2.11.7"
scalaVersion := "2.11.8"

val sriVersion = "0.3.0"
val sriVersion = "0.5.0"

libraryDependencies ++= Seq("com.github.chandu0101.sri" %%% "web" % sriVersion)
val sriscalaCssVersion = "2016.5.0"

libraryDependencies ++= Seq("com.github.chandu0101.sri" %%% "web" % sriVersion,
"com.github.chandu0101.sri" %%% "scalacss" % sriscalaCssVersion)

val assetsDir = "assets/"

Expand All @@ -17,3 +20,7 @@ crossTarget in(Compile, packageScalaJSLauncher) := file(assetsDir)
artifactPath in(Compile, fastOptJS) := ((crossTarget in(Compile, fastOptJS)).value /
((moduleName in fastOptJS).value + "-opt.js"))

scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature",
"-language:postfixOps", "-language:implicitConversions",
"-language:higherKinds", "-language:existentials")

5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var React = require('react-web'),
window.React = React;
window.ReactDOM = ReactDOM;

window.History = require('history');

//window.PouchDB = require("pouchdb");
//require('pouchdb/extras/memory');

//js


Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "sri-web-template",
"version": "0.1.0",
"version": "0.4.0",
"description": "sri web template project",
"repository": {
"type": "git",
"url": ""
},
"scripts": {
"start": "webpack --watch & webpack-dev-server --progress --colors --port 8090",
"start": "webpack & webpack-dev-server --progress --colors --port 8090 --history-api-fallback",
"build": "webpack --config webpack.config.prod.js"
},
"devDependencies": {
Expand All @@ -22,12 +22,15 @@
"style-loader": "^0.12.3",
"haste-resolver-webpack-plugin": "~0.1.2",
"url-loader": "^0.5.6",
"webpack": "^1.9.10",
"webpack-dev-server": "^1.9.0"
"webpack": "^1.12.13",
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"history": "^2.0.0",
"json-loader": "^0.5.4",
"pouchdb": "^5.3.1",
"react": "^0.14.6",
"react-dom": "^0.14.6",
"react-web": "^0.2.1"
"react-web": "^0.2.2"
}
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sbt.version=0.13.8
sbt.version=0.13.9

2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.6")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.9")


5 changes: 3 additions & 2 deletions src/main/scala/sri/templates/web/WebApp.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package sri.templates.web

import org.scalajs.dom
import sri.templates.web.router.AppRouter
import sri.templates.web.routes.AppRouter
import sri.templates.web.styles.AppStyles
import sri.web.ReactDOM

import scala.scalajs.js.Dynamic.{global => g, literal => json}
Expand All @@ -13,7 +14,7 @@ object WebApp extends JSApp {

@JSExport
override def main(): Unit = {

AppStyles.load()
ReactDOM.render(AppRouter.router, dom.document.getElementById("app"))
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/scala/sri/templates/web/components/Button.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sri.templates.web.components

import sri.core._
import sri.web.all._
import sri.web.vdom.htmltags._

import scala.scalajs.js

object Button {

val Component = (props: Props,children : ReactElement) => {
div(className = props.style, onClick = (e: ReactMouseEventH) => props.onPress())(children)
}

case class Props(style: String, onPress: () => _)

def apply(style: String, onPress: () => _,key : js.UndefOr[String] = js.undefined)(children : ReactNode*) = createStatelessFunctionElementWithChildren(Component, Props(style, onPress),key = key)(children : _*)

}
42 changes: 0 additions & 42 deletions src/main/scala/sri/templates/web/components/HelloWeb.scala

This file was deleted.

81 changes: 81 additions & 0 deletions src/main/scala/sri/templates/web/components/TopNav.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package sri.templates.web.components

import sri.scalacss.Defaults._
import sri.templates.web.routes.AppRouter.HomePage
import sri.templates.web.styles.Colors
import sri.web.all._
import sri.web.router.{WebDynamicPage, WebRouterComponent, WebStaticPage}
import sri.web.vdom.htmltags._

import scala.scalajs.js
import scala.scalajs.js.Dynamic.{literal => json}
import scala.scalajs.js.annotation.ScalaJSDefined
import scala.scalajs.js.{UndefOr => U}
import scalacss.Defaults._

object TopNav {

@ScalaJSDefined
class Component extends WebRouterComponent[Unit, Unit] {
def render() = {
div(className = styles.navMenu)(
getStaticItem("Home", HomePage))
}

def getStaticItem(text: String, page: WebStaticPage, query: js.UndefOr[js.Object] = js.undefined, state: js.UndefOr[js.Object] = js.undefined) = {
Button(style = styles.menuItem(page == currentRoute.page),
onPress = () => navigateTo(page, query = query, state = state))(
span()(text)
)
}

def getDynamicItem(text: String, page: WebDynamicPage[_], placeholder: String, query: js.UndefOr[js.Object] = js.undefined, state: js.UndefOr[js.Object] = js.undefined) = {
Button(style = styles.menuItem(page == currentRoute.page),
onPress = () => navigateToDynamic(page, placeholder = placeholder, query = query, state = state))(
span()(text)
)
}
}

@ScalaJSDefined
class StaticQuery(val sorting: String, val option: js.UndefOr[String] = js.undefined) extends js.Object


object styles extends StyleSheet.Inline {

import dsl._

val navMenu = style(display.flex,
flexDirection.row,
alignItems.center,
backgroundColor :=! Colors.gold,
margin.`0`,
height(60.px),
paddingLeft(40 px))

val menuItem = styleF.bool(selected => {
styleS(padding(20.px),
fontSize :=! "1.5em",
cursor.pointer,
color :=! c"rgb(244, 233, 233)",
marginLeft(10.px),
marginRight(10.px),
mixinIfElse(selected)(backgroundColor :=! Colors.darkGold,
fontWeight._500)(backgroundColor :=! Colors.transparent,
fontWeight.normal)
)
})


}


val ctor = getTypedConstructor(js.constructorOf[Component], classOf[Component])

ctor.contextTypes = sri.web.router.routerContextTypes


def apply(ref: js.UndefOr[String] = "", key: js.Any = {}) = createElementNoProps(ctor)

}

26 changes: 0 additions & 26 deletions src/main/scala/sri/templates/web/router/AppRouter.scala

This file was deleted.

38 changes: 38 additions & 0 deletions src/main/scala/sri/templates/web/routes/AppRouter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package sri.templates.web.routes

import sri.core.ReactElement
import sri.scalacss.Defaults._
import sri.templates.web.components._
import sri.templates.web.screens.HomeScreen
import sri.templates.web.styles.GlobalStyle
import sri.web.router._
import sri.web.vdom.htmltags._
object AppRouter {

object HomePage extends WebStaticPage


object Config extends WebRouterConfig {

override val history: History = HistoryFactory.browserHistory()

override val initialRoute: (WebStaticPage, WebRoute) = defineInitialRoute(HomePage, (route: WebRoute) => HomeScreen())


override val notFound: WebRouteNotFound = WebRouteNotFound(HomePage)

/**
* this method is responsible for rendering components ,
* @param route current route that is pushed to stack
* @return
*/
override def renderScene(route: WebRoute): ReactElement = {
div(className = GlobalStyle.flexOneAndDirectionVertical)(
TopNav(),
super.renderScene(route)
)
}
}

val router = WebRouter(Config)
}
29 changes: 29 additions & 0 deletions src/main/scala/sri/templates/web/screens/HomeScreen.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package sri.templates.web.screens

import sri.templates.web.styles.GlobalStyle
import sri.web.all._
import sri.web.vdom.htmltags._
import sri.core._
import sri.universal.components._
import sri.web.all._
import sri.web.vdom.htmltags._
import scala.scalajs.js
import scala.scalajs.js.annotation.ScalaJSDefined
import scala.scalajs.js.{UndefOr => U, undefined => undefined}
import scalacss.Defaults._
import sri.scalacss.Defaults._

object HomeScreen {

@ScalaJSDefined
class Component extends ReactComponent[Unit, Unit] {
def render() = div(className = GlobalStyle.flexOneAndCenter)(
span(className = GlobalStyle.bigText)("Home Screen")
)
}

val ctor = getTypedConstructor(js.constructorOf[Component], classOf[Component])

def apply(key: js.UndefOr[String] = js.undefined, ref: js.Function1[Component, _] = null) = createElementNoProps(ctor, key = key, ref = ref)

}
17 changes: 17 additions & 0 deletions src/main/scala/sri/templates/web/styles/AppStyles.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package sri.templates.web.styles


import sri.scalacss.Defaults._
import sri.templates.web.components.TopNav

import scalacss.Defaults._
import scalacss.mutable.GlobalRegistry

object AppStyles {

def load() = {
GlobalRegistry.register(GlobalStyle,
TopNav.styles)
GlobalRegistry.addToDocumentOnRegistration()
}
}
17 changes: 17 additions & 0 deletions src/main/scala/sri/templates/web/styles/Colors.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package sri.templates.web.styles

object Colors {

val blue = "#0B8AA9"

val darkBlue = "#126884"


val gold = "#D09527"

val darkGold = "#D86D1F"

val transparent = "transparent"

val lightGrey = "#DAD5D5"
}
Loading

0 comments on commit 7a65657

Please sign in to comment.