Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 79352beacb0206c25451eda129fb416f10347a54 @NilsLattek committed May 8, 2012
Showing with 24,595 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +6 −0 .nodemonignore
  3. +7 −0 LICENSE
  4. +7 −0 Makefile
  5. +77 −0 README.md
  6. +46 −0 bin/build.sh
  7. +27 −0 bin/build.txt
  8. +9,822 −0 bin/r.js
  9. +13 −0 client-build/index.html
  10. +6 −0 client-build/js/libs/require/require.js
  11. +6 −0 client-build/js/main.js
  12. +43 −0 client-test-runner.html
  13. +13 −0 client/index.html
  14. +29 −0 client/js/build.js
  15. +19 −0 client/js/collections/entries.js
  16. +1,290 −0 client/js/libs/backbone/backbone.js
  17. +3 −0 client/js/libs/backbone/wrapper.js
  18. +1,550 −0 client/js/libs/handlebars/handlebars.js
  19. +4 −0 client/js/libs/handlebars/wrapper.js
  20. +189 −0 client/js/libs/require/order.js
  21. +2,053 −0 client/js/libs/require/require.js
  22. +11 −0 client/js/libs/require/text.js
  23. +999 −0 client/js/libs/underscore/underscore.js
  24. +4 −0 client/js/libs/underscore/wrapper.js
  25. +4 −0 client/js/libs/zepto/wrapper.js
  26. +1,412 −0 client/js/libs/zepto/zepto.js
  27. +23 −0 client/js/main.js
  28. +20 −0 client/js/models/entry.js
  29. +33 −0 client/js/routers/workspace.js
  30. +5 −0 client/js/templates/entries-list.handlebars
  31. +1 −0 client/js/templates/entry-item.handlebars
  32. +69 −0 client/js/views/entries-list.js
  33. +38 −0 client/js/views/entry-item.js
  34. +17 −0 client/js/views/page.js
  35. +13 −0 package.json
  36. +30 −0 server/controllers/entries.js
  37. +31 −0 server/models/entry.js
  38. +38 −0 server/server.js
  39. +15 −0 shared/js/entry-validation.js
  40. +1,290 −0 test/client/libs/backbone/backbone.js
  41. +3 −0 test/client/libs/backbone/wrapper.js
  42. +1,148 −0 test/client/libs/expect.js
  43. BIN test/client/libs/mocha.css
  44. +4,112 −0 test/client/libs/mocha.js
  45. +14 −0 test/client/models/entry.test.js
  46. +37 −0 test/server/controllers/entries.test.js
  47. +16 −0 test/shared/entry-validation.test.js
@@ -0,0 +1,2 @@
+.DS_Store
+node_modules
@@ -0,0 +1,6 @@
+# ignore js files in the following folders:
+/bin/*
+/client/*
+/client-build/*
+/shared/*
+./README.md
@@ -0,0 +1,7 @@
+Copyright (c) 2012 Nils Lattek
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
+# thanks to TJ: https://github.com/visionmedia/mocha/issues/106#issuecomment-2979500
+TESTS = $(shell find test/server test/shared -name "*.test.js")
+
+test:
+ @./node_modules/.bin/mocha $(TESTS)
+
+.PHONY: test
@@ -0,0 +1,77 @@
+##Sharing RequireJS modules
+
+This example shows how to reuse code between the client and server. A typical use case would be to use the same validation logic for your models on both sides.
+
+Feel free to use it as a basic template for your applications.
+
+##Project structure
+This backbone application is divided into a couple of AMD modules. A special shared module is used inside the node.js server.
+It is possible to test all modules using mocha and expect.js. (Examples included)
+
+The Backbone app is inside the 'client' folder.
+The server is inside the 'server' folder (obviously...).
+Any module which should be shared between client and server is in the 'shared' folder and has to start with the amdefine wrapper.
+The minified client app is in the 'client-build' folder. This folder gets deleted on every build.
+
+##Usage
+The following steps were tested with the following environment:
+
+ MacOS 10.7.3
+ Node.js 0.6.14
+ npm 1.1.16
+
+Check out this git repository:
+
+ $ git clone git@github.com:NilsLattek/backbone-requirejs-node-boilerplate.git
+
+Remove git history if you want to use this example as a template for your project:
+
+ $ cd backbone-requirejs-node-boilerplate
+ $ rm -rf .git
+
+Install node.js if you haven't already: http://nodejs.org/
+
+Install npm (should already be installed if you are using the latest node setup):
+
+ $ curl http://npmjs.org/install.sh | sh
+
+Install node packages for the node.js server:
+
+ $ npm install .
+
+Start the development server and navigate to 'http://localhost:8000':
+
+ $ node server/server.js
+
+Or use nodemon for watching your server files and automatically restart the server:
+
+ $ npm install -g nodemon
+ $ nodemon server/server.js
+
+Run serverside and shared modules unittests:
+
+ $ make test
+
+Run clientside unittests:
+
+ Open 'client-test-runner.html' in your browser. (TODO: it would be nice to run these along with the serverside tests in one command.) If you add more tests you have to adjust the client-test-runner.html file and list the new test files. This is not the optimal way and should be optimized...
+
+Build (concatenate and minify) everything using r.js:
+
+ $ cd bin
+ $ ./build.sh
+
+Start production environment (node will use the client-build folder with the minifed client app):
+
+ $ NODE_ENV=production node server/server.js
+
+
+
+###Roadmap
+- Use r.js to optimize CSS files
+- Provide a coffeescript version
+- Add strict mode: "use strict";
+
+
+###License
+MIT license (of course).
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+# thanks to https://github.com/mozilla/BrowserQuest
+
+BUILDDIR="../client-build"
+PROJECTDIR="../client/js"
+SHAREDDIR="../shared"
+CURDIR=$(pwd)
+
+
+echo "Deleting previous build directory"
+rm -rf $BUILDDIR
+
+echo "Creating build directory"
+mkdir $BUILDDIR
+
+echo "Copy over shared modules"
+cp -r $SHAREDDIR/* $BUILDDIR
+
+echo "Building client with RequireJS"
+cd $PROJECTDIR
+node ../../bin/r.js -o build.js
+cd $CURDIR
+
+echo "Removing unnecessary js files from the build directory"
+find $BUILDDIR/js -type f -not \( -name "main.js" -o -name "require.js" \) -delete
+
+echo "Removing collections directory"
+rm -rf $BUILDDIR/js/collections
+
+echo "Removing models directory"
+rm -rf $BUILDDIR/js/models
+
+echo "Removing routers directory"
+rm -rf $BUILDDIR/js/routers
+
+echo "Removing templates directory"
+rm -rf $BUILDDIR/js/templates
+
+echo "Removing views directory"
+rm -rf $BUILDDIR/js/views
+
+echo "Moving build.txt to current dir"
+mv $BUILDDIR/build.txt $CURDIR
+
+echo "Build complete"
@@ -0,0 +1,27 @@
+
+js/libs/require/require.js
+----------------
+js/libs/require/require.js
+
+js/main.js
+----------------
+js/libs/underscore/underscore.js
+js/libs/zepto/zepto.js
+js/libs/require/order.js
+js/libs/backbone/backbone.js
+order!libs/backbone/backbone
+js/libs/backbone/wrapper.js
+js/libs/zepto/wrapper.js
+js/libs/handlebars/handlebars.js
+js/libs/handlebars/wrapper.js
+js/libs/require/text.js
+text!templates/entries-list.handlebars
+text!templates/entry-item.handlebars
+js/views/entry-item.js
+js/views/entries-list.js
+js/entry-validation.js
+js/models/entry.js
+js/collections/entries.js
+js/routers/workspace.js
+js/views/page.js
+js/main.js
Oops, something went wrong.

0 comments on commit 79352be

Please sign in to comment.