Skip to content

Commit

Permalink
livescript everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
vendethiel committed Oct 8, 2012
1 parent d071060 commit e3eab6c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 53 deletions.
12 changes: 5 additions & 7 deletions app/app.ls
@@ -1,14 +1,12 @@
# Declare app level module which depends on filters, and services
App = angular.module \app, <[ ngCookies ngResource app.controllers app.directives app.filters app.services ]>
App = angular.module \app <[ngCookies ngResource app.controllers app.directives app.filters app.services]>

App.config [ '$routeProvider' '$locationProvider'
($routeProvider, $locationProvider, config) ->
App.config <[$routeProvider $locationProvider]> +++ ($routeProvider, $locationProvider, config) ->
$routeProvider
.when \/view1, templateUrl: \/partials/app/partial1.html
.when \/view2, templateUrl: \/partials/app/partial2.html
.when \/view1 templateUrl: \/partials/app/partial1.html
.when \/view2 templateUrl: \/partials/app/partial2.html
# Catch all
.otherwise redirectTo: \/view1

# Without serve side support html5 must be disabled.
$locationProvider.html5Mode false
]
$locationProvider.html5Mode false
37 changes: 10 additions & 27 deletions app/app/controllers.ls
@@ -1,20 +1,12 @@

mod = {}

mod.AppCtrl = [
'$scope'
'$location'
'$resource'
'$rootScope'

(s, $location, $resource, $rootScope) ->
mod.AppCtrl = <[$scope $location $resource $rootScope]> +++ (s, $location, $resource, $rootScope) ->

# Uses the url to determine if the selected
# menu item should have the class active.
s.$location = $location
s.$watch('$location.path()', (path) ->
s.activeNavId = path || '/'
)
s <<< {$location}
s.$watch '$location.path()' (path or '/') ->
s.activeNavId = path

# getClass compares the current url with the id.
# If the current url starts with the id it returns 'active'
Expand All @@ -25,24 +17,15 @@ mod.AppCtrl = [
# getClass('/orders') # returns ''
#
s.getClass = (id) ->
if s.activeNavId.substring(0, id.length) == id
return 'active'
if s.activeNavId.substring 0 id.length is id
'active'
else
return ''
]
''

mod.MyCtrl1 = [
'$scope'

(s) ->
mod.MyCtrl1 = <[$scope]> +++ (s) ->
s.Title = "MyCtrl1"
]

mod.MyCtrl2 = [
'$scope'

(s) ->
mod.MyCtrl2 = <[$scope]> +++ (s) ->
s.Title = "MyCtrl2"
]

angular.module('app.controllers', []).controller(mod)
angular.module 'app.controllers'[] .controller mod
13 changes: 4 additions & 9 deletions app/app/directives.ls
Expand Up @@ -3,17 +3,12 @@
# Create an object to hold the module.
mod = {}

mod.appVersion = [
'version'

(version) ->

mod.appVersion = <[version]> +++ (version) ->
(scope, elm, attrs) ->
elm.text(version)
]
elm.text version

# register the module with Angular
angular.module('app.directives', [
angular.module 'app.directives' [
# require the 'app.service' module
'app.services'
]).directive(mod)
] .directive mod
6 changes: 3 additions & 3 deletions app/app/filters.ls
@@ -1,8 +1,8 @@
# Filters

angular.module('app.filters', []).
filter \interpolate, [\version, (version) ->
(text) -> String(text).replace(/\%VERSION\%/mg, version) ]
angular.module 'app.filters' [] .
filter \interpolate <[version]> +++ (version) ->
(text) -> String text .replace /\%VERSION\%/mg version

# TODO Convert to following syntax.
# # Create an object to hold the module.
Expand Down
6 changes: 2 additions & 4 deletions app/app/services.ls
@@ -1,8 +1,6 @@
# Services

# Create an object to hold the module.
mod = {}
mod = version: = -> "0.1"

mod.version = -> "0.1"

angular.module('app.services', []).factory(mod)
angular.module 'app.services' [] .factory mod
5 changes: 2 additions & 3 deletions app/init.ls
@@ -1,3 +1,2 @@

angular.element(document).ready ->
angular.bootstrap(document, [\app])
angular.element document .ready ->
angular.bootstrap document, <[app]>

0 comments on commit e3eab6c

Please sign in to comment.