Browse files

Update to Dojo 1.8.0, separate package & application profiles, change…

… whitespace rules.
  • Loading branch information...
1 parent c952e71 commit f35c4793270eb19dbc2798ced26f532182f60443 @csnover committed Aug 19, 2012
Showing with 273 additions and 650 deletions.
  1. +8 −10 README.md
  2. +8 −8 build.sh
  3. +107 −0 profiles/app.profile.js
  4. +5 −5 src/app/Dialog.js
  5. +0 −129 src/app/app.profile.js
  6. +43 −36 src/app/main.js
  7. +43 −0 src/app/package.js
  8. +24 −24 src/app/package.json
  9. +1 −1 src/app/resources/app.css
  10. +21 −28 src/app/run.js
  11. +0 −278 src/dbp/Router.js
  12. +0 −11 src/dbp/tests/Router.html
  13. +0 −109 src/dbp/tests/Router.js
  14. +1 −1 src/dijit
  15. +1 −1 src/dojo
  16. +1 −1 src/dojox
  17. +7 −5 src/index.html
  18. +2 −2 src/server.sh
  19. +1 −1 src/util
View
18 README.md
@@ -3,10 +3,10 @@ Dojo Boilerplate: A Starter Kit for Dojo Development
The Dojo Boilerplate is a set of files to help you rapidly get up and running
with the Dojo Toolkit. It illustrates some basic best practices when working
-with Dojo. This is the branch for the new Dojo 1.7 loader and build systems,
-which use AMD modules; there is also a [branch using the old synchronous
-loader](https://github.com/csnover/dojo-boilerplate/tree/1.6), for use
-with Dojo 1.6.
+with Dojo. This is the branch for the new AMD loader and build systems in Dojo
+1.7 and later; there is also a
+[branch using the old synchronous loader](https://github.com/csnover/dojo-boilerplate/tree/1.6),
+for use with Dojo 1.6 and earlier.
Huge thanks go out to [neonstalwart](https://github.com/neonstalwart) for his
original
@@ -50,19 +50,17 @@ A brief tour
(by way of the second `[ 'app' ]` argument).
* The file `build.sh` takes your application files and builds them for
production use using the Dojo build tool. It depends on the presence of the
- build profile at `src/app/app.profile.js`.
+ build profile at `profiles/app.profile.js`.
* The file `src/app/resources/app.css` contains import statements to load
the CSS for Dojo’s Claro theme. _If you are not using Dijit widgets, you
probably want to remove these imports!_
-* The directory `src/dbp` contains tools you may find useful. These tools
- are a work in progress, and are not yet updated to AMD syntax.
Useful resources
----------------
-* [Dojo Reference Guide (latest release version)](http://dojotoolkit.org/reference-guide/)
-* [Dojo Reference Guide (Dojo trunk)](http://livedocs.dojotoolkit.org/)
-* [Introduction to Custom Dojo Widgets](http://www.enterprisedojo.com/2010/09/21/introduction-to-custom-dojo-widgets/)
+* [Dojo Tutorials](http://dojotoolkit.org/documentation/)
+* [Dojo Reference Guide](http://dojotoolkit.org/reference-guide/)
+* [Dojo API Browser](http://dojotoolkit.org/api/)
About the boilerplate
---------------------
View
16 build.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
set -e
@@ -21,13 +21,13 @@ LOADERMID="app/run"
LOADERCONF="$SRCDIR/$LOADERMID.js"
# Main application package build configuration
-PROFILE="$SRCDIR/app/app.profile.js"
+PROFILE="$BASEDIR/profiles/app.profile.js"
# Configuration over. Main application start up!
if [ ! -d "$TOOLSDIR" ]; then
- echo "Can't find Dojo build tools -- did you initialise submodules? (git submodule update --init --recursive)"
- exit 1
+ echo "Can't find Dojo build tools -- did you initialise submodules? (git submodule update --init --recursive)"
+ exit 1
fi
echo "Building application with $PROFILE to $DISTDIR."
@@ -39,12 +39,12 @@ echo " Done"
cd "$TOOLSDIR"
if which node >/dev/null; then
- node ../../dojo/dojo.js load=build --require "$LOADERCONF" --profile "$PROFILE" --releaseDir "$DISTDIR" "$@"
+ node ../../dojo/dojo.js load=build --require "$LOADERCONF" --profile "$PROFILE" --releaseDir "$DISTDIR" $@
elif which java >/dev/null; then
- java -Xms256m -Xmx256m -cp ../shrinksafe/js.jar:../closureCompiler/compiler.jar:../shrinksafe/shrinksafe.jar org.mozilla.javascript.tools.shell.Main ../../dojo/dojo.js baseUrl=../../dojo load=build --require "$LOADERCONF" --profile "$PROFILE" --releaseDir "$DISTDIR" "$@"
+ java -Xms256m -Xmx256m -cp ../shrinksafe/js.jar:../closureCompiler/compiler.jar:../shrinksafe/shrinksafe.jar org.mozilla.javascript.tools.shell.Main ../../dojo/dojo.js baseUrl=../../dojo load=build --require "$LOADERCONF" --profile "$PROFILE" --releaseDir "$DISTDIR" $@
else
- echo "Need node.js or Java to build!"
- exit 1
+ echo "Need node.js or Java to build!"
+ exit 1
fi
cd "$BASEDIR"
View
107 profiles/app.profile.js
@@ -0,0 +1,107 @@
+/**
+ * This is the default application build profile used by the boilerplate. While it looks similar, this build profile
+ * is different from the package build profile at `app/package.js` in the following ways:
+ *
+ * 1. you can have multiple application build profiles (e.g. one for desktop, one for tablet, etc.), but only one
+ * package build profile;
+ * 2. the package build profile only configures the `resourceTags` for the files in the package, whereas the
+ * application build profile tells the build system how to build the entire application.
+ *
+ * Look to `util/build/buildControlDefault.js` for more information on available options and their default values.
+ */
+
+var profile = {
+ // `basePath` is relative to the directory containing this profile file; in this case, it is being set to the
+ // src/ directory, which is the same place as the `baseUrl` directory in the loader configuration. (If you change
+ // this, you will also need to update run.js.)
+ basePath: '../src/',
+
+ // This is the directory within the release directory where built packages will be placed. The release directory
+ // itself is defined by `build.sh`. You should probably not use this; it is a legacy option dating back to Dojo
+ // 0.4.
+ // If you do use this, you will need to update build.sh, too.
+ // releaseName: '',
+
+ // Builds a new release.
+ action: 'release',
+
+ // Strips all comments and whitespace from CSS files and inlines @imports where possible.
+ cssOptimize: 'comments',
+
+ // Excludes tests, demos, and original template files from being included in the built version.
+ mini: true,
+
+ // Uses Closure Compiler as the JavaScript minifier. This can also be set to "shrinksafe" to use ShrinkSafe,
+ // though ShrinkSafe is deprecated and not recommended.
+ // This option defaults to "" (no compression) if not provided.
+ optimize: 'closure',
+
+ // We're building layers, so we need to set the minifier to use for those, too.
+ // This defaults to "shrinksafe" if not provided.
+ layerOptimize: 'closure',
+
+ // Strips all calls to console functions within the code. You can also set this to "warn" to strip everything
+ // but console.error, and any other truthy value to strip everything but console.warn and console.error.
+ // This defaults to "normal" (strip all but warn and error) if not provided.
+ stripConsole: 'all',
+
+ // The default selector engine is not included by default in a dojo.js build in order to make mobile builds
+ // smaller. We add it back here to avoid that extra HTTP request. There is also a "lite" selector available; if
+ // you use that, you will need to set the `selectorEngine` property in `app/run.js`, too. (The "lite" engine is
+ // only suitable if you are not supporting IE7 and earlier.)
+ selectorEngine: 'acme',
+
+ // Builds can be split into multiple different JavaScript files called "layers". This allows applications to
+ // defer loading large sections of code until they are actually required while still allowing multiple modules to
+ // be compiled into a single file.
+ layers: {
+ // This is the main loader module. It is a little special because it is treated like an AMD module even though
+ // it is actually just plain JavaScript. There is some extra magic in the build system specifically for this
+ // module ID.
+ 'dojo/dojo': {
+ // In addition to the loader `dojo/dojo` and the loader configuration file `app/run`, we are also including
+ // the main application `app/main` and the `dojo/i18n` and `dojo/domReady` modules because, while they are
+ // all conditional dependencies in `app/main`, we do not want to have to make extra HTTP requests for such
+ // tiny files.
+ include: [ 'dojo/i18n', 'dojo/domReady', 'app/main', 'app/run' ],
+
+ // By default, the build system will try to include `dojo/main` in the built `dojo/dojo` layer, which adds
+ // a bunch of stuff we do not want or need. We want the initial script load to be as small and quick to
+ // load as possible, so we configure it as a custom, bootable base.
+ boot: true,
+ customBase: true
+ },
+
+ // In the demo application, we conditionally require `app/Dialog` on the client-side, so here we build a
+ // separate layer containing just that client-side code. (Practically speaking, you would probably just want
+ // to roll everything into a single layer, but this helps provide a basic illustration of multi-layer builds.)
+ // Note that when you create a new layer, the module referenced by the layer is always included in the layer
+ // (in this case, `app/Dialog`), so it does not need to be explicitly defined in the `include` array.
+ 'app/Dialog': {}
+ },
+
+ // Providing hints to the build system allows code to be conditionally removed on a more granular level than
+ // simple module dependencies can allow. This is especially useful for creating tiny mobile builds.
+ // Keep in mind that dead code removal only happens in minifiers that support it! Currently, only Closure Compiler
+ // to the Dojo build system with dead code removal.
+ // A documented list of has-flags in use within the toolkit can be found at
+ // <http://dojotoolkit.org/reference-guide/dojo/has.html>.
+ staticHasFeatures: {
+ // The trace & log APIs are used for debugging the loader, so we do not need them in the build.
+ 'dojo-trace-api': 0,
+ 'dojo-log-api': 0,
+
+ // This causes normally private loader data to be exposed for debugging. In a release build, we do not need
+ // that either.
+ 'dojo-publish-privates': 0,
+
+ // This application is pure AMD, so get rid of the legacy loader.
+ 'dojo-sync-loader': 0,
+
+ // `dojo-xhr-factory` relies on `dojo-sync-loader`, which we have removed.
+ 'dojo-xhr-factory': 0,
+
+ // We are not loading tests in production, so we can get rid of some test sniffing code.
+ 'dojo-test-sniff': 0
+ }
+};
View
10 src/app/Dialog.js
@@ -1,10 +1,10 @@
/**
- * This file is a very simple example of a class declaration in Dojo. It defines the app/Dialog module as a new
+ * This file is a very simple example of a class declaration in Dojo. It defines the `app/Dialog` module as a new
* class that extends a dijit Dialog and overrides the default title and content properties.
*/
define([ 'dojo/_base/declare', 'dijit/Dialog' ], function (declare, Dialog) {
- return declare(Dialog, {
- title: 'Hello World',
- content: 'Loaded successfully!'
- });
+ return declare(Dialog, {
+ title: 'Hello World',
+ content: 'Loaded successfully!'
+ });
});
View
129 src/app/app.profile.js
@@ -1,129 +0,0 @@
-/**
- * This is a new Dojo 1.7 style build profile. Look at util/build/buildControlDefault.js if you want to explore the
- * default Dojo build profile options.
- */
-
-// This function is used to determine whether or not a resource should be tagged as copy-only. See the resourceTags
-// property below for more information.
-function copyOnly(mid) {
- return mid in {
- // There are no modules right now in dojo boilerplate that are copy-only. If you have some, though, just add
- // them here like this:
- // 'app/module': 1
- };
-}
-
-var profile = {
- // basePath is relative to the directory containing this profile file; in this case, it is being set to the
- // src/ directory, which is the same place as the baseUrl directory in the loader configuration. (If you change
- // this, you will also need to update run.js).
- basePath: '..',
-
- // This is the directory within the release directory where built packages will be placed. The release directory
- // itself is defined by build.sh. You really probably should not use this; it is a legacy option from very old
- // versions of Dojo (like, version 0.1). If you do use it, you will need to update build.sh, too.
- // releaseName: '',
-
- // Builds a new release.
- action: 'release',
-
- // Strips all comments from CSS files.
- cssOptimize: 'comments',
-
- // Excludes tests, demos, and original template files from being included in the built version.
- mini: true,
-
- // Uses Closure Compiler as the JavaScript minifier. This can also be set to "shrinksafe" to use ShrinkSafe.
- // Note that you will probably get some “errors” with CC; these are generally safe to ignore, and will be
- // fixed in a later version of Dojo. This defaults to "" (no compression) if not provided.
- optimize: 'closure',
-
- // We’re building layers, so we need to set the minifier to use for those, too. This defaults to "shrinksafe" if
- // it is not provided.
- layerOptimize: 'closure',
-
- // Strips all calls to console functions within the code. You can also set this to "warn" to strip everything
- // but console.error, and any other truthy value to strip everything but console.warn and console.error.
- stripConsole: 'all',
-
- // The default selector engine is not included by default in a dojo.js build in order to make mobile builds
- // smaller. We add it back here to avoid that extra HTTP request. There is also a "lite" selector available; if
- // you use that, you’ll need to set selectorEngine in app/run.js too. (The "lite" engine is only suitable if you
- // are not supporting IE7 and earlier.)
- selectorEngine: 'acme',
-
- // Builds can be split into multiple different JavaScript files called “layers”. This allows applications to
- // defer loading large sections of code until they are actually required while still allowing multiple modules to
- // be compiled into a single file.
- layers: {
- // This is the main loader module. It is a little special because it is treated like an AMD module even though
- // it is actually just plain JavaScript. There is some extra magic in the build system specifically for this
- // module ID.
- 'dojo/dojo': {
- // In addition to the loader (dojo/dojo) and the loader configuration file (app/run), we’re also including
- // the main application (app/main) and the dojo/i18n and dojo/domReady modules because they are one of the
- // conditional dependencies in app/main (the other being app/Dialog) but we don’t want to have to make
- // extra HTTP requests for such tiny files.
- include: [ 'dojo/dojo', 'dojo/i18n', 'dojo/domReady', 'app/main', 'app/run' ],
-
- // By default, the build system will try to include dojo/main in the built dojo/dojo layer, which adds a
- // bunch of stuff we don’t want or need. We want the initial script load to be as small and quick as
- // possible, so we configure it as a custom, bootable base.
- boot: true,
- customBase: true
- },
-
- // In the demo application, we conditionally require app/Dialog on the client-side, so we’re building a
- // separate layer containing just that client-side code. (Practically speaking, you’d probably just want
- // to roll everything into a single layer, but I wanted to make sure to illustrate multi-layer builds.)
- 'app/Dialog': { include: [ 'app/Dialog' ] }
- },
-
- // Providing hints to the build system allows code to be conditionally removed on a more granular level than
- // simple module dependencies can allow. This is especially useful for creating tiny mobile builds.
- // Keep in mind that dead code removal only happens in minifiers that support it! Currently, ShrinkSafe does not
- // support dead code removal; Closure Compiler and UglifyJS do.
- staticHasFeatures: {
- // The trace & log APIs are used for debugging the loader, so we don’t need them in the build
- 'dojo-trace-api':0,
- 'dojo-log-api':0,
-
- // This causes normally private loader data to be exposed for debugging, so we don’t need that either
- 'dojo-publish-privates':0,
-
- // We’re fully async, so get rid of the legacy loader
- 'dojo-sync-loader':0,
-
- // dojo-xhr-factory relies on dojo-sync-loader
- 'dojo-xhr-factory':0,
-
- // We aren’t loading tests in production
- 'dojo-test-sniff':0
- },
-
- // Resource tags are functions that provide hints to the compiler about a given file. The first argument is the
- // filename of the file, and the second argument is the module ID for the file.
- resourceTags: {
- // Files that contain test code.
- test: function (filename, mid) {
- return false;
- },
-
- // Files that should be copied as-is without being modified by the build system.
- copyOnly: function (filename, mid) {
- return copyOnly(mid);
- },
-
- // Files that are AMD modules.
- amd: function (filename, mid) {
- return !copyOnly(mid) && /\.js$/.test(filename);
- },
-
- // Files that should not be copied when the “mini” compiler flag is set to true.
- miniExclude: function (filename, mid) {
- return mid in {
- 'app/profile': 1
- };
- }
- }
-};
View
79 src/app/main.js
@@ -1,50 +1,57 @@
/**
- * This file is your applications main JavaScript file. It is listed as a dependency in run.js and will
- * automatically load when run.js loads.
+ * This file is the application's main JavaScript file. It is listed as a dependency in run.js and will automatically
+ * load when run.js loads.
*
- * Because this file has the special filename main.js, and because weve registered the app package in run.js,
- * whatever object this module returns can be loaded by other files simply by requiring app (instead of app/main).
+ * Because this file has the special filename `main.js`, and because we've registered the `app` package in run.js,
+ * whatever object this module returns can be loaded by other files simply by requiring `app` (instead of `app/main`).
*
- * Our first dependency is to the dojo/has module, which allows us to conditionally execute code based on
+ * Our first dependency is to the `dojo/has` module, which allows us to conditionally execute code based on
* configuration settings or environmental information. Unlike a normal conditional, these branches can be compiled
- * away by the build system; see staticHasFeatures in app.profile.js for more information.
+ * away by the build system; see `staticHasFeatures` in app.profile.js for more information.
*
- * Our second dependency is to the special module require; this allows us to make additional require calls using
- * relative module IDs within the body of our define function.
+ * Our second dependency is to the special module `require`; this allows us to make additional require calls using
+ * module IDs relative to this module within the body of the define callback.
*
- * In all cases, whatever function is passed to define() is only invoked once, and the return value is cached.
+ * In all cases, whatever function is passed to define() is only invoked once, and the returned value is cached.
*
* More information about everything described about the loader throughout this file can be found at
- * http://livedocs.dojotoolkit.org/loader/amd.
+ * <http://dojotoolkit.org/reference-guide/loader/amd.html>.
*/
define([ 'dojo/has', 'require' ], function (has, require) {
- var app = {};
+ var app = {};
- if (has('host-browser')) {
- /*
- * This require call’s first dependency, “./Dialog”, uses a relative module identifier; you should use this
- * type of notation for dependencies *within* a package in order to ensure the package is fully portable. It
- * works like a path, where “./” refers to the current directory and “../” refers to the parent directory. If
- * you are referring to a module in a *different* package, you should *not* use a relative module identifier.
- *
- * The second dependency is a plugin dependency; in this case, it is a dependency on the special functionality
- * of the “dojo/domReady” plugin, which waits until the DOM is ready before finishing loading.
- * The “!” after the module name indicates you want to use special plugin functionality; if you were to
- * require just “dojo/domReady”, it would load that module just like any other module, without any of the
- * special plugin functionality.
- */
- require([ './Dialog', 'dojo/domReady!' ], function (Dialog) {
- app.dialog = new Dialog().placeAt(document.body);
+ /**
+ * This main.js file conditionally executes different code depending upon the host environment it is loaded in.
+ * This is an increasingly common pattern when dealing with applications that run in different environments that
+ * require different functionality (i.e. client/server or desktop/tablet/phone).
+ */
+ if (has('host-browser')) {
+ /*
+ * This require call's first dependency, `./Dialog`, uses a relative module identifier; you should use this
+ * type of notation for dependencies *within* a package in order to ensure the package is fully portable. It
+ * works like a path, where `./` refers to the current directory and `../` refers to the parent directory. If
+ * you are referring to a module in a *different* package (like `dojo` or `dijit`), you should *not* use a
+ * relative module identifier.
+ *
+ * The second dependency is a plugin dependency; in this case, it is a dependency on the special functionality
+ * of the `dojo/domReady` plugin, which simply waits until the DOM is ready before resolving.
+ * The `!` after the module name indicates you want to use special plugin functionality; if you were to
+ * require just `dojo/domReady`, it would load that module just like any other module, without the special
+ * plugin functionality.
+ */
+ require([ './Dialog', 'dojo/domReady!' ], function (Dialog) {
+ app.dialog = new Dialog().placeAt(document.body);
- // It is important to remember to always call startup on widgets after you have added them to the DOM.
- // It won’t hurt if you do it twice, but things will often not work right if you forget to do it.
- app.dialog.startup();
+ // It is important to remember to always call startup on widgets after you have added them to the DOM.
+ // It will not hurt if you do it twice, but things will often not work right if you forget to do it.
+ app.dialog.startup();
- // And now…
- app.dialog.show();
- });
- }
- else {
- console.log('Hello from the server!');
- }
+ // And now we just show the dialog to demonstrate that, yes, the example app has loaded successfully.
+ app.dialog.show();
+ });
+ }
+ else {
+ // TODO: Eventually, the Boilerplate will actually have a useful server implementation here :)
+ console.log('Hello from the server!');
+ }
});
View
43 src/app/package.js
@@ -0,0 +1,43 @@
+/**
+ * This file is referenced by the `dojoBuild` key in `package.json` and provides extra hinting specific to the Dojo
+ * build system about how certain files in the package need to be handled at build time. Build profiles for the
+ * application itself are stored in the `profiles` directory.
+ */
+
+var profile = {
+ // Resource tags are functions that provide hints to the build system about the way files should be processed.
+ // Each of these functions is called once for every file in the package directory. The first argument passed to
+ // the function is the filename of the file, and the second argument is the computed AMD module ID of the file.
+ resourceTags: {
+ // Files that contain test code and should be excluded when the `copyTests` build flag exists and is `false`.
+ // It is strongly recommended that the `mini` build flag be used instead of `copyTests`. Therefore, no files
+ // are marked with the `test` tag here.
+ test: function (filename, mid) {
+ return false;
+ },
+
+ // Files that should be copied as-is without being modified by the build system.
+ // All files in the `app/resources` directory that are not CSS files are marked as copy-only, since these files
+ // are typically binaries (images, etc.) and may be corrupted by the build system if it attempts to process
+ // them and naively assumes they are scripts.
+ copyOnly: function (filename, mid) {
+ return (/^app\/resources\//.test(filename) && !/\.css$/.test(filename));
+ },
+
+ // Files that are AMD modules.
+ // All JavaScript in this package should be AMD modules if you are starting a new project. If you are copying
+ // any legacy scripts from an existing project, those legacy scripts should not be given the `amd` tag.
+ amd: function (filename, mid) {
+ return !this.copyOnly(filename, mid) && /\.js$/.test(filename);
+ },
+
+ // Files that should not be copied when the `mini` build flag is set to true.
+ // In this case, we are excluding this package configuration file which is not necessary in a built copy of
+ // the application.
+ miniExclude: function (filename, mid) {
+ return mid in {
+ 'app/package': 1
+ };
+ }
+ }
+};
View
48 src/app/package.json
@@ -1,26 +1,26 @@
{
- "name": "app",
- "version": "1.0",
- "main": "main",
- "dependencies": {
- "dojo": "current",
- "dijit": "current",
- "dojox": "current",
- "util": "current"
- },
- "description": "Dojo Boilerplate Example Application. A quick-start application that demonstrates basic usage of the Dojo Toolkit. This package.json file is a CommonJS Packages/1.0 manifest, with a special dojoBuild property to point to the build file for this package. (This is more useful for library packages than the main application package.)",
- "licenses": [
- {
- "type": "AFLv2.1",
- "url": "http://trac.dojotoolkit.org/browser/dojo/trunk/LICENSE#L43"
- },
- {
- "type": "BSD",
- "url": "http://trac.dojotoolkit.org/browser/dojo/trunk/LICENSE#L13"
- }
- ],
- "bugs": "https://github.com/csnover/dojo-boilerplate/issues",
- "keywords": ["JavaScript", "Dojo", "Boilerplate", "Example", "Howto"],
- "homepage": "https://github.com/csnover/dojo-boilerplate",
- "dojoBuild": "app.profile.js"
+ "name": "app",
+ "version": "1.0",
+ "main": "main",
+ "dependencies": {
+ "dojo": "1.8.0",
+ "dijit": "1.8.0",
+ "dojox": "1.8.0",
+ "util": "1.8.0"
+ },
+ "description": "Dojo Boilerplate Example Application. A quick-start application that demonstrates basic usage of the Dojo Toolkit. This package.json file is a CommonJS Packages/1.0 manifest, with a special `dojoBuild` property to point to the build file for this package.",
+ "licenses": [
+ {
+ "type": "AFLv2.1",
+ "url": "http://bugs.dojotoolkit.org/browser/dojo/trunk/LICENSE#L43"
+ },
+ {
+ "type": "BSD",
+ "url": "http://bugs.dojotoolkit.org/browser/dojo/trunk/LICENSE#L13"
+ }
+ ],
+ "bugs": "https://github.com/csnover/dojo-boilerplate/issues",
+ "keywords": ["JavaScript", "Dojo", "Boilerplate", "Example", "Howto"],
+ "homepage": "https://github.com/csnover/dojo-boilerplate",
+ "dojoBuild": "package.js"
}
View
2 src/app/resources/app.css
@@ -3,7 +3,7 @@
* below; otherwise, you can remove them. When building for release, Dojo will automatically combine all of your
* @imported CSS files into a single file.
*
- * It is highly, highly recommended that you develop your CSS using LESS: http://lesscss.org.
+ * It is highly, highly recommended that you develop your CSS using Stylus: http://learnboost.github.com/stylus/.
*/
@import '../../dojo/resources/dojo.css';
View
49 src/app/run.js
@@ -1,38 +1,31 @@
/**
- * This file is used to reconfigure parts of the loader at runtime for this application. Weve put this extra
+ * This file is used to reconfigure parts of the loader at runtime for this application. We've put this extra
* configuration in a separate file, instead of adding it directly to index.html, because it contains options that
* can be shared if the application is run on both the client and the server.
*
- * If you arent planning on running your app on both the client and the server, you could easily move this
+ * If you aren't planning on running your app on both the client and the server, you could easily move this
* configuration into index.html (as a dojoConfig object) if it makes your life easier.
*/
require({
- // The base path for all packages and modules. If you don't provide this, baseUrl defaults to the directory
- // that contains dojo.js. Since all packages are in the root, we just leave it blank. (If you change this, you
- // will also need to update app.profile.js).
- baseUrl: '',
+ // The base path for all packages and modules. If you don't provide this, baseUrl defaults to the directory
+ // that contains dojo.js. Since all packages are in the root, we just leave it blank. (If you change this, you
+ // will also need to update `app.profile.js`).
+ baseUrl: '',
- // A list of packages to register. Strictly speaking, you do not need to register any packages,
- // but you can't require "app" and get app/main.js if you do not register the "app" package (the loader will look
- // for a module at <baseUrl>/app.js instead). Unregistered packages also cannot use the packageMap feature, which
- // might be important to you if you need to relocate dependencies. TL;DR, register all your packages all the time:
- // it will make your life easier.
- packages: [
- // If you are registering a package that has an identical name and location, you can just pass a string
- // instead, and it will configure it using that string for both the "name" and "location" properties. Handy!
- 'dojo',
- 'dijit',
- 'dojox',
- 'app',
+ // A list of packages to register. Strictly speaking, you do not need to register any packages,
+ // but you can't require "app" and get app/main.js if you do not register the "app" package (the loader will look
+ // for a module at <baseUrl>/app.js instead). Unregistered packages also cannot use the `map` feature, which
+ // might be important to you if you need to relocate dependencies. TL;DR, register all your packages all the time:
+ // it will make your life easier.
+ packages: [
+ // If you are registering a package that has an identical name and location, you can just pass a string
+ // instead, and it will configure it using that string for both the "name" and "location" properties. Handy!
+ 'dojo',
+ 'dijit',
+ 'dojox',
- // For reference, this is what a more verbose package declaration looks like.
- { name: 'dbp', location: 'dbp', packageMap: {} }
- ],
-
- // This is a hack. In order to allow app/main and app/run to be built together into a single file, a cache key needs
- // to exist here in order to force the loader to actually process the other modules in the file. Without this hack,
- // the loader will think that code for app/main has not been loaded yet and will try to fetch it again, resulting in
- // a needless extra HTTP request.
- cache: {}
-// Require 'app'. This loads the main application file, app/main.js.
+ // For reference, this is what a more verbose package declaration looks like.
+ { name: 'app', location: 'app', map: {} }
+ ]
+// Require `app`. This loads the main application module, `app/main`, since we registered the `app` package above.
}, [ 'app' ]);
View
278 src/dbp/Router.js
@@ -1,278 +0,0 @@
-/**
- * THIS FILE IS A WORK IN PROGRESS AND MOST LIKELY
- * DOES NOT WORK AT THE MOMENT. YOU HAVE BEEN WARNED.
- */
-dojo.provide("dbp.Router");
-
-dojo.require("dojo.hash");
-
-/**
- * dbp.Router provides an API for specifying hash-based URLs ("routes") and
- * the functionality associated with each. It allows the routes to include both
- * path and query string parameters which are then available inside the
- * handling function:
- *
- * /things/:id -> #/things/3
- * /things -> #/things?id=3&color=red
- *
- * Defining a route involves providing a path for the route, and a function to
- * run for the route. The function receives two arguments: an object containing
- * the parameters associated with the route, if any; and an object containing
- * information about the route that was run.
- *
- * Example usage
- *
- * var myRouter = new dbp.Router([
- * {
- * path : "/foo/:bar",
- * handler : function(params) { },
- * defaultRoute : true
- * }
- * ]);
- *
- * myRouter.init();
- *
- * This router was heavily inspired by Sammy.js, a full-featured router
- * for jQuery projects. http://sammyjs.org/
- */
-
-(function(d){
-
-var routes = [],
- routeCache = {},
- currentPath,
- connections = [],
- subscriptions = [],
-
- PATH_REPLACER = "([^\/]+)",
- PATH_NAME_MATCHER = /:([\w\d]+)/g,
-
- hasHistoryState = "onpopstate" in window;
-
-dojo.declare('dbp.Router', null, {
- constructor : function(userRoutes) {
- if (!userRoutes || !userRoutes.length) {
- throw "No routes provided to dbp.Router.";
- }
-
- if (routes.length) {
- console.warn("An instance of dbp.Router already exists. You may want to create another one, but it's unlikely.");
- }
-
-
- d.forEach(userRoutes, function(r) {
- this._registerRoute(r.path, r.handler, r.defaultRoute);
- }, this);
-
- // use the first route as the default if one
- // is not marked as the default
- if (!this.defaultRoute) {
- this.defaultRoute = userRoutes[0];
- }
-
- },
-
- /**
- * Initialization method; looks at current hash and handles,
- * else uses default route to get started
- */
- init : function() {
- this.go(window.location.hash || this.defaultRoute.path);
-
- if (hasHistoryState) {
- connections.push(d.connect(window, "onpopstate", this, function() {
- this._handle(window.location.hash);
- }));
- } else {
- subscriptions.push(d.subscribe("/dojo/hashchange", this, "_handle"));
- }
- },
-
- /**
- * Redirect to a path
- * @param {String} path
- */
- go : function(path) {
- path = dojo.trim(path);
- if (!path) { return; }
-
- this._handle(path);
-
- if (path.indexOf("#") !== 0) {
- path = "#" + path;
- }
-
- if (hasHistoryState) {
- history.pushState(null, null, path);
- } else {
- window.location.hash = path;
- }
- },
-
- /**
- * When the router observes navigation to a new hash, it passes
- * the hash to this function to be handled.
- *
- * @param {String} The hash to which the user navigated
- */
- _handle : function(hash) {
- if (hash === currentPath) { return; }
- currentPath = hash;
-
- var path = hash.replace("#",""),
-
- route = this._chooseRoute(this._getRouteablePath(path)) ||
- this.defaultRoute;
-
- params = this._parseParams(path, route);
-
- route = d.mixin(route, {
- hash : hash,
- params : params
- });
-
- route.handler(params, route);
- },
-
- /**
- * Find the route to use for a given path
- */
- _chooseRoute : function(path) {
- var routeablePath;
-
- if (!routeCache[path]) {
- routeablePath = this._getRouteablePath(path);
- d.forEach(routes, function(r) {
- if (routeablePath.match(r.matcher)) { routeCache[path] = r; }
- });
- }
-
- return routeCache[path];
- },
-
- /**
- * Register a route with the router. Generally only used internally,
- * but exposed for external use as well.
- *
- * @param {Regex|String} path The path pattern to which the route applies
- * @param {Function} fn The handler to use for the route
- * @param {Boolean} defaultRoute Whether the route should be used as
- * the default route.
- */
- _registerRoute : function(path, fn, defaultRoute) {
- var r = {
- path : path,
- handler : fn,
- matcher : this._convertPathToMatcher(path),
- paramNames : this._getParamNames(path)
- };
-
- routes.push(r);
-
- if (defaultRoute) { this.defaultRoute = r; }
- },
-
- /**
- * Given a path, which may be a regex or a string, return a regex
- * that can be used to determine whether to use the associated route
- * to process a given path.
- *
- * @private
- * @param {Regex|String} route
- * @returns Regex for determining whether a path matches the route
- * @type {Regex}
- */
- _convertPathToMatcher : function(route) {
- return d.isString(route) ?
- new RegExp("^" + route.replace(PATH_NAME_MATCHER, PATH_REPLACER) + "$") :
- route;
- },
-
- /**
- * Given a path to which a user navigated, and the route that we've
- * determined should handle the path, return an object containg the parameter
- * name(s) and value(s)
- *
- * @private
- * @param {String} hash The hash to which a user navigated
- * @param {Route} route The route
- * @returns A params object containing parameter keynames and values
- * @type {Object}
- */
- _parseParams : function(hash, route) {
- // TODO
- var parts = hash.split('?'),
- path = parts[0],
- query = parts[1],
- params,
- pathParams,
- _decode = decodeURIComponent;
-
- params = query ? d.mixin({}, d.queryToObject(query)) : {};
-
- if ((pathParams = route.matcher.exec(this._getRouteablePath(path))) !== null) {
- // first match is the full path
- pathParams.shift();
-
- // for each of the matches
- d.forEach(pathParams, function(param, i) {
- // if theres a matching param name
- if (route.paramNames[i]) {
- // set the name to the match
- params[route.paramNames[i]] = _decode(param);
- } else {
- // initialize 'splat'
- if (!params.splat) { params.splat = []; }
- params.splat.push(_decode(param));
- }
- });
- }
-
- return params;
- },
-
- /**
- * Given a path that may contain a query string:
- *
- * /foo/bar?baz=1
- *
- * Return a string that does not contain the query string, so we
- * can use the string for matching to a route.
- *
- * @private
- * @param {String} path
- */
- _getRouteablePath : function(path) {
- return path.split('?')[0];
- },
-
- /**
- * Given a route, which could be a string or a regex, return
- * the parameter names expected by the route as an array.
- *
- * @param {Regex|String} path The path specified for a route
- * @returns An array of parameter names
- * @type Array
- */
- _getParamNames : function(path) {
- var pathMatch,
- paramNames = [];
-
- PATH_NAME_MATCHER.lastIndex = 0;
-
- while ((pathMatch = PATH_NAME_MATCHER.exec(path)) !== null) {
- paramNames.push(pathMatch[1]);
- }
-
- return paramNames;
- },
-
- destroy : function() {
- dojo.forEach(connections, d.disconnect);
- dojo.forEach(subscriptions, d.unsubscribe);
- routes = [];
- }
-});
-
-}(dojo));
-
View
11 src/dbp/tests/Router.html
@@ -1,11 +0,0 @@
-<!doctype html>
-<html>
- <head>
- <title>Dojo Unit Test Runner</title>
- <meta http-equiv="REFRESH" content="0;url=../../dojo-release-1.6.0-src/util/doh/runner.html?registerModulePath=dbp,../../dbp;&amp;testModule=dbp.tests.Router">
- </head>
- <body>
- Redirecting to D.O.H runner.
- </body>
-</html>
-
View
109 src/dbp/tests/Router.js
@@ -1,109 +0,0 @@
-dojo.provide('dbp.tests.Router');
-
-dojo.require('dbp.Router');
-
-(function() {
-
-var testVal,
-
- routes = [
- {
- path : '/test',
- handler : function() {
- testVal = '/test';
- },
- defaultRoute : true
- },
- {
- path : '/test2',
- handler : function() {
- testVal = '/test2';
- }
- },
- {
- path : '/basic',
- handler : function() {
- testVal = 'basic';
- }
- },
- {
- path : '/bar/:baz',
- handler : function(params) {
- testVal = params.baz;
- }
- },
- {
- path : '/bar/:baz/:bim',
- handler : function(params) {
- testVal = params.baz + params.bim;
- }
- },
- {
- path : '/bar/:baz/bim/:bop',
- handler : function(params) {
- testVal = params.baz + params.bop;
- }
- },
- {
- path : /\/splat\/(.*)/,
- handler : function(params) {
- testVal = params.splat[0];
- }
- },
- {
- path : /\/splat\/(.*)\/foo\/(.*)/,
- handler : function(params) {
- testVal = params.splat[0] + ':' + params.splat[1];
- }
- }
- ];
-
-doh.register('dbp.Router', [
-
- {
- name : "It should handle a hash if one is set when initialized",
- setUp : function() {
- this.router = new dbp.Router(routes);
- },
- runTest : function() {
- window.location.hash = '#/test';
- this.router.init();
- doh.is(testVal, '/test');
- },
- tearDown : function() {
- this.router.destroy();
- }
- },
-
- {
- name : "It should route the request to the appropriate route with the appropriate parameters",
- setUp : function() {
- this.router = new dbp.Router(routes);
- },
- runTest : function() {
- this.router.go('/bar/test-123');
- doh.is(testVal, 'test-123');
-
- this.router.go('/basic');
- doh.is(testVal, 'basic');
-
- this.router.go('/bar/hello/world');
- doh.is(testVal, 'helloworld');
-
- this.router.go('/bar/testing/bim/123');
- doh.is(testVal, 'testing123');
-
- this.router.go('/splat/1/2/3');
- doh.is(testVal, '1/2/3');
-
- this.router.go('/splat/1/2/3/foo/4/5/6');
- doh.is(testVal, '1/2/3:4/5/6');
- },
- tearDown : function() {
- this.router.destroy();
- }
- }
-
-]);
-
-}());
2 src/dijit
@@ -1 +1 @@
-Subproject commit 18f1bb1bf1d479aa16a68ff859db7e9759d1711c
+Subproject commit ef9e7bf5df60a8a74f7e7a7eeaf859b9df3b09b6
2 src/dojo
@@ -1 +1 @@
-Subproject commit 2e1e84ecd7829b9f17311ffb621fbfba27653aab
+Subproject commit 2d9bb030ed4587473b6d2e1d338c0a552d783aac
2 src/dojox
@@ -1 +1 @@
-Subproject commit 8dc197aa90ebdcd5eeace9ebc68d61037989f344
+Subproject commit bae5b676e32877b0a20cdd27fa1f4f2d9a4bb7c4
View
12 src/index.html
@@ -12,7 +12,7 @@
as shown here, from a global dojoConfig object (which must be defined *before* dojo.js is loaded), or from
a global require object.
- Configuration options for the loader can be viewed at http://livedocs.dojotoolkit.org/loader/amd
+ Configuration options for the loader can be viewed at http://dojotoolkit.org/reference-guide/loader/amd.html
along with a bunch of additional information about its features.
Below, we’re doing the following:
@@ -24,13 +24,15 @@
3. Enabling debugging. (isDebug: 1)
The remainder of Dojo configuration, as well as our application’s instantiation, occurs within
- app/run.js. -->
- <script data-dojo-config="async: 1, tlmSiblingOfDojo: 0, isDebug: 1"
- src="dojo/dojo.js" defer></script>
+ app/run.js.
+
+ NOTE: `build.sh` is responsible for removing the "isDebug" flag when deploying to production. If you modify
+ this flag at all, you will break the build! -->
+ <script data-dojo-config="async: 1, tlmSiblingOfDojo: 0, isDebug: 1" src="dojo/dojo.js"></script>
<!-- Load the loader configuration script. Note that this module ID is hard-coded in build.sh in order to provide
an optimised build that loads as few as one script for the entire application. If you change the name or
location of this module, you will need to update build.sh too. -->
- <script src="app/run.js" defer></script>
+ <script src="app/run.js"></script>
</body>
</html>
View
4 src/server.sh
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/usr/bin/env bash
# This is a very simple script that demonstrates how to load a Dojo
# application on the server using Node.js.
-node dojo/dojo.js load=app/run
+node dojo/dojo.js load=app/run $@
2 src/util
@@ -1 +1 @@
-Subproject commit 859717b49f74bab670a2d9d94029d65fc2d9a65b
+Subproject commit 46d61804c75d787ba70ff7cd251e341cce8c15dd

0 comments on commit f35c479

Please sign in to comment.