Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
solomon23 committed Nov 13, 2013
0 parents commit 5625dd9
Show file tree
Hide file tree
Showing 92 changed files with 47,622 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
public/css
public/js
s-seed.sublime-workspace
build
226 changes: 226 additions & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
_ = require "underscore"
Path = require "path"

module.exports = (grunt) ->
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks "grunt-contrib-less"
grunt.loadNpmTasks "grunt-contrib-requirejs"
grunt.loadNpmTasks "grunt-contrib-watch"
grunt.loadNpmTasks "grunt-contrib-cssmin"
grunt.loadNpmTasks "grunt-contrib-copy"
grunt.loadNpmTasks "grunt-contrib-clean"

grunt.loadNpmTasks "grunt-newer"
grunt.loadNpmTasks "grunt-nodemon"
grunt.loadNpmTasks "grunt-concurrent"
grunt.loadNpmTasks "grunt-angular-templates"
grunt.loadNpmTasks "grunt-filerev"
grunt.loadNpmTasks "grunt-filerev-assets"


grunt.registerTask "default", ["build"]

# combine the javascript files using the requirejs config
grunt.registerTask "jscombine", "Require.Js optimization", ->
config = require "./client/js/require-config.coffee"

rjsClientConfig = config.requireConfig

# client build config needs some extra items
_.extend rjsClientConfig,
name: './lib/almond'
baseUrl: "build/temp"
include: ["js/main.js"]
out: "./build/public/js/combined.js"

grunt.config.set "requirejs",
optimize:
options: rjsClientConfig

grunt.task.run "requirejs"

grunt.registerTask "server", ["builddev", "concurrent"]

grunt.registerTask "builddev", [
# removing the public dir
"clean:public"

# turn the client coffee into js into the public folder
"coffee:dev"

# compile the less CSS
"less:dev"

# create the single template file
"ngtemplates"
]

grunt.registerTask "build", [
# remove build folder
"clean:build"

# turn the client coffee into js in the build/temp
"coffee:prod"

# compile the templates
"ngtemplates"

# copy the templates and lib to build/temp
"copy:client"

# combine all the js files
"jscombine"

# compile the css
"less:prod"

# minify the css
"cssmin"

# set versions on all the files
"filerev"

# create a server map
"filerev_assets"

# copy over server coffee files
"copy:server"

# copy over deploy files
"copy:heroku"

# remove the temp files
"clean:temp"
]

grunt.initConfig

clean:
build:
files: [{
dot: true
src: [
"build/*"
"!build/.git*"
]
}]

temp: ["build/temp"]

public: ["public"]

concurrent:
dev:
tasks: ["nodemon", "watch"]
options:
logConcurrentOutput: true

nodemon:
dev:
options:
watchedFolders: ["server"]
file: "./server/app.coffee"

coffee:
dev:
options:
bare: true
sourceMap: true
sourceRoot: ""

expand: true
cwd: "client"
src: ["./**/*.coffee"]
dest: "public"
ext: ".js"

prod:
options:
bare: true
sourceMap: false
sourceRoot: ""

expand: true
cwd: "client"
src: ["./**/*.coffee"]
dest: "build/temp"
ext: ".js"

less:
dev:
options: yuicompress: true
files:
"./public/css/app.css": "./client/less/app.less"

prod:
files:
"./build/temp/css/app.css": "./client/less/app.less"

# put hash numbers on the assets
filerev:
files:
src: [
"./build/public/js/**/*.js"
"./build/public/lib/**/*.js"
"./build/public/css/**/*.css"
"./build/public/images/**/*.{png,jpg,jpeg,gif,webp,svg}"
]

# create a map file for all the assets
filerev_assets:
options:
cwd: "build/public"
dest: "build/server/assets.json"

cssmin:
minify:
expand: true
cwd: "build/temp"
src: ["css/app.css"]
dest: "build/public"
ext: ".css"

copy:
client:
files: [
# external lib files
{expand: true, src: "lib/**/*.js", cwd: "client/", dest: "./build/temp/"}

# combined template file
{src: "public/js/templates.js", dest: "build/temp/js/templates.js"}

# image files
{expand: true, src: "images/**", cwd: "client/", dest: "./build/public/"}
]
server:
files: [
{src: ["server/**"], dest: "build/"}
]
heroku:
files: [
{src: ["Procfile"], dest: "build/"}
{src: "package.json", dest: "build/package.json"}
]

ngtemplates:
myApp:
cwd: "./client"
src: "./partials/**/*.html"
dest:"./public/js/templates.js"
options:
htmlmin: collapseWhitespace: true, collapseBooleanAttributes: true
bootstrap: (module, script) ->
"define(['appModule'], function(appModule) {appModule.run(['$templateCache', function($templateCache){ #{script} }])});"

watch:
coffee:
files: ["**/*.coffee"]
tasks: ["newer:coffee:dev"]

less:
files: ["./client/less/**/*.less"]
tasks: ["less:dev"]

ngtemplates:
files: ["client/partials/**.html"]
tasks: ["ngtemplates"]
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: coffee server/app.coffee
Binary file added client/images/lauren-cats.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions client/js/app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
define ["angular"], (angular) ->

# setup the app
angular.module("myApp", [
"ngRoute"
]).
config ["$routeProvider", ($routeProvider) ->
# add app config here
]
18 changes: 18 additions & 0 deletions client/js/controllers/page1.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
define ["appModule"], (appModule) ->
Page1Controller = ($scope, remote) ->
_init = ->
$scope.page = "page1"

# gets data from a remote server
remote.getData()
.success (data) ->
$scope.myData = data.message

_init()

# register the controller
appModule.controller "Page1Controller", [
"$scope"
"remote"
Page1Controller
]
11 changes: 11 additions & 0 deletions client/js/controllers/page2.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define ["appModule"], (appModule) ->

Page2Controller = ($scope) ->
$scope.page = "page2"


# register the controller
appModule.controller "Page2Controller", [
"$scope"
Page2Controller
]
15 changes: 15 additions & 0 deletions client/js/controllers/root.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
define ["appModule", "templates"], (appModule) ->

RootController = ($scope, $route, $location) ->
_init = ->
$scope.location = $location

_init()

# register the controller
appModule.controller "rootController", [
"$scope"
"$route"
"$location"
RootController
]
12 changes: 12 additions & 0 deletions client/js/directives/app-version.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
define ["appModule"], (appModule) ->

# Directive
appVersion = (version) ->
(scope, elm, attrs) ->
elm.text version

# register the directive
appModule.directive "appVersion", [
"version"
appVersion
]
11 changes: 11 additions & 0 deletions client/js/filters/interpolate.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define ["appModule"], (appModule) ->

# Filter
interpolate = (version) ->
(text) ->
String(text).replace /\%VERSION\%/mg, version

appModule.filter "interpolate", [
"version"
interpolate
]
12 changes: 12 additions & 0 deletions client/js/filters/static.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
define ["appModule"], (appModule) ->

###
Filter to map static content to versioned static content
###
staticFilter = ->
(text) ->
staticMapping[text] ? text

appModule.filter "static", [
staticFilter
]
46 changes: 46 additions & 0 deletions client/js/main.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
requirejs.config requireConfig if requireConfig?

require [
"angular"
"jquery"
"underscore"
"appModule"
"templates"

# bootstrap
"lib/bootstrap/affix.js"
"lib/bootstrap/alert.js"
"lib/bootstrap/button.js"
"lib/bootstrap/carousel.js"
"lib/bootstrap/collapse.js"
"lib/bootstrap/dropdown.js"
"lib/bootstrap/modal.js"
"lib/bootstrap/tooltip.js"
"lib/bootstrap/popover.js"
"lib/bootstrap/scrollspy.js"
"lib/bootstrap/tab.js"
"lib/bootstrap/transition.js"

"lib/angular/angular-route.js"

# the routes
"js/routes.js"

# services
"js/services/version.js"
"js/services/remote.js"

# controllers
"js/controllers/root.js"
"js/controllers/page1.js"
"js/controllers/page2.js"

# filters
"js/filters/interpolate.js"
"js/filters/static.js"

# directives
"js/directives/app-version.js"

], (angular) ->
angular.bootstrap $("html"), ["myApp"]
Loading

0 comments on commit 5625dd9

Please sign in to comment.