From 608154336dbafec7dee4c86ac06e4c7f88eec7e5 Mon Sep 17 00:00:00 2001 From: Eric Fong Date: Fri, 7 Nov 2014 15:46:40 +0800 Subject: [PATCH 01/20] Use map SiteSucker app to download whole site and put it into gh-page to try --- _00.txt | 1 + _downloads.html | 2 + api.html | 581 + docs/basics-include=all.html | 414 + docs/basics/cli.md.html | 376 + docs/basics/public.md.html | 334 + docs/basics/source-control.md.html | 328 + docs/collections-include=all.html | 2113 +++ .../collections/accessing-collections.md.html | 524 + docs/collections/adding-logic.md.html | 551 + .../advanced-guides-include=all.html | 548 + .../advanced-guides/custom-client.md.html | 533 + docs/collections/creating-collections.md.html | 513 + docs/collections/examples-include=all.html | 530 + .../a-simple-todo-app-with-angular.md.html | 471 + .../a-simple-todo-app-with-backbone.md.html | 471 + .../examples/a-simple-todo-app.md.html | 470 + docs/collections/examples/chatroom.md.html | 472 + docs/collections/notifying-clients.md.html | 525 + docs/collections/reference-include=all.html | 1621 ++ docs/collections/reference/dpd-js.md.html | 757 + docs/collections/reference/event-api.md.html | 727 + docs/collections/reference/http.md.html | 877 + .../reference/querying-collections.md.html | 583 + .../reference/updating-objects.md.html | 514 + .../relationships-between-collections.md.html | 609 + docs/developing-modules-include=all.html | 1632 ++ .../creating-modules.md.html | 522 + .../custom-resource-types.md.html | 662 + .../examples-include=all.html | 525 + .../developing-modules/examples/email.md.html | 490 + .../developing-modules/examples/event.md.html | 490 + docs/developing-modules/examples/s3.md.html | 490 + .../internal-api-include=all.html | 1416 ++ .../internal-api/collection.md.html | 593 + .../internal-api/context.md.html | 551 + .../internal-api/internal-client.md.html | 600 + .../internal-api/resource.md.html | 838 + .../internal-api/script.md.html | 571 + .../internal-api/server.md.html | 564 + .../internal-api/session-store.md.html | 546 + .../internal-api/session.md.html | 592 + .../internal-api/store.md.html | 578 + docs/getting-started-include=all.html | 734 + docs/getting-started/faq.md.html | 360 + .../installing-deployd.md.html | 397 + docs/getting-started/what-is-deployd.md.html | 360 + docs/getting-started/your-first-api.md.html | 374 + docs/getting-started/your-first-app.md.html | 541 + docs/server-include=all.html | 491 + docs/server/as-a-node-module.md.html | 372 + docs/server/run-script.md.html | 402 + docs/server/your-server.md.html | 341 + docs/users-include=all.html | 607 + docs/users/advanced-guides-include=all.html | 358 + .../understanding-sessions.md.html | 349 + docs/users/authenticating-users.md.html | 472 + docs/users/creating-user-collections.md.html | 366 + docs/users/examples-include=all.html | 377 + docs/users/examples/microblogging.md.html | 353 + docs/users/examples/simple-login.md.html | 343 + docs/users/users-in-events.md.html | 389 + docs/using-modules-include=all.html | 841 + docs/using-modules/installing-modules.md.html | 400 + docs/using-modules/official-include=all.html | 631 + docs/using-modules/official/email.md.html | 436 + docs/using-modules/official/event.md.html | 460 + docs/using-modules/official/importer.md.html | 402 + docs/using-modules/official/s3.md.html | 472 + docs/using-modules/reference-include=all.html | 553 + docs/using-modules/reference/dpd-js.md.html | 496 + .../using-modules/reference/event-api.md.html | 424 + .../using-resource-types.md.html | 405 + examples/images/chat-room.png | Bin 0 -> 11127 bytes examples/images/todo-app.png | Bin 0 -> 5729 bytes examples/index.html | 379 + guides.html | 439 + images/basic-dashboard.png | Bin 0 -> 16022 bytes images/property-editor.png | Bin 0 -> 103413 bytes img/glyphicons-halflings-white.png | Bin 0 -> 8777 bytes img/glyphicons-halflings.png | Bin 0 -> 12799 bytes index.html | 564 + javascripts/app.js | 57 + javascripts/libs/angular-sanitize.js | 532 + javascripts/libs/angular.js | 14401 ++++++++++++++++ javascripts/libs/bootstrap.js | 2025 +++ javascripts/libs/jquery-1.8.2.js | 9440 ++++++++++ javascripts/libs/jquery.highlight.js | 107 + javascripts/libs/jquery.masonry.js | 500 + javascripts/libs/prettify.js | 28 + javascripts/search.js | 125 + modules.html | 307 + stylesheets/prettify.css | 30 + stylesheets/style.css | 5827 +++++++ tutorials/first-api/images/console.png | Bin 0 -> 18668 bytes tutorials/first-api/images/data-editor.png | Bin 0 -> 65281 bytes tutorials/first-api/images/json.png | Bin 0 -> 37961 bytes tutorials/first-api/images/new-dashboard.png | Bin 0 -> 69061 bytes .../first-app/images/comments-app-preview.png | Bin 0 -> 12938 bytes .../creating-custom-resource.png | Bin 0 -> 8399 bytes 100 files changed, 75372 insertions(+) create mode 100644 _00.txt create mode 100644 _downloads.html create mode 100644 api.html create mode 100644 docs/basics-include=all.html create mode 100644 docs/basics/cli.md.html create mode 100644 docs/basics/public.md.html create mode 100644 docs/basics/source-control.md.html create mode 100644 docs/collections-include=all.html create mode 100644 docs/collections/accessing-collections.md.html create mode 100644 docs/collections/adding-logic.md.html create mode 100644 docs/collections/advanced-guides-include=all.html create mode 100644 docs/collections/advanced-guides/custom-client.md.html create mode 100644 docs/collections/creating-collections.md.html create mode 100644 docs/collections/examples-include=all.html create mode 100644 docs/collections/examples/a-simple-todo-app-with-angular.md.html create mode 100644 docs/collections/examples/a-simple-todo-app-with-backbone.md.html create mode 100644 docs/collections/examples/a-simple-todo-app.md.html create mode 100644 docs/collections/examples/chatroom.md.html create mode 100644 docs/collections/notifying-clients.md.html create mode 100644 docs/collections/reference-include=all.html create mode 100644 docs/collections/reference/dpd-js.md.html create mode 100644 docs/collections/reference/event-api.md.html create mode 100644 docs/collections/reference/http.md.html create mode 100644 docs/collections/reference/querying-collections.md.html create mode 100644 docs/collections/reference/updating-objects.md.html create mode 100644 docs/collections/relationships-between-collections.md.html create mode 100644 docs/developing-modules-include=all.html create mode 100644 docs/developing-modules/creating-modules.md.html create mode 100644 docs/developing-modules/custom-resource-types.md.html create mode 100644 docs/developing-modules/examples-include=all.html create mode 100644 docs/developing-modules/examples/email.md.html create mode 100644 docs/developing-modules/examples/event.md.html create mode 100644 docs/developing-modules/examples/s3.md.html create mode 100644 docs/developing-modules/internal-api-include=all.html create mode 100644 docs/developing-modules/internal-api/collection.md.html create mode 100644 docs/developing-modules/internal-api/context.md.html create mode 100644 docs/developing-modules/internal-api/internal-client.md.html create mode 100644 docs/developing-modules/internal-api/resource.md.html create mode 100644 docs/developing-modules/internal-api/script.md.html create mode 100644 docs/developing-modules/internal-api/server.md.html create mode 100644 docs/developing-modules/internal-api/session-store.md.html create mode 100644 docs/developing-modules/internal-api/session.md.html create mode 100644 docs/developing-modules/internal-api/store.md.html create mode 100644 docs/getting-started-include=all.html create mode 100644 docs/getting-started/faq.md.html create mode 100644 docs/getting-started/installing-deployd.md.html create mode 100644 docs/getting-started/what-is-deployd.md.html create mode 100644 docs/getting-started/your-first-api.md.html create mode 100644 docs/getting-started/your-first-app.md.html create mode 100644 docs/server-include=all.html create mode 100644 docs/server/as-a-node-module.md.html create mode 100644 docs/server/run-script.md.html create mode 100644 docs/server/your-server.md.html create mode 100644 docs/users-include=all.html create mode 100644 docs/users/advanced-guides-include=all.html create mode 100644 docs/users/advanced-guides/understanding-sessions.md.html create mode 100644 docs/users/authenticating-users.md.html create mode 100644 docs/users/creating-user-collections.md.html create mode 100644 docs/users/examples-include=all.html create mode 100644 docs/users/examples/microblogging.md.html create mode 100644 docs/users/examples/simple-login.md.html create mode 100644 docs/users/users-in-events.md.html create mode 100644 docs/using-modules-include=all.html create mode 100644 docs/using-modules/installing-modules.md.html create mode 100644 docs/using-modules/official-include=all.html create mode 100644 docs/using-modules/official/email.md.html create mode 100644 docs/using-modules/official/event.md.html create mode 100644 docs/using-modules/official/importer.md.html create mode 100644 docs/using-modules/official/s3.md.html create mode 100644 docs/using-modules/reference-include=all.html create mode 100644 docs/using-modules/reference/dpd-js.md.html create mode 100644 docs/using-modules/reference/event-api.md.html create mode 100644 docs/using-modules/using-resource-types.md.html create mode 100644 examples/images/chat-room.png create mode 100644 examples/images/todo-app.png create mode 100644 examples/index.html create mode 100644 guides.html create mode 100644 images/basic-dashboard.png create mode 100644 images/property-editor.png create mode 100644 img/glyphicons-halflings-white.png create mode 100644 img/glyphicons-halflings.png create mode 100644 index.html create mode 100644 javascripts/app.js create mode 100644 javascripts/libs/angular-sanitize.js create mode 100644 javascripts/libs/angular.js create mode 100644 javascripts/libs/bootstrap.js create mode 100644 javascripts/libs/jquery-1.8.2.js create mode 100644 javascripts/libs/jquery.highlight.js create mode 100644 javascripts/libs/jquery.masonry.js create mode 100644 javascripts/libs/prettify.js create mode 100644 javascripts/search.js create mode 100644 modules.html create mode 100644 stylesheets/prettify.css create mode 100644 stylesheets/style.css create mode 100644 tutorials/first-api/images/console.png create mode 100644 tutorials/first-api/images/data-editor.png create mode 100644 tutorials/first-api/images/json.png create mode 100644 tutorials/first-api/images/new-dashboard.png create mode 100644 tutorials/first-app/images/comments-app-preview.png create mode 100644 tutorials/resource-type/creating-custom-resource.png diff --git a/_00.txt b/_00.txt new file mode 100644 index 0000000..21ccf47 --- /dev/null +++ b/_00.txt @@ -0,0 +1 @@ +localhost/index.html \ No newline at end of file diff --git a/_downloads.html b/_downloads.html new file mode 100644 index 0000000..5813a34 --- /dev/null +++ b/_downloads.html @@ -0,0 +1,2 @@ + Downloads

Downloads

\ No newline at end of file diff --git a/api.html b/api.html new file mode 100644 index 0000000..d7e587c --- /dev/null +++ b/api.html @@ -0,0 +1,581 @@ + + + + + + deployd + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + +
+

Collections

+ +
+ + + +
+

Using Modules

+ +
+ + + +
+

Developing Modules

+ +
+ + +
+ + + + + + +
+ +
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/basics-include=all.html b/docs/basics-include=all.html new file mode 100644 index 0000000..d11e2ce --- /dev/null +++ b/docs/basics-include=all.html @@ -0,0 +1,414 @@ + + + + + + Basics - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + + + + + + +

Using the dpd command line tool #

Commands #

dpd #

+ +

Start Deployd the current project in development mode with an interactive shell/repl for interacting with the running server.

dpd create [name] #

+ +

Create a Deployd project in a new directory with the given name.

dpd showkey #

+ +

Print the app's key for use in a remote dashboard or for making remote authenticated / administrative requests.

dpd keygen #

+ +

Generate a new key for remote access / administration.

dpd remote #

+ +

Open up the remote dashboard in your browser.

Help #

+ +

Here is the help output of dpd -h:

+ +
Usage: dpd [options] [command]
+
+Commands:
+
+  create [project-name]
+      create a project in a new directory
+      eg. `dpd create my-app`
+
+  keygen 
+      generate a key for remote access (./.dpd/keys.json)
+
+  showkey 
+      shows current key for connecting to remote dashboard (./.dpd/keys.json)
+
+  remote 
+      open the remote dashboard in your browser
+
+
+  * 
+      [default] start the server in the current project in development mode
+      with an interactive shell/repl for interacting with the running server
+      e.g. dpd (starts server in current directory),
+           dpd my-app/app.dpd (starts app from file)
+
+Options:
+
+  -h, --help                   output usage information
+  -V, --version                output the version number
+  -m, --mongod [path]          path to mongod executable (defaults to `mongod`)
+  -p, --port [port]            port to host server (defaults to 2403)
+  -w, --wait                   wait for input before exiting
+  -d, --dashboard              start the dashboard immediately
+  -o, --open                   open in a browser
+  -e, --environment [env]      defaults to development
+  -H, --host [host]            specify host for mongo server
+  -P, --mongoPort [mongoPort]  mongodb port to connect to
+  -n, --dbname [dbname]        name of the mongo database
+  -a, --auth                   prompts for mongo server credentials 
+
+ + + + +

The Public Directory #

+ +

Deployd serves static files from your app's /public directory. This directory is created when you run dpd create. These files will be served with the appropriate cache headers (Last-Modified and Etag) so browsers will cache them.

+ +

If available, Deployd will serve index.html as the default file in a folder.

Environments #

+ +

When Deployd is run with the environment setting (see the documentation on the cli), it will attempt to serve files from the /public-[environment] directory instead. For example, if Deployd is run with dpd -e production, it will serve files from the /public-production directory.

+ +

This is useful for optimizing your app in production. You can serve a slightly different version of your front-end with minified JavaScript and CSS. You can also use it to serve compiled versions of pre-processed languages such as LESS, SASS, and CoffeeScript.

+ +

If the environment-specific public directory does not exist, it will serve from the standard /public directory.

+ + + + +

Using Source Control with Deployd #

+ +

Deployd projects are designed to be committed to version control systems so teams can easily manage the source of their applications.

Recommended Ignored Files #

+ +

You shouldn't commit the /data or .dpd directories. The files in these directories are environment specific and should be kept out of version control. All other Deployd files should be committed.

+ + + +

More

+ + + +
+
+
+

Other docs in "Docs"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/basics/cli.md.html b/docs/basics/cli.md.html new file mode 100644 index 0000000..d7e9083 --- /dev/null +++ b/docs/basics/cli.md.html @@ -0,0 +1,376 @@ + + + + + + The "dpd" Command Line Tool - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Using the dpd command line tool #

Commands #

dpd #

+ +

Start Deployd the current project in development mode with an interactive shell/repl for interacting with the running server.

dpd create [name] #

+ +

Create a Deployd project in a new directory with the given name.

dpd showkey #

+ +

Print the app's key for use in a remote dashboard or for making remote authenticated / administrative requests.

dpd keygen #

+ +

Generate a new key for remote access / administration.

dpd remote #

+ +

Open up the remote dashboard in your browser.

Help #

+ +

Here is the help output of dpd -h:

+ +
Usage: dpd [options] [command]
+
+Commands:
+
+  create [project-name]
+      create a project in a new directory
+      eg. `dpd create my-app`
+
+  keygen 
+      generate a key for remote access (./.dpd/keys.json)
+
+  showkey 
+      shows current key for connecting to remote dashboard (./.dpd/keys.json)
+
+  remote 
+      open the remote dashboard in your browser
+
+
+  * 
+      [default] start the server in the current project in development mode
+      with an interactive shell/repl for interacting with the running server
+      e.g. dpd (starts server in current directory),
+           dpd my-app/app.dpd (starts app from file)
+
+Options:
+
+  -h, --help                   output usage information
+  -V, --version                output the version number
+  -m, --mongod [path]          path to mongod executable (defaults to `mongod`)
+  -p, --port [port]            port to host server (defaults to 2403)
+  -w, --wait                   wait for input before exiting
+  -d, --dashboard              start the dashboard immediately
+  -o, --open                   open in a browser
+  -e, --environment [env]      defaults to development
+  -H, --host [host]            specify host for mongo server
+  -P, --mongoPort [mongoPort]  mongodb port to connect to
+  -n, --dbname [dbname]        name of the mongo database
+  -a, --auth                   prompts for mongo server credentials 
+
+ + +

More

+ + + +
+
+
+

Other docs in "Basics"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/basics/public.md.html b/docs/basics/public.md.html new file mode 100644 index 0000000..1c73cb0 --- /dev/null +++ b/docs/basics/public.md.html @@ -0,0 +1,334 @@ + + + + + + The Public Directory - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

The Public Directory #

+ +

Deployd serves static files from your app's /public directory. This directory is created when you run dpd create. These files will be served with the appropriate cache headers (Last-Modified and Etag) so browsers will cache them.

+ +

If available, Deployd will serve index.html as the default file in a folder.

Environments #

+ +

When Deployd is run with the environment setting (see the documentation on the cli), it will attempt to serve files from the /public-[environment] directory instead. For example, if Deployd is run with dpd -e production, it will serve files from the /public-production directory.

+ +

This is useful for optimizing your app in production. You can serve a slightly different version of your front-end with minified JavaScript and CSS. You can also use it to serve compiled versions of pre-processed languages such as LESS, SASS, and CoffeeScript.

+ +

If the environment-specific public directory does not exist, it will serve from the standard /public directory.

+ + +

More

+ + + +
+
+
+

Other docs in "Basics"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/basics/source-control.md.html b/docs/basics/source-control.md.html new file mode 100644 index 0000000..3eaa9f0 --- /dev/null +++ b/docs/basics/source-control.md.html @@ -0,0 +1,328 @@ + + + + + + Using Source Control with Deployd - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Using Source Control with Deployd #

+ +

Deployd projects are designed to be committed to version control systems so teams can easily manage the source of their applications.

Recommended Ignored Files #

+ +

You shouldn't commit the /data or .dpd directories. The files in these directories are environment specific and should be kept out of version control. All other Deployd files should be committed.

+ + +

More

+ + + +
+
+
+

Other docs in "Basics"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections-include=all.html b/docs/collections-include=all.html new file mode 100644 index 0000000..01518a5 --- /dev/null +++ b/docs/collections-include=all.html @@ -0,0 +1,2113 @@ + + + + + + Collections - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Creating Collections #

+ +

A Collection exposes a database-like API directly to clients over HTTP and WebSockets. Clients can run advanced queries, create and update objects, and listen for realtime messages to sync with the Collection when it updates. You can create a Collection in the dashboard by clicking the "Resources +" button in the sidebar, and choosing "Collection".

Properties #

+ +

Every Collection requires a set of properties that describe the data it can store. By default every object in a Collection is created with an id. If an object being POSTed or PUT into a Collection includes properties or values that don't match what the collection allows, they will be ignored. The following property types are available when creating a Collection:

+ +
    +
  • String - Acts like a JavaScript string
  • +
  • Number - Stores numeric values, including floating points.
  • +
  • Boolean - Either true or false. (To avoid confusion, Deployd will consider null or undefined to be false)
  • +
  • Object - Stores any JSON object. Useful for storing arbitrary data on an object without needing to validate schema.
  • +
  • Array - Stores an array of any type.
  • +

The Data Editor #

+ +

Once you create a Collection from the dashboard, you can add and edit its data using the data editor. The data editor is designed to edit all sorts of data, including objects and arrays.

Basic Use #

+ +

Double-click in a cell to start editing. Press Enter to save your changes, or Escape to cancel and undo your changes.

+ +

While editing a string property, click the "edit" icon next to the field to open up a multiline editor.

+ +

Click the trash can icon in any row to delete it.

+ +

Edit the bottom-most row to create a new object. Press Enter when editing a property to save the row, or click the checkmark in the margin.

Useful Shortcuts #

+ +
    +
  • Use the arrow keys to move your selection without using the mouse.
  • +
  • Press "Enter" when a cell is selected to start editing.
  • +
  • Start typing when a cell is selected to overwrite its existing value.
  • +
  • If you accidentally save a change, press Ctrl/Cmd-Z to reverse it.
  • +
  • Press Ctrl-Delete to remove a row. Press Ctrl/Cmd-Z to add it back. (heads up: it will have a different id)
  • +
  • Press Ctrl-Enter to open up the multiline editor for a string property; this lets you write long text values.
  • +
  • Press Ctrl-Enter while in the multiline editor to save it (pressing Enter will just create a new line)
  • +
  • Press Tab to save the current property and edit the next one.
  • +
+ + + + +

Accessing Collections with dpd.js #

+ +

dpd.js is an auto-generated library that updates as you update the resources in your Deployd API. If you are writing your front-end in the public directory, include a script tag tag in your HTML:

+ +
<script src="/dpd.js" type="text/javascript"></script>
+
+ +

Note: The dpd.js file will not appear in the public directory because it is generated at runtime.

Example Usage #

+ +
dpd.todos.get(function(todos, error) {
+  if (error) {
+    alert(error.message);
+  } else {
+    for (var i = 0; i < todos.length; i++) {
+      renderTodo(todos[i]);
+    };
+  }
+});
+
+ +

Dpd.js functions are asynchronous: they do not return a value, but execute a callback function when the AJAX operation is complete.

+ +
// Does not work
+var result = dpd.todos.get();
+
+ + + +
// Works as expected
+dpd.todos.get(function(result, error) {
+  // Work with result
+});
+
+ +

For details on using dpd.js, see the dpd.js reference

+ +

Also see A Simple Todo App for a working example.

Using dpd.js on a different origin #

+ +

You can use the dpd.js library outside of the public folder by using an absolute URL to the file.

+ +

This will not work on browsers that do not support Cross-Origin Resource Sharing (namely Internet Explorer 7 and below).

Accessing Collections without Dpd.js #

+ +

The dpd.js library is not required; it is only a utility library for accessing Deployd's HTTP API with AJAX. For details on the HTTP API, see the HTTP API Refernence.

+ +

Some front-end libraries include support for HTTP or REST APIs; for examples of how to use these instead of dpd.js, see A Simple Todo App with Backbone and A Simple Todo App with AngularJS

+ + + + +

Adding Custom Business Logic with Events #

+ +

Events allow you to add custom business logic to your Collection. By writing Events, you can add validation, relationships, and security to your app. Events are written in JavaScript (specifically, the ECMAScript 5 standard) and have access to the Collection Events API.

+ +

The following events are available for scripting:

On Get #

+ +

Called whenever an object is loaded from the server. Commonly used to hide properties, restrict access to private objects, and calculate dynamic values.

+ +
// Example On Get: Hide Secret Properties
+if (!me || me.id !== this.creatorId) {
+  hide('secret');
+}
+
+ + + +
// Example On Get: Load A Post's Comments
+if (query.loadComments) {
+  dpd.comments.get({postId: this.id}, function(comments) {
+    this.comments = comments;
+  });  
+}
+
+ +

Note: When a list of objects is loaded, On Get will run once for each object in the list. Calling cancel() in this case will remove the object from the list, rather than cancelling the entire request.

On Validate #

+ +

Called whenever an object's values change, including when it is first created. Commonly used to validate property values and calculate certain dynamic values (i.e. last modified time).

+ +
// Example On Validate: Enforce a max length
+if (this.body.length > 100) {
+  error('body', "Cannot be more than 100 characters");
+}
+
+ + + +
// Example On Validate: Normalize an @handle
+if (this.handle.indexOf('@') !== 0) {
+  this.handle = '@' + this.handle;
+}
+
+ +

Note: On Post or On Put will execute after On Validate, unless cancel() or error() is called

On Post #

+ +

Called when an object is created. Commonly used to prevent unauthorized creation and save data relevant to the creation of an object, such as its creator.

+ +
// Example On Post: Save the date created
+this.createdDate = new Date().getTime();
+
+ + + +
// Example On Post: Prevent unauthorized users from posting
+if (!me) {
+  cancel("You must be logged in", 401);
+}
+

On Put #

+ +

Called when an object is updated. Commonly used to restrict editing access to certain roles, or to protect certain properties from editing. It is strongly recommended that you protect() any properties that should not be modifiable by users after an object is created.

+ +
// Example On Put: Protect readonly/automatic properties
+protect('createdDate');
+protect('creatorId');
+

On Delete #

+ +

Called when an object is deleted. Commonly used to prevent unauthorized deletion.

+ +
// Example On Delete: Prevent non-admins from deleting
+if (!me || me.role !== 'admin') {
+  cancel("You must be an admin to delete this", 401);
+}
+
+ + + + +

Accessing Collections - Building a Custom Client #

+ +

In this guide, we will build an HTTP client from scratch to perform CRUD as well as listen for events from a Collection.

REST #

+ +

Most REST clients should work with Deployd Collections right away, though Deployd does not strictly follow REST. For example, Backbone.js and AngularJS's HTTP utilities work with Deployd without modification.

WebSockets #

+ +

To fully implement the Collection API, a client must be compatible with WebSockets and Socket.IO specifically. Clients are responsible for sending heartbeat information as well as reconnecting in the case of unexpected disconnects.

Building a Node.js Client #

+ +

The following is implemented in Node.js, but the basic idea can be applied to any language or platform.

Basics #

+ +

All we need to create a collection client is a constructor and a single method for making requests.

+ +
var request = require('request');
+
+function Collection(url) {
+  this.url = url
+}
+
+Collection.prototype.request = function (options, fn) {
+  var url = this.url;
+  options.url = url + (options.url || '');  
+  request(options, function (err, res, body) {
+    if(res.statusCode >= 400) {
+      err = body || {message: 'an unknown error occurred'};
+      return fn(err);
+    }
+
+    fn(null, body);
+  });
+}
+
+ +

Now we can construct new collections by passing the URL as the only argument to our constructor.

+ +
var c = new Collection('http://foo.deploydapp.com/todos');
+
+c.request({url: '?done=false'}, function(err, todos) {
+  console.log(todos); // [...]
+});
+
+ +

We can add an object to our collection by passing an object as the json body and setting the method to "POST".

+ +
var todo = {
+  title: 'wash the car'
+};
+
+c.request({json: todo, method: 'POST'}, function(err, todo) {
+  console.log(todo); // {id: '...', ...}
+});
+
+ +

To update an object we just need to set the method to "PUT".

+ +
var todo = {
+  id: '06a5254f11ff7853',
+  done: true
+};
+
+c.request({json: todo, method: 'PUT'}, function(err, todo) {
+  console.log(todo); // {id: '...', ...}
+});
+
+ +

Deleting an object requires an ID and the method must be set to "DELETE".

+ +
var id = '06a5254f11ff7853';
+
+c.request({url: '/' + id, method: 'DELETE'}, function(err, todo) {
+  console.log(err); // null - if no error occurred
+});
+

Listening to Events #

+ +

The simplest way to listen events is to use a Socket.IO client. You can find a list of clients here.

+ +

Using the node.js Socket.IO client, we can create a socket by connecting to our deployed app. Then calling the socket's on() method to listen to a custom event emitted by a collection.

+ +
var io = require('socket.io-client');
+var socket = io.connect('http://foo.deploydapp.com');
+
+socket.on('my event', function (data) {
+  console.log(data); // emit()ed from the server
+});
+
+ + + + +

A Simple Todo App #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using dpd.js.

+ +

Download View Source

Useful files #

+ +

A Simple Todo App with AngularJS #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using the AngularJS framework.

+ +

Download View Source

Useful files #

+ +

A Simple Todo App with Backbone.js #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using Backbone.js.

+ +

Download View Source

Useful files #

+ +

Chatroom #

+ +

Todo app

+ +

This app demonstrates how to send messages to the client using Sockets when data is updated on the server.

+ +

Download View Source

Useful files #

+ +
+ + + + + + + + + +

Relationships Between Collections with Events #

+ +

Designing the relationships between the collections in your application is crucial to a useful API. In typical databases, there are very specific ways to implement the relation of objects in one table (or collection) and another. Deployd lets you relate your data however your application requires and is flexible enough to allow you to easily change the way objects are related.

Types of Relationships #

+ +

When designing the collections in your application keep in mind the following strategies for relating data. There isn't a single best way to create relationships, so you will have to take into account how data will change in your collections.

Embedding Data #

+ +

Deployd allows your collection to store complex structures such as nested objects or arrays. This is useful if you want to embed data inside your collection's objects. Keep in mind this is only recommended when the embedded data is not likely to change. For example, a blog-posts collection could have an author property with a type set to Object.

+ +
{
+  "title": "Foo Bar Bat Baz?",
+  "author": {
+    "name": "Joe Bob",
+    "id": "5ef0f7d515764998"
+  }
+}
+
+ +

This style of relationship allows users of the collection to display the name of the author without running any other queries. The downside is an update event is required to keep the author name in sync if it ever changes. If your data changes often, this may not be the best approach.

Contains Many or One-to-Many #

+ +

Similarly to storing nested objects in your collection, you can also store arrays of arbitrary JSON. This is useful when you want to setup a contains relationship. For example, in a gradebook application, your classes collection objects could contain students.

+ +
{
+  "title": "Language Arts",
+  "students": ["5ef0f7d515764998", "5ef0f7d515764531", ...] 
+}
+
+ +

By storing an array of student ids you can easily query classes by student.

+ +
dpd.classes.get({students: '5ef0f7d515764998'}, function(classes) {
+  console.log(classes); // [...] - all the classes the student is in.
+});
+

Many-to-Many #

+ +

There are several ways to handle many-to-many relationships. The most common way is to include an Array property that stores the ids of the related objects on both collections.

+ +

Continuing with the gradebook example, a student may have many classes, and a class may have many students. The classes collection would have a students Array property containing the student ids and the students collection would have a classes Array property containing class ids.

+ +

This lets you query each collection to get the students in a class or the classes a student is taking by providing the id of the class or student.

+ +
dpd.students.get({id: {$in: class.students}}, function(students) {
+  console.log(students);
+}); 
+
+// or
+
+dpd.classes.get({id: {$in: student.classes}}, function(classes) {
+  console.log(classes);
+});
+
+ +

If you wanted to include the full objects when querying the API you could implement a simple GET event.

+ +
// on GET /students
+
+if(query.include === 'classes') {
+  dpd.classes.get({id: {$in: student.classes}}, function(classes) {
+    this.classes = classes;
+  });
+}
+
+ +

Then if you added the include param when querying from the browser, a student would come back with all of its classes.

+ +
dpd.students.get({id: '2ef0f7d515764991', include: 'classes'}, fn);
+
+ +

would output

+ +
{
+  "id": "2ef0f7d515764991",
+  "name": "Joe Bob",
+  "classes": [{
+    "id": "...",
+    "title": "Language Arts"
+  }, ...]
+}
+

Parent-Child #

+ +

Some collections contain objects related to other objects in the same collection. A simple example of this is threaded comments. Where a comment can be in reply to another comment, creating a tree-like structure when rendered.

+ +

To accomplish this, all you need is a parent property containing the id of a parent object if one exists. Since Deployd supports recursive queries in a collection's GET event, the following works as you would expect.

+ +
// on GET /comments
+var comment = this;
+
+dpd.comments.get({parent: comment.id}, function(comments) {
+  if(comments && comments.length) comment.children = comments;
+});
+
+ +

Running the following query from the browser would result in a nested structure of all possible comments:

+ +
// from the browser
+dpd.comments.get({id: '2ef0f7d515764991'}, console.log);
+
+ +

would output

+ +
{
+  "id": "2ef0f7d515764991"
+  "text": "Hello, World!",
+  "children": [
+    {
+      "id": "tef0f7d515761234",
+      "text": "Foo bar...",
+      "children": [
+        {
+          "id": "ff00f7d515764642",
+          "text": "I agree!"
+        },
+        {
+          "id": "2200f7d51576123",
+          "text": "I do not agree!"
+        },
+      ]
+    }
+  ]
+}
+
+ +

If you expect that a query could become an infinite loop (or if it already is an infinite loop; a good sign of this is requests that time out before returning a result), put a $limitRecursion property on your query with the maximum number of levels to iterate:

+ +
// on GET /comments
+var comment = this;
+
+dpd.comments.get({parent: comment.id, $limitRecursion: 10}, function(comments) {
+  if(comments && comments.length) comments.children = comments;
+});
+
+ + + + +

Notifying the Client of Changes with Messages #

+ +

Keeping all of the clients of your API up-to-date with your collection's latest data is simple with collection events. For example, in a PUT event, you can notify all connected clients of the changes to the object being updated by calling the emit() function to send all connected users a message.

+ +

The emit() function takes an event argument and an arbitrary data object to send to all of the connected clients (eg. emit('my message', {foo: 'bar'})). Dpd.js clients can listen for these events using the on() method (eg. dpd.todos.on('my message', fn)).

Example #

+ +

Let's say you want to make a chatroom app and you have a Collection called /messages.

+ +

In the On POST event of /messages, you would add the following line:

+ +
emit('messages:create', this);
+
+ +

This sends a message called messages:create (This could be anything) with the current object (this) as an argument. The messages: prefix namespaces the event to the collection.

+ +

On the client, you would listen for that event using dpd.on() and respond by updating the DOM:

+ +
dpd.messages.on('create', function(message) {
+  renderMessage(message);
+});
+
+ +

The message argument is the value you passed on the server (this).

+ +

See the Chatroom Example for a working version of this code.

Browser and Server Support #

+ +

The realtime messaging features of Deployd are built on Socket.IO and work on almost every major browser:

+ +
    +
  • Internet Explorer 5.5+
  • +
  • Safari 3+
  • +
  • Google Chrome 4+
  • +
  • Firefox 3+
  • +
  • Opera 10.61+
  • +
  • iOS Safari
  • +
  • Android WebKit
  • +
  • WebOS WebKit
  • +
+ +

(taken from Socket.IO's site)

+ + + + +

Event API #

this #

+ +

The current object is represented as this. You can always read its properties. Modifying its properties in an On Get request will change the result that the client receives, while modifying its properties in an On Post, On Put, or On Validate will change the value in the database.

+ +
// Example: On Validate
+// If a property is too long, truncate it
+if (this.message.length > 140) {
+  this.message = this.message.substring(0, 137) + '...';
+}
+
+ +

Note: In some cases, the meaning of this will change to something less useful inside of a function. If you are using functions such as Array.forEach(), you may need to bind another variable to this:

+ +
// Won't work - sum remains at 0
+this.sum = 0;
+this.targets.forEach(function(t) {
+  this.sum += t.points;
+});
+
+ + + +
//Works as expected
+var self = this;
+
+this.sum = 0;
+this.targets.forEach(function(t) {
+  self.sum += t.points;
+});
+

me #

+ +

The currently logged in User from a User Collection. undefined if no user is logged in.

+ +
// Example: On Post
+// Save the creator's information
+if (me) {
+    this.creatorId = me.id;
+    this.creatorName = me.name;
+}
+

isMe() #

+ +
isMe(id)
+
+ +

Checks whether the current user matches the provided id.

+ +
// Example: On Get /users
+// Hide properties unless this is the current user
+if (!isMe(this.id)) {
+    hide('privateVariable');
+}
+
+ + + +
// Example: On Put 
+// Make sure that only the creator can edit a post
+cancelUnless(isMe(this.id), "You are not authorized to edit that post", 401);
+

query #

+ +

The query string object. On a specific query (such as /posts/a59551a90be9abd8), this includes an id property.

+ +
// Example: On Get
+// Don't show the body of a post in a general query
+if (!query.id) {
+  hide(this.body);
+}
+

cancel() #

+ +
cancel(message, [statusCode])
+
+ +

Stops the current request with the provided error message and HTTP status code. Status code defaults to 400. Commonly used for security and authorization.

+ +

It is strongly recommended that you cancel() any events that are not accessible to your front-end, because your API is open to anyone.

+ +
// Example: On Post
+// Don't allow non-admins to create items
+if (!me.admin) {
+  cancel("You are not authorized to do that", 401);
+}
+
+ +

Note: In a GET event where multiple values are queried (such as on /posts), the cancel() function will remove the current item from the results without an error message.

cancelIf(), cancelUnless() #

+ +
cancelIf(condition, message, [statusCode])
+cancelUnless(condition, message, [statusCode])
+
+ +

Calls cancel(message, statusCode) if the provided condition is truthy (for cancelIf()) or falsy (for cancelUnless()).

+ +
Example: On Post
+// Prevent banned users from posting
+cancelUnless(me, "You are not logged in", 401);
+cancelIf(me.isBanned, "You are banned", 401);
+

error() #

+ +
error(key, message)
+
+ +

Adds an error message to an errors object in the response. Cancels the request, but continues running the event so it can collect multiple errors to display to the user. Commonly used for validation.

+ +
// Example: On Validate
+// Don't allow certain words
+// Returns response {"errors": {"name": "Contains forbidden words"}}
+if (!this.name.match(/(foo|bar)/)) {
+  error('name', "Contains forbidden words");
+}
+

errorIf(), errorUnless() #

+ +
errorIf(condition, key, message)
+errorUnless(condition, key, message)
+
+ +

Calls error(key, message) if the provided condition is truthy (for errorIf()) or falsy (for errorUnless()).

+ +
// Example: On Validate
+// Require message to be a certain length
+errorUnless(this.message && this.message.length > 2, 'message', "Must be at least 2 characters");
+

hide() #

+ +
hide(property)
+
+ +

Hides a property from the response.

+ +
// Example: On Get
+// Don't show private information
+if (!me || me.id !== this.creatorId) {
+  hide('secret');
+}
+

protect() #

+ +
protect(property)
+
+ +

Prevents a property from being updated. It is strongly recommended you protect() any properties that should not be modified after an object is created.

+ +
// Example: On Put
+// Protect a property
+protect('createdDate');
+
+ + + +
// Example: On Put
+// Only the creator can change the title
+if (!(me && me.id === this.creatorId)) {
+  protect('title');
+}
+

changed() #

+ +
changed(property)
+
+ +

Returns whether a property has been updated.

+ +
// Example: On Put
+// Validate the title when it changes
+if(changed('title') && this.title.length < 5) {
+  error('title', 'must be over 5 characters');
+}
+

previous #

+ +

An Object containing the previous values of the item to be updated.

+ +
// Example: On Put
+if(this.votes < previous.votes) {
+  emit('votes have decreased');
+}
+

emit() #

+ +
emit([userCollection, query], message, [data])
+
+ +

Emits a realtime message to the client.

+ +
// Example: On Post
+// Alert clients that a new post has been created
+emit('postCreated', this);
+
+ +

In the front end:

+ +
// Listen for new posts
+dpd.on('postCreated', function(post) {
+    //do something...
+});
+
+ +

You can use userCollection and query parameters to limit the message broadcast to specific users.

+ +
// Example: On Put
+// Alert the owner that their post has been modified
+if (me.id !== this.creatorId) {
+  emit(dpd.users, {id: this.creatorId}, 'postModified', this); 
+} 
+
+ +

See Notifying Clients of Changes with Sockets for an overview on realtime functionality.

dpd #

+ +

The entire dpd.js library, except for the realtime functions, is available in events. It will also properly bind this in callbacks.

+ +
// Example: On Get
+// If specific query, get comments
+dpd.comments.get({postId: this.id}, function(results) {
+  this.comments = results;
+});
+
+ + + +
// Example: On Delete
+// Log item elsewhere
+dpd.archived.post(this);
+
+ +

Dpd.js will prevent recursive requests if you set the $limitRecursion property. This works by returning null from a dpd function call that has already been called several times further up in the stack.

+ +
// Example: On Get /recursive
+// Call self
+dpd.recursive.get({$limitRecursion: 1}, function(results) {
+    if (results) this.recursive = results;
+});
+
+ + + +
// GET /recursive
+{
+    "id": "a59551a90be9abd8",
+    "recursive": [
+        {
+            "id": "a59551a90be9abd8"    
+        }
+    ]
+}
+

internal #

+ +

Equal to true if this request has been sent by another script.

+ +
// Example: On GET /posts
+// Posts with a parent are invisible, but are counted by their parent
+if (this.parentId && !internal) cancel();
+
+dpd.posts.get({parentId: this.id}, function(posts) {
+    this.childPosts = posts.length;
+});
+

isRoot #

+ +

Equal to true if this request has been authenticated as root (has the dpd-ssh-key header with the appropriate key; such as from the dashboard)

+ +
// Example: On PUT /users
+// Protect reputation property - should only be calculated by a custom script.
+
+if (!isRoot) protect('reputation');
+

console.log() #

+ +
console.log([arguments]...)
+
+ +

Logs the values provided to the command line. Useful for debugging.

Accessing Collections Over HTTP #

+ +

Deployd exposes an HTTP API to your Collections which can be used by any platform or library that supports HTTP or AJAX. Though it does not strictly adhere to REST, it should also work with most libraries designed for REST.

Collection API #

+ +

The examples below use a Collection called /todos with the following schema:

+ +
    +
  • id
  • +
  • string title
  • +
  • string category
  • +
+ +

Your Collection is available at the URL you specified. If you are using the default development hostname of localhost:2403, for example, the /todos collection will be available at http://localhost:2403/todos.

Requests #

+ +

A request to the Deployd API should include the Content-Type header. The following content types are supported:

+ +
    +
  • application/json (recommended)
  • +
  • application/x-www-form-urlencoded (All values will be parsed as strings)
  • +
+ +

The Content-Type header is not necessary for GET or DELETE requests which have no body.

Responses #

+ +

Deployd will send standard HTTP status codes depending on the results on an operation. If the code is 200 (OK), the request was successful and the result is available in the body as JSON.

+ +

If the code is 204 (No Content), the request was successful, but there is no result.

+ +

If the code is 400 or greater, it will return the error message formatted as a JSON object:

+ +
    +
  • status (number): The HTTP status code of the request. Common codes include: +
    • 400 - Bad Request: The request contained invalid data and could not be completed
    • +
    • 401 - Unauthorized: The current session is not authorized to perform that action
    • +
    • 500 - Internal Server Error: Something went wrong on the server
  • +
  • message (string): A message describing the error. Not always present.
  • +
  • errors (object): A hash of error messages corresponding to the properties of the object that was sent - usually indicates validation errors. Not always present.
  • +
+ +

Examples of errors:

+ +
{
+  "status": 401,
+  "message": "You are not allowed to access that collection!"
+}
+
+ + + +
{
+  "status": 400,
+  "errors": {
+      "title": "Title must be less than 100 characters",
+      "category": "Not a valid category"
+  }
+}
+

Listing Data #

+ +

To retreive an array of objects in the collection, send a GET request to your collection's path:

+ +
GET /todos
+
+ +

The response will be an array of objects:

+ +
200 OK
+[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }, {
+    "id": "320d6151a9aad8ce"
+    "title": "Write autobiography",
+    "category": "writing"
+  }
+]
+
+ +

If the collection has no objects, it will be an empty array:

+ +
200 OK
+[]    
+

Querying Data #

+ +

To filter results by the specified query object, send a GET request to your collection's path with a query string. See Querying Collections for information on constructing a query.

+ +
GET /todos?category=pets
+
+ +

For more advanced queries, you will need to pass the query string as JSON instead:

+ +
GET /todos?{"category": "pets"}
+
+ +

The response body is an array of objects:

+ +
200 OK
+[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }
+]
+

Getting a Specific Object #

+ +

To retrieve a single object by its id property, send a GET request with the id value as the path.

+ +
GET /todos/320d6151a9aad8ce
+
+ +

The response body is the object that you requested:

+ +
200 OK
+{
+  "id": "320d6151a9aad8ce",
+  "title": "Wash the dog",
+  "category": "pets"
+}
+

Creating an Object #

+ +

To create an object in the collection, send a POST request with the object's properties in the body.

+ +
POST /todos
+{
+  "title": "Walk the dog"
+}
+
+ +

The response body is the object that you posted, with any additional calculated properties and the id:

+ +
{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the dog"
+}
+

Updating an Object #

+ +

To update an object that is already in the collection, send a POST or PUT request with the id value as the path and with the properties you wish to update in the body. It will only change the properties that are provided. It is also possible to incrementally update certain properties; see Updating Objects in Collections for details.

+ +
PUT /todos/91c621a3026ca8ef
+{
+  "title": "Walk the cat"
+}
+
+ + + +
POST /todos/91c621a3026ca8ef
+{
+  "title": "Walk the cat"
+}
+
+ +

You can also omit the id in the path if you provide an id property in the body:

+ +
PUT /todos
+{
+  "id": "91c621a3026ca8ef"
+  "title": "Walk the cat"
+}
+
+ +

Finally, you can provide a query string to ensure that the object you are updating has the correct properties. You must still provide an id. This can be useful as a failsafe.

+ +
PUT /todos/91c621a3026ca8ef?category=pets
+{
+  "title": "Walk the cat"
+}
+
+ +

The response body is the entire object after the update:

+ +
200 OK  
+{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the cat",
+  "category": "pets"
+}
+
+ +

The PUT verb will return an error if the id and/or query does not match any object in the collection:

+ +
400 Bad Request
+{
+  "status": 400,
+  "message": "No object exists that matches that query"
+}
+

Deleting an Object #

+ +

To delete an object from the collection, send a DELETE request with the id value as a path.

+ +
DELETE /todos/91c621a3026ca8ef
+
+ +

You can also pass a query string to ensure that you are removing the correct object:

+ +
DELETE /todos/91c621a3026ca8ef?title=Walk the dog
+
+ +

You can omit the id in the path if you provide it in the query string:

+ +
DELETE /todos?id=91c621a3026ca8ef&title=Walk the dog
+
+ +

The response body will always be empty.

Realtime API #

+ +

Deployd uses Socket.io for its realtime functionality. If you are not using dpd.js, you can use the Socket.io client library.

+ +
var socket = io.connect('/');
+socket.on('todos:create', function(todo) {
+  // Do something
+});
+
+ +

The Socket.io community has created client libraries for other languages and platforms as well.

Root Requests #

+ +

You can elevate your session to root access by adding the header dpd-ssh-key. It must have the value of your app's key (you can find this by typing dpd showkey into the command line); although in the development environment, the dpd-ssh-key header can have any value.

+ +

Sending a request as root has several effects. Most notably, you can use the {$skipEvents: true} property in either the query string or request body. This will cause events not to run. This is useful for bypassing authentication or validation.

+ +

Your front-end app should never gain root access, and you should never store the app's key in a place where it can be accessed by users, even if they understand the system. This is primarily useful for writing data management utilities for yourself, other developers, and system administrators.

Examples #

+ +

The examples below show how to use various JavaScript front-end libraries to access a Collection called /todos.

jQuery #

+ +
$.ajax('/todos', {
+  type: "GET",
+  success: function(todos) {
+    // Do something
+  },
+  error: function(xhr) {
+    alert(xhr.responseText);
+  }
+});
+
+$.ajax('/todos', {
+  type: "POST",
+  contentType: "application/json",
+  data: JSON.stringify({
+    title: "Walk the dog"
+  }),
+  success: function(todo) {
+    // Do something
+  }, 
+  error: function(xhr) {
+    alert(xhr.responseText);
+  }
+});
+
+ +

Note: When providing a request body, jQuery defaults to form encoding. Deployd works best with a JSON body, so you'll need to set the contentType option and manually convert to JSON.

Backbone.js #

+ +
var Todo = Backbone.Model.extend({});
+var Todos = Backbone.Collection.extend({
+  model: Todo,
+  url: "/todos"
+});
+
+var todos = new Todos();  
+
+todos.fetch({
+  success: function(collection, response) {
+    // Do something
+  }, error: function(collection, response) {
+    alert(response);
+  }
+});
+
+todos.create({
+  title: "Walk the dog"
+}, {
+  success: function(collection, response) {
+    // Do something
+  }, error: function(collection, response) {
+    alert(response);
+  }
+});
+

Angular.js #

+ +

Using $http:

+ +
function Controller($scope, $http) {
+  $http.get('/todos')
+    .success(function(todos) {
+      $scope.todos = todos;
+    })
+    .error(function(err) {
+      alert(err);
+    });
+
+  $http.post('/todos', {
+      title: "Walk the dog"
+    })
+    .success(function(todo) {
+      // Do something
+    })
+    .error(function(err) {
+      alert(err);
+    });
+}
+
+ +

Using ngResource:

+ +
var myApp = angular.module('myApp', ['ngResource']);
+
+myApp.factory('Todos', function($resource) {
+  return $resource('/todos/:todoId', {todoId: '@id'});
+});
+
+function Controller($scope, Todos) {
+  $scope.todos = Todos.query(function(response) {
+    // Do something
+  }, function(error) {
+    alert(error);
+  });
+
+  Todos.save({
+    title: "Walk the dog"
+  }, function(todo) {
+    // Do something
+  }, function(error) {
+    alert(error);
+  });
+}
+
+myApp.controller('Controller', Controller);
+

Cross-Origin Requests #

+ +

The most common bug when implementing a CORS client for Deploy is to include headers that are not allowed. A client must not send any custom headers besides the following:

+ +
Origin, Accept, Accept-Language, Content-Language, Content-Type, Last-Event-ID
+
+ +

This will not work on browsers that do not support Cross-Origin Resource Sharing (namely Internet Explorer 7 and below).

Cross-Origin Requests with dpd.js #

+ +

When using dpd.js, all the required CORS headers are sent by default to any domain. You don't have to make any changes to your requests. dpd.js takes care of it for you.

Cross-Origin Requests with jQuery #

+ +

When using jQuery.ajax() on cross-origin requests the credentials are not sent along with the request automatically. You have to add them to each ajax() request using the xhrFields parameter. Here is an example of login followed by getting some data.

+ +
// Logging a user in.
+$.ajax({
+  url: 'http://<domain>:<port>/users/login',
+  type: "POST",
+  data: {username:"un", password:"pw"},
+  cache: false,
+  xhrFields:{
+    withCredentials: true
+  },
+  success: function(data) {
+    console.log(data);
+  },
+  error: function(xhr) {
+    console.log(xhr.responseText);
+  }
+});
+
+// On subsequent requests or in the success callback above.  (After having logged in) 
+$.ajax({
+  url: 'http://<domain>:<port>/<collection>',
+  type: "GET",
+  cache: false,
+  xhrFields:{
+    withCredentials: true
+  },
+  success: function(data) {
+    console.log(data);
+  },
+  error: function(xhr) {
+    console.log(xhr.responseText);
+  }
+});
+

HTTP method override #

+ +

Provides faux HTTP method support.

+ +

Most browsers doesn’t support methods other than “GET” and “POST” when it comes to submitting forms. So It's support something like 'Rails'.

+ +

Pass an optional key to use when checking for a method override, othewise defaults to _method. The original method is available via req.originalMethod.

+ +

It's support both URL query and POST body

+ +
URL       : ?_method=METHOD_NAME or
+JSON body : { _method: 'METHOD_NAME' }
+
+ +

$.ajax({ + type: "POST", + url : "/todos/"+ todoId, + data: { _method:"DELETE" }, + success: function(res) {

Ajax Example #

+ +
$.ajax({
+  type : "POST",
+  url  : "/todos/OBJECT_ID"
+  data : { _method:"DELETE" },
+  success: function(todo) {
+    // Object was deleted. response body empty.
+  }, 
+  error: function(xhr) {}
+});
+
+or
+
+$.ajax({
+  type : "POST",
+  url  : "/todos/OBJECT_ID?_method=DELETE",
+  success: function(todo) {
+    // Object was deleted. response body empty.
+  }, 
+  error: function(xhr) {}
+});
+

Querying Collections #

Simple Queries #

+ +

Collections can be queried over HTTP using the query string.

+ +

This example will return all the posts with an author "Joe":

+ +
GET /posts?author=Joe   
+

Advanced Queries #

+ +

When querying a Collection, you can use special commands to create a more advanced query.

+ +

Deployd supports all of MongoDB's conditional operators; only the common operators and Deployd's custom commands are documented here.

+ +

When using an advanced query in REST, you must pass JSON as the query string, for example:

+ +
GET /posts?{"likes": {"$gt": 10}}
+
+ +

If you are using dpd.js, this will be handled automatically.

Comparison ($gt, $lt, $gte, $lte) #

+ +

Compares a Number property to a given value.

+ +
    +
  • $gt - Greater than
  • +
  • $lt - Less than
  • +
  • $gte - Greater than or equal to
  • +
  • $lte - Less than or equal to

    + +
    // Finds all posts with more than 10 likes
    +{
    +    likes: {$gt: 10}
    +}
    +
  • +

$ne (Not Equal) #

+ +

The $ne command lets you choose a value to exclude.

+ +
// Get all posts except those posted by Bob
+{
+    author: {$ne: "Bob"}
+}
+

$in #

+ +

The $in command allows you to specify an array of possible matches.

+ +
// Get articles in the "food", "business", and "technology" categories
+{
+    category: {$in: ["food", "business", "technology"]}
+}
+

$regex #

+ +

The $regex command allows you to specify a regular expression to match a string property.

+ +

You can also use the $options command to specify regular expression flags.

+ +
// Get usernames that might be email addresses (x@y.z)
+{
+    "username": {$regex: "[a-z0-9\-]+@[a-z0-9\-]+\.[a-z0-9\-]+", $options: 'i' }
+}
+

Query commands #

+ +

Query commands apply to the entire query, not just a single property.

$fields #

+ +

The $fields command allows you to include or exclude properties from your results.

+ +
    // Exclude the "email" property
+    {
+        $fields: {email: 0}
+    }
+
+ + + +
    // Only include the "title" property
+    {
+        $fields: {title: 1}
+    }
+

$or #

+ +

The $or command allows you to specify multiple queries for an object to match in an array.

+ +
// Get all public posts and all posts by a specified user (even if those are private)
+{
+    $or: [{
+      isPublic: true
+    }, {
+      creator: "Bob"
+    }]
+}
+

$sort #

+ +

The $sort command allows you to order your results by the value of a property. The value can be 1 for ascending sort (lowest first; A-Z, 0-10) or -1 for descending (highest first; Z-A, 10-0)

+ +
// Sort posts by likes, descending
+{
+    $sort: {likes: -1}
+}
+

$limit #

+ +

The $limit command allows you to limit the amount of objects that are returned from a query. This is commonly used for paging, along with $skip.

+ +
// Return the top 10 scores
+{
+    $sort: {score: -1},
+    $limit: 10
+}
+

$skip #

+ +

The $skip command allows you to exclude a given number of the first objects returned from a query. This is commonly used for paging, along with $limit.

+ +
// Return the third page of posts, with 10 posts per page
+{
+    $skip: 20,
+    $limit: 10
+}
+

$limitRecursion #

+ +

The $limitRecursion command allows you to override the default recursive limits in Deployd. This is useful when you want to query a very deeply nested structure of data. Otherwise you can still query nested structures, but Deployd will stop the recursion after 2 levels. See the Collection Relationships guide for more info.

Updating Objects in Collections #

+ +

When updating an object in a Collection, you can use special modifier commands to more granularly change property values.

$inc #

+ +

The $inc command increments the value of a given Number property.

+ +
// Give a player 5 points
+{
+  score: {$inc: 5}
+}
+

$push #

+ +

The $push command adds a value to an Array property.

+ +
// Add a follower to a user by storing their id.
+{
+  followers: {$push: 'a59551a90be9abd8'}
+}
+

$pushAll #

+ +

The $pushAll command adds multiple values to an Array property.

+ +
// Add mentions of users
+{
+  mentions: {
+    $pushAll: ['a59551a90be9abd8', 'd0be45d1445d3809']
+  }
+}
+

$pull #

+ +

The $pull command removes a value from an Array property.

+ +
// Remove a user from followers
+{
+  followers: {$pull: 'a59551a90be9abd8'}
+}
+
+ +

Note: If there is more than one matching value in the Array, this will remove all of them

$pullAll #

+ +

The $pullAll command removes multiple values from an Array property.

+ +
// Remove multiple users
+{
+  followers: {$pullAll: ['a59551a90be9abd8', 'd0be45d1445d3809']}
+}
+
+ +

Note: This will remove all of the matching values from the Array

Dpd.js #

+ +

dpd.js is an auto-generated library that provides access to Collections and other Deployd features on the front-end. For a basic overview, see Accessing Collections with dpd.js.

Accessing the Collection #

+ +

The API for your Collection is automatically generated as dpd.[collectionname].

+ +

Examples:

+ +
dpd.todos
+dpd.users
+dpd.todolists
+
+ +

Note: If your Collection name has a dash in it (e.g. /todo-lists), the dash is removed when accessing it in this way (e.g. dpd.todolists).

+ +

You can also access your collection by using dpd(collectionName) as a function.

+ +

Examples:

+ +
dpd('todos')
+dpd('users')
+dpd('todo-lists')
+
+ +

Note: Collections accessed in this way will not have helper functions besides get, post, put, del, and exec (see Dpd.js for Custom Resources for details on these generic functions)

Collection API #

+ +

The examples below use a Collection called /todos with the following schema:

+ +
    +
  • id
  • +
  • string title
  • +
  • string category
  • +

Callbacks #

+ +

Every function in the Collection API takes a callback function (represented by fn in the docs) with the signature function(result, error).

+ +

The callback will be executed asynchronously when the API has received a response from the server.

+ +

The result argument differs depending on the function. If the result failed, it will be null and the error argument will contain the error message.

+ +

The error argument, if there was an error, is an object:

+ +
    +
  • status (number): The HTTP status code of the request. Common codes include: +
    • 400 - Bad Request: The request contained invalid data and could not be completed
    • +
    • 401 - Unauthorized: The current session is not authorized to perform that action
    • +
    • 500 - Internal Server Error: Something went wrong on the server
  • +
  • message (string): A message describing the error. Not always present.
  • +
  • errors (object): A hash of error messages corresponding to the properties of the object that were sent - usually indicates validation errors. Not always present.
  • +
+ +

Examples of errors:

+ +
{
+  "status": 401,
+  "message": "You are not allowed to access that collection!"
+}
+
+ + + +
{
+  "status": 400,
+  "errors": {
+      "title": "Title must be less than 100 characters",
+      "category": "Not a valid category"
+  }
+}
+

.get([id], [query], fn) #

Listing Data #
+ +

The .get(fn) function returns an array of objects in the collection.

+ +
// Get all todos
+dpd.todos.get(function(results, error) {
+  //Do something
+});
+
+ +

results is an array of objects:

+ +
[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }, {
+    "id": "320d6151a9aad8ce"
+    "title": "Write autobiography",
+    "category": "writing"
+  }
+]
+
+ +

If the collection has no objects, it will be an empty array:

+ +
[]    
+
Querying Data #
+ +

The .get(query, fn) function filters results by the specified query object. See Querying Collections for information on constructing a query.

+ +
// Get all todos that are in the pets category
+dpd.todos.get({category: 'pets'}, function(results, error) {
+  // Do something
+});
+
+ +

results is an array of objects:

+ +
[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }
+]
+
Getting a Specific Object #
+ +

The .get(id, fn) function returns a single object by its id property.

+ +
// Get a specific todo
+dpd.todos.get("320d6151a9aad8ce", function(result, error) {
+  // Do something
+});
+
+ +

result is the object that you requested:

+ +
{
+  "id": "320d6151a9aad8ce",
+  "title": "Wash the dog",
+  "category": "pets"
+}
+

.post([id], object, fn) #

Creating an Object #
+ +

The .post(object, fn) function creates an object in the collection with the specified properties.

+ +
// Create a todo
+dpd.todos.post({title: "Walk the dog"}, function(result, error)) {
+  // Do something
+});
+
+ +

result is the object that you posted, with any additional calculated properties and the id:

+ +
{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the dog"
+}
+
Updating an Object #
+ +

The .post(id, object, fn) function, or .post(object, fn) where object has an id property, will update an object. Using the .post() function in this way behaves the same as the put() function.

+ +

This is useful when you want to insert an object if it does not exist and update it if it does.

.put([id or query], object, fn) #

Updating an Object #
+ +

The .put(id, object, fn) function will update an object that is already in the collection. It will only change the properties that are provided. It is also possible to incrementally update certain properties; see Updating Objects in Collections for details.

+ +
// Update a todo
+dpd.todos.put("91c621a3026ca8ef", {title: "Walk the cat"}, function(result, error)) {
+  // Do something
+});
+
+ +

You can also use the syntax put(object, fn) if object has an id property:

+ +
// Update a todo
+dpd.todos.put({id: "91c621a3026ca8ef", title: "Walk the cat"}, function(result, error)) {
+  // Do something
+});
+
+ +

Finally, you can provide a query object to ensure that the object you are updating has the correct properties. You must still provide an id property. This can be useful as a failsafe.

+ +
// Update a todo only if it is in the "pets" category
+dpd.todos.put(
+  {id: "91c621a3026ca8ef", category: "pets"},
+  {title: "Walk the cat"},
+  function(result, error) {
+    // Do something
+  });
+
+ +

result is the entire object after the update:

+ +
{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the cat",
+  "category": "pets"
+}
+
+ +

The .put() function will return an error if the id and/or query does not match any object in the collection:

+ +
{
+  "status":400,
+  "message":"No object exists that matches that query"
+}
+

.del(id or query, fn) #

Deleting an Object #
+ +

The .del(id, fn) function will delete an object from the collection.

+ +
// Delete an object
+dpd.todos.del("91c621a3026ca8ef", function(result, error) {
+  // Do something
+});
+
+ +

You can also use the syntax .del(query, fn) if object has an id property. You can add additional properties to the query object to ensure that you are removing the correct object:

+ +
// Delete an object
+dpd.todos.del({id: "91c621a3026ca8ef", title: "Walk the dog"}, function(result, error) {
+  // Do something
+});
+
+ +

result will always be null.

Realtime API #

dpd.on(message, fn) #

+ +

The dpd.on(message, fn) function listens for realtime messages emitted from the server. See Notifying the Client of Changes for information on sending realtime messages with the emit() function.

+ +
    +
  • message - The name of the message to listen for
  • +
  • fn - Callback function(messageData). Called every time the message is received. There is no error argument.
  • +
+ + + +
// Listen for a new todo
+dpd.on('todos:create', function(post) {
+  // Do something
+});
+
+ +

In your Collection Event:

+ +
// On Post
+emit('todos:create', this); 
+
+ +

Calling .on() on the collection itself will namespace the message by the collection name:

+ +
// Same as dpd.on('todos:create', fn)
+dpd.todos.on('create', function(post) {
+  // Do something
+});
+

dpd.off(message, [fn]) #

+ +

The dpd.off(message) function stops listening for the specified message.

+ +
dpd.off('todos:create');
+
+ +

You can also provide a function that was originally set as a listener to remove only that function.

+ +
function onTodoCreated(post) {
+  // Do something
+}
+
+dpd.on('todos:create', onTodoCreated);
+
+dpd.off('todos:create', onTodoCreated);
+
+ +

Calling .off() on the collection itself will namespace the message by the collection name:

+ +
// Same as dpd.off('todos:create');
+dpd.todos.off('create');
+

dpd.once(message, fn) #

+ +

The dpd.once(message, fn) function listens for a realtime message emitted by the server and runs the fn callback exactly once.

+ +
dpd.once('todos:create', function(post) {
+  // Do something
+});
+
+ +

Calling .once() on the collection itself will namespace the message by the collection name:

+ +
// Same as dpd.once('todos:create');
+dpd.todos.once('create', function(post) {
+  // Do something
+});
+

dpd.socketReady(fn) #

+ +

The dpd.socketReady(fn) function waits for a connection to be established to the server and executes the fn callback with no arguments. If a connection has already been established, it will execute the fn callback immediately.

+ +

It can sometimes take a second or more to establish a connection, and messages sent during this time will not be received by your front end. This function is useful for ensuring that you will receive an message when it is broadcast.

+ +
dpd.socketReady(function() {
+  // Do something
+});
+

dpd.socket #

+ +

The dpd.socket object is a socket.io object. This is useful if you want to finely control how messages are received.

+ + + + +

Collections #

+ +

The most commonly used resource in a Deployd app is the Collection. It exposes a database like API that allows any client to query, modify and sync the data in your app, all without having to write a ton of boilerplate code on the server.

Properties #

+ +

Collection properties allow you to restrict what type of data a collection can store. You define them using the property editor in the dashboard.

+ +

Property Editor

Data #

+ +

Collection's use JSON to store and transport your objects over the wire. Deployd comes bundled with a fully featured data-editor for easily managing the data in your collection.

Events #

+ +

Control the behavior and business logic of the data in your collection by writing events. Events also allow you to easily create relationships between collections.

Notifying Clients of Changes #

+ +

Deployd allows you to send messages to the browser in real time when a Collection is updated.

+ + + +

More

+ + + +
+
+
+

Other docs in "Docs"

+ +
+
+ + + +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/accessing-collections.md.html b/docs/collections/accessing-collections.md.html new file mode 100644 index 0000000..94f38ca --- /dev/null +++ b/docs/collections/accessing-collections.md.html @@ -0,0 +1,524 @@ + + + + + + Accessing Collections with dpd.js - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Accessing Collections with dpd.js #

+ +

dpd.js is an auto-generated library that updates as you update the resources in your Deployd API. If you are writing your front-end in the public directory, include a script tag tag in your HTML:

+ +
<script src="/dpd.js" type="text/javascript"></script>
+
+ +

Note: The dpd.js file will not appear in the public directory because it is generated at runtime.

Example Usage #

+ +
dpd.todos.get(function(todos, error) {
+  if (error) {
+    alert(error.message);
+  } else {
+    for (var i = 0; i < todos.length; i++) {
+      renderTodo(todos[i]);
+    };
+  }
+});
+
+ +

Dpd.js functions are asynchronous: they do not return a value, but execute a callback function when the AJAX operation is complete.

+ +
// Does not work
+var result = dpd.todos.get();
+
+ + + +
// Works as expected
+dpd.todos.get(function(result, error) {
+  // Work with result
+});
+
+ +

For details on using dpd.js, see the dpd.js reference

+ +

Also see A Simple Todo App for a working example.

Using dpd.js on a different origin #

+ +

You can use the dpd.js library outside of the public folder by using an absolute URL to the file.

+ +

This will not work on browsers that do not support Cross-Origin Resource Sharing (namely Internet Explorer 7 and below).

Accessing Collections without Dpd.js #

+ +

The dpd.js library is not required; it is only a utility library for accessing Deployd's HTTP API with AJAX. For details on the HTTP API, see the HTTP API Refernence.

+ +

Some front-end libraries include support for HTTP or REST APIs; for examples of how to use these instead of dpd.js, see A Simple Todo App with Backbone and A Simple Todo App with AngularJS

+ + +

More

+ + + + +
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/adding-logic.md.html b/docs/collections/adding-logic.md.html new file mode 100644 index 0000000..6554721 --- /dev/null +++ b/docs/collections/adding-logic.md.html @@ -0,0 +1,551 @@ + + + + + + Adding Custom Business Logic with Events - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Adding Custom Business Logic with Events #

+ +

Events allow you to add custom business logic to your Collection. By writing Events, you can add validation, relationships, and security to your app. Events are written in JavaScript (specifically, the ECMAScript 5 standard) and have access to the Collection Events API.

+ +

The following events are available for scripting:

On Get #

+ +

Called whenever an object is loaded from the server. Commonly used to hide properties, restrict access to private objects, and calculate dynamic values.

+ +
// Example On Get: Hide Secret Properties
+if (!me || me.id !== this.creatorId) {
+  hide('secret');
+}
+
+ + + +
// Example On Get: Load A Post's Comments
+if (query.loadComments) {
+  dpd.comments.get({postId: this.id}, function(comments) {
+    this.comments = comments;
+  });  
+}
+
+ +

Note: When a list of objects is loaded, On Get will run once for each object in the list. Calling cancel() in this case will remove the object from the list, rather than cancelling the entire request.

On Validate #

+ +

Called whenever an object's values change, including when it is first created. Commonly used to validate property values and calculate certain dynamic values (i.e. last modified time).

+ +
// Example On Validate: Enforce a max length
+if (this.body.length > 100) {
+  error('body', "Cannot be more than 100 characters");
+}
+
+ + + +
// Example On Validate: Normalize an @handle
+if (this.handle.indexOf('@') !== 0) {
+  this.handle = '@' + this.handle;
+}
+
+ +

Note: On Post or On Put will execute after On Validate, unless cancel() or error() is called

On Post #

+ +

Called when an object is created. Commonly used to prevent unauthorized creation and save data relevant to the creation of an object, such as its creator.

+ +
// Example On Post: Save the date created
+this.createdDate = new Date().getTime();
+
+ + + +
// Example On Post: Prevent unauthorized users from posting
+if (!me) {
+  cancel("You must be logged in", 401);
+}
+

On Put #

+ +

Called when an object is updated. Commonly used to restrict editing access to certain roles, or to protect certain properties from editing. It is strongly recommended that you protect() any properties that should not be modifiable by users after an object is created.

+ +
// Example On Put: Protect readonly/automatic properties
+protect('createdDate');
+protect('creatorId');
+

On Delete #

+ +

Called when an object is deleted. Commonly used to prevent unauthorized deletion.

+ +
// Example On Delete: Prevent non-admins from deleting
+if (!me || me.role !== 'admin') {
+  cancel("You must be an admin to delete this", 401);
+}
+
+ + +

More

+ + + + +
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/advanced-guides-include=all.html b/docs/collections/advanced-guides-include=all.html new file mode 100644 index 0000000..f40b6cf --- /dev/null +++ b/docs/collections/advanced-guides-include=all.html @@ -0,0 +1,548 @@ + + + + + + Advanced Guides - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Accessing Collections - Building a Custom Client #

+ +

In this guide, we will build an HTTP client from scratch to perform CRUD as well as listen for events from a Collection.

REST #

+ +

Most REST clients should work with Deployd Collections right away, though Deployd does not strictly follow REST. For example, Backbone.js and AngularJS's HTTP utilities work with Deployd without modification.

WebSockets #

+ +

To fully implement the Collection API, a client must be compatible with WebSockets and Socket.IO specifically. Clients are responsible for sending heartbeat information as well as reconnecting in the case of unexpected disconnects.

Building a Node.js Client #

+ +

The following is implemented in Node.js, but the basic idea can be applied to any language or platform.

Basics #

+ +

All we need to create a collection client is a constructor and a single method for making requests.

+ +
var request = require('request');
+
+function Collection(url) {
+  this.url = url
+}
+
+Collection.prototype.request = function (options, fn) {
+  var url = this.url;
+  options.url = url + (options.url || '');  
+  request(options, function (err, res, body) {
+    if(res.statusCode >= 400) {
+      err = body || {message: 'an unknown error occurred'};
+      return fn(err);
+    }
+
+    fn(null, body);
+  });
+}
+
+ +

Now we can construct new collections by passing the URL as the only argument to our constructor.

+ +
var c = new Collection('http://foo.deploydapp.com/todos');
+
+c.request({url: '?done=false'}, function(err, todos) {
+  console.log(todos); // [...]
+});
+
+ +

We can add an object to our collection by passing an object as the json body and setting the method to "POST".

+ +
var todo = {
+  title: 'wash the car'
+};
+
+c.request({json: todo, method: 'POST'}, function(err, todo) {
+  console.log(todo); // {id: '...', ...}
+});
+
+ +

To update an object we just need to set the method to "PUT".

+ +
var todo = {
+  id: '06a5254f11ff7853',
+  done: true
+};
+
+c.request({json: todo, method: 'PUT'}, function(err, todo) {
+  console.log(todo); // {id: '...', ...}
+});
+
+ +

Deleting an object requires an ID and the method must be set to "DELETE".

+ +
var id = '06a5254f11ff7853';
+
+c.request({url: '/' + id, method: 'DELETE'}, function(err, todo) {
+  console.log(err); // null - if no error occurred
+});
+

Listening to Events #

+ +

The simplest way to listen events is to use a Socket.IO client. You can find a list of clients here.

+ +

Using the node.js Socket.IO client, we can create a socket by connecting to our deployed app. Then calling the socket's on() method to listen to a custom event emitted by a collection.

+ +
var io = require('socket.io-client');
+var socket = io.connect('http://foo.deploydapp.com');
+
+socket.on('my event', function (data) {
+  console.log(data); // emit()ed from the server
+});
+
+ + + +

More

+ + + + +
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/advanced-guides/custom-client.md.html b/docs/collections/advanced-guides/custom-client.md.html new file mode 100644 index 0000000..8300382 --- /dev/null +++ b/docs/collections/advanced-guides/custom-client.md.html @@ -0,0 +1,533 @@ + + + + + + Building a Custom Client - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Accessing Collections - Building a Custom Client #

+ +

In this guide, we will build an HTTP client from scratch to perform CRUD as well as listen for events from a Collection.

REST #

+ +

Most REST clients should work with Deployd Collections right away, though Deployd does not strictly follow REST. For example, Backbone.js and AngularJS's HTTP utilities work with Deployd without modification.

WebSockets #

+ +

To fully implement the Collection API, a client must be compatible with WebSockets and Socket.IO specifically. Clients are responsible for sending heartbeat information as well as reconnecting in the case of unexpected disconnects.

Building a Node.js Client #

+ +

The following is implemented in Node.js, but the basic idea can be applied to any language or platform.

Basics #

+ +

All we need to create a collection client is a constructor and a single method for making requests.

+ +
var request = require('request');
+
+function Collection(url) {
+  this.url = url
+}
+
+Collection.prototype.request = function (options, fn) {
+  var url = this.url;
+  options.url = url + (options.url || '');  
+  request(options, function (err, res, body) {
+    if(res.statusCode >= 400) {
+      err = body || {message: 'an unknown error occurred'};
+      return fn(err);
+    }
+
+    fn(null, body);
+  });
+}
+
+ +

Now we can construct new collections by passing the URL as the only argument to our constructor.

+ +
var c = new Collection('http://foo.deploydapp.com/todos');
+
+c.request({url: '?done=false'}, function(err, todos) {
+  console.log(todos); // [...]
+});
+
+ +

We can add an object to our collection by passing an object as the json body and setting the method to "POST".

+ +
var todo = {
+  title: 'wash the car'
+};
+
+c.request({json: todo, method: 'POST'}, function(err, todo) {
+  console.log(todo); // {id: '...', ...}
+});
+
+ +

To update an object we just need to set the method to "PUT".

+ +
var todo = {
+  id: '06a5254f11ff7853',
+  done: true
+};
+
+c.request({json: todo, method: 'PUT'}, function(err, todo) {
+  console.log(todo); // {id: '...', ...}
+});
+
+ +

Deleting an object requires an ID and the method must be set to "DELETE".

+ +
var id = '06a5254f11ff7853';
+
+c.request({url: '/' + id, method: 'DELETE'}, function(err, todo) {
+  console.log(err); // null - if no error occurred
+});
+

Listening to Events #

+ +

The simplest way to listen events is to use a Socket.IO client. You can find a list of clients here.

+ +

Using the node.js Socket.IO client, we can create a socket by connecting to our deployed app. Then calling the socket's on() method to listen to a custom event emitted by a collection.

+ +
var io = require('socket.io-client');
+var socket = io.connect('http://foo.deploydapp.com');
+
+socket.on('my event', function (data) {
+  console.log(data); // emit()ed from the server
+});
+
+ + +

More

+ + + +
+
+
+

Other docs in "Advanced Guides"

+
    + +
+
+
+ + + +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/creating-collections.md.html b/docs/collections/creating-collections.md.html new file mode 100644 index 0000000..edf1ed7 --- /dev/null +++ b/docs/collections/creating-collections.md.html @@ -0,0 +1,513 @@ + + + + + + Creating Collections - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Creating Collections #

+ +

A Collection exposes a database-like API directly to clients over HTTP and WebSockets. Clients can run advanced queries, create and update objects, and listen for realtime messages to sync with the Collection when it updates. You can create a Collection in the dashboard by clicking the "Resources +" button in the sidebar, and choosing "Collection".

Properties #

+ +

Every Collection requires a set of properties that describe the data it can store. By default every object in a Collection is created with an id. If an object being POSTed or PUT into a Collection includes properties or values that don't match what the collection allows, they will be ignored. The following property types are available when creating a Collection:

+ +
    +
  • String - Acts like a JavaScript string
  • +
  • Number - Stores numeric values, including floating points.
  • +
  • Boolean - Either true or false. (To avoid confusion, Deployd will consider null or undefined to be false)
  • +
  • Object - Stores any JSON object. Useful for storing arbitrary data on an object without needing to validate schema.
  • +
  • Array - Stores an array of any type.
  • +

The Data Editor #

+ +

Once you create a Collection from the dashboard, you can add and edit its data using the data editor. The data editor is designed to edit all sorts of data, including objects and arrays.

Basic Use #

+ +

Double-click in a cell to start editing. Press Enter to save your changes, or Escape to cancel and undo your changes.

+ +

While editing a string property, click the "edit" icon next to the field to open up a multiline editor.

+ +

Click the trash can icon in any row to delete it.

+ +

Edit the bottom-most row to create a new object. Press Enter when editing a property to save the row, or click the checkmark in the margin.

Useful Shortcuts #

+ +
    +
  • Use the arrow keys to move your selection without using the mouse.
  • +
  • Press "Enter" when a cell is selected to start editing.
  • +
  • Start typing when a cell is selected to overwrite its existing value.
  • +
  • If you accidentally save a change, press Ctrl/Cmd-Z to reverse it.
  • +
  • Press Ctrl-Delete to remove a row. Press Ctrl/Cmd-Z to add it back. (heads up: it will have a different id)
  • +
  • Press Ctrl-Enter to open up the multiline editor for a string property; this lets you write long text values.
  • +
  • Press Ctrl-Enter while in the multiline editor to save it (pressing Enter will just create a new line)
  • +
  • Press Tab to save the current property and edit the next one.
  • +
+ + +

More

+ + + + +
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/examples-include=all.html b/docs/collections/examples-include=all.html new file mode 100644 index 0000000..6906442 --- /dev/null +++ b/docs/collections/examples-include=all.html @@ -0,0 +1,530 @@ + + + + + + Examples - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

A Simple Todo App #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using dpd.js.

+ +

Download View Source

Useful files #

+ +
+ + + + +

A Simple Todo App with AngularJS #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using the AngularJS framework.

+ +

Download View Source

Useful files #

+ +
+ + + + +

A Simple Todo App with Backbone.js #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using Backbone.js.

+ +

Download View Source

Useful files #

+ +
+ + + + +

Chatroom #

+ +

Todo app

+ +

This app demonstrates how to send messages to the client using Sockets when data is updated on the server.

+ +

Download View Source

Useful files #

+ +
+ + + +

More

+ + + + +
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/examples/a-simple-todo-app-with-angular.md.html b/docs/collections/examples/a-simple-todo-app-with-angular.md.html new file mode 100644 index 0000000..e7f1cff --- /dev/null +++ b/docs/collections/examples/a-simple-todo-app-with-angular.md.html @@ -0,0 +1,471 @@ + + + + + + A Simple Todo App with AngularJS - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

A Simple Todo App with AngularJS #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using the AngularJS framework.

+ +

Download View Source

Useful files #

+ +
+ + +

More

+ + + +
+
+
+

Other docs in "Examples"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/examples/a-simple-todo-app-with-backbone.md.html b/docs/collections/examples/a-simple-todo-app-with-backbone.md.html new file mode 100644 index 0000000..f051b54 --- /dev/null +++ b/docs/collections/examples/a-simple-todo-app-with-backbone.md.html @@ -0,0 +1,471 @@ + + + + + + A Simple Todo App with Backbone.js - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

A Simple Todo App with Backbone.js #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using Backbone.js.

+ +

Download View Source

Useful files #

+ +
+ + +

More

+ + + +
+
+
+

Other docs in "Examples"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/examples/a-simple-todo-app.md.html b/docs/collections/examples/a-simple-todo-app.md.html new file mode 100644 index 0000000..a317884 --- /dev/null +++ b/docs/collections/examples/a-simple-todo-app.md.html @@ -0,0 +1,470 @@ + + + + + + A Simple Todo App - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

A Simple Todo App #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using dpd.js.

+ +

Download View Source

Useful files #

+ +
+ + +

More

+ + + +
+
+
+

Other docs in "Examples"

+ +
+
+ + + +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/examples/chatroom.md.html b/docs/collections/examples/chatroom.md.html new file mode 100644 index 0000000..9e483f8 --- /dev/null +++ b/docs/collections/examples/chatroom.md.html @@ -0,0 +1,472 @@ + + + + + + Chatroom - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Chatroom #

+ +

Todo app

+ +

This app demonstrates how to send messages to the client using Sockets when data is updated on the server.

+ +

Download View Source

Useful files #

+ +
+ + +

More

+ + + +
+ + + + +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/notifying-clients.md.html b/docs/collections/notifying-clients.md.html new file mode 100644 index 0000000..7451aa7 --- /dev/null +++ b/docs/collections/notifying-clients.md.html @@ -0,0 +1,525 @@ + + + + + + Notifying the Client of Changes with Messages - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Notifying the Client of Changes with Messages #

+ +

Keeping all of the clients of your API up-to-date with your collection's latest data is simple with collection events. For example, in a PUT event, you can notify all connected clients of the changes to the object being updated by calling the emit() function to send all connected users a message.

+ +

The emit() function takes an event argument and an arbitrary data object to send to all of the connected clients (eg. emit('my message', {foo: 'bar'})). Dpd.js clients can listen for these events using the on() method (eg. dpd.todos.on('my message', fn)).

Example #

+ +

Let's say you want to make a chatroom app and you have a Collection called /messages.

+ +

In the On POST event of /messages, you would add the following line:

+ +
emit('messages:create', this);
+
+ +

This sends a message called messages:create (This could be anything) with the current object (this) as an argument. The messages: prefix namespaces the event to the collection.

+ +

On the client, you would listen for that event using dpd.on() and respond by updating the DOM:

+ +
dpd.messages.on('create', function(message) {
+  renderMessage(message);
+});
+
+ +

The message argument is the value you passed on the server (this).

+ +

See the Chatroom Example for a working version of this code.

Browser and Server Support #

+ +

The realtime messaging features of Deployd are built on Socket.IO and work on almost every major browser:

+ +
    +
  • Internet Explorer 5.5+
  • +
  • Safari 3+
  • +
  • Google Chrome 4+
  • +
  • Firefox 3+
  • +
  • Opera 10.61+
  • +
  • iOS Safari
  • +
  • Android WebKit
  • +
  • WebOS WebKit
  • +
+ +

(taken from Socket.IO's site)

+ + +

More

+ + + + +
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/reference-include=all.html b/docs/collections/reference-include=all.html new file mode 100644 index 0000000..473be56 --- /dev/null +++ b/docs/collections/reference-include=all.html @@ -0,0 +1,1621 @@ + + + + + + Reference - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Event API #

this #

+ +

The current object is represented as this. You can always read its properties. Modifying its properties in an On Get request will change the result that the client receives, while modifying its properties in an On Post, On Put, or On Validate will change the value in the database.

+ +
// Example: On Validate
+// If a property is too long, truncate it
+if (this.message.length > 140) {
+  this.message = this.message.substring(0, 137) + '...';
+}
+
+ +

Note: In some cases, the meaning of this will change to something less useful inside of a function. If you are using functions such as Array.forEach(), you may need to bind another variable to this:

+ +
// Won't work - sum remains at 0
+this.sum = 0;
+this.targets.forEach(function(t) {
+  this.sum += t.points;
+});
+
+ + + +
//Works as expected
+var self = this;
+
+this.sum = 0;
+this.targets.forEach(function(t) {
+  self.sum += t.points;
+});
+

me #

+ +

The currently logged in User from a User Collection. undefined if no user is logged in.

+ +
// Example: On Post
+// Save the creator's information
+if (me) {
+    this.creatorId = me.id;
+    this.creatorName = me.name;
+}
+

isMe() #

+ +
isMe(id)
+
+ +

Checks whether the current user matches the provided id.

+ +
// Example: On Get /users
+// Hide properties unless this is the current user
+if (!isMe(this.id)) {
+    hide('privateVariable');
+}
+
+ + + +
// Example: On Put 
+// Make sure that only the creator can edit a post
+cancelUnless(isMe(this.id), "You are not authorized to edit that post", 401);
+

query #

+ +

The query string object. On a specific query (such as /posts/a59551a90be9abd8), this includes an id property.

+ +
// Example: On Get
+// Don't show the body of a post in a general query
+if (!query.id) {
+  hide(this.body);
+}
+

cancel() #

+ +
cancel(message, [statusCode])
+
+ +

Stops the current request with the provided error message and HTTP status code. Status code defaults to 400. Commonly used for security and authorization.

+ +

It is strongly recommended that you cancel() any events that are not accessible to your front-end, because your API is open to anyone.

+ +
// Example: On Post
+// Don't allow non-admins to create items
+if (!me.admin) {
+  cancel("You are not authorized to do that", 401);
+}
+
+ +

Note: In a GET event where multiple values are queried (such as on /posts), the cancel() function will remove the current item from the results without an error message.

cancelIf(), cancelUnless() #

+ +
cancelIf(condition, message, [statusCode])
+cancelUnless(condition, message, [statusCode])
+
+ +

Calls cancel(message, statusCode) if the provided condition is truthy (for cancelIf()) or falsy (for cancelUnless()).

+ +
Example: On Post
+// Prevent banned users from posting
+cancelUnless(me, "You are not logged in", 401);
+cancelIf(me.isBanned, "You are banned", 401);
+

error() #

+ +
error(key, message)
+
+ +

Adds an error message to an errors object in the response. Cancels the request, but continues running the event so it can collect multiple errors to display to the user. Commonly used for validation.

+ +
// Example: On Validate
+// Don't allow certain words
+// Returns response {"errors": {"name": "Contains forbidden words"}}
+if (!this.name.match(/(foo|bar)/)) {
+  error('name', "Contains forbidden words");
+}
+

errorIf(), errorUnless() #

+ +
errorIf(condition, key, message)
+errorUnless(condition, key, message)
+
+ +

Calls error(key, message) if the provided condition is truthy (for errorIf()) or falsy (for errorUnless()).

+ +
// Example: On Validate
+// Require message to be a certain length
+errorUnless(this.message && this.message.length > 2, 'message', "Must be at least 2 characters");
+

hide() #

+ +
hide(property)
+
+ +

Hides a property from the response.

+ +
// Example: On Get
+// Don't show private information
+if (!me || me.id !== this.creatorId) {
+  hide('secret');
+}
+

protect() #

+ +
protect(property)
+
+ +

Prevents a property from being updated. It is strongly recommended you protect() any properties that should not be modified after an object is created.

+ +
// Example: On Put
+// Protect a property
+protect('createdDate');
+
+ + + +
// Example: On Put
+// Only the creator can change the title
+if (!(me && me.id === this.creatorId)) {
+  protect('title');
+}
+

changed() #

+ +
changed(property)
+
+ +

Returns whether a property has been updated.

+ +
// Example: On Put
+// Validate the title when it changes
+if(changed('title') && this.title.length < 5) {
+  error('title', 'must be over 5 characters');
+}
+

previous #

+ +

An Object containing the previous values of the item to be updated.

+ +
// Example: On Put
+if(this.votes < previous.votes) {
+  emit('votes have decreased');
+}
+

emit() #

+ +
emit([userCollection, query], message, [data])
+
+ +

Emits a realtime message to the client.

+ +
// Example: On Post
+// Alert clients that a new post has been created
+emit('postCreated', this);
+
+ +

In the front end:

+ +
// Listen for new posts
+dpd.on('postCreated', function(post) {
+    //do something...
+});
+
+ +

You can use userCollection and query parameters to limit the message broadcast to specific users.

+ +
// Example: On Put
+// Alert the owner that their post has been modified
+if (me.id !== this.creatorId) {
+  emit(dpd.users, {id: this.creatorId}, 'postModified', this); 
+} 
+
+ +

See Notifying Clients of Changes with Sockets for an overview on realtime functionality.

dpd #

+ +

The entire dpd.js library, except for the realtime functions, is available in events. It will also properly bind this in callbacks.

+ +
// Example: On Get
+// If specific query, get comments
+dpd.comments.get({postId: this.id}, function(results) {
+  this.comments = results;
+});
+
+ + + +
// Example: On Delete
+// Log item elsewhere
+dpd.archived.post(this);
+
+ +

Dpd.js will prevent recursive requests if you set the $limitRecursion property. This works by returning null from a dpd function call that has already been called several times further up in the stack.

+ +
// Example: On Get /recursive
+// Call self
+dpd.recursive.get({$limitRecursion: 1}, function(results) {
+    if (results) this.recursive = results;
+});
+
+ + + +
// GET /recursive
+{
+    "id": "a59551a90be9abd8",
+    "recursive": [
+        {
+            "id": "a59551a90be9abd8"    
+        }
+    ]
+}
+

internal #

+ +

Equal to true if this request has been sent by another script.

+ +
// Example: On GET /posts
+// Posts with a parent are invisible, but are counted by their parent
+if (this.parentId && !internal) cancel();
+
+dpd.posts.get({parentId: this.id}, function(posts) {
+    this.childPosts = posts.length;
+});
+

isRoot #

+ +

Equal to true if this request has been authenticated as root (has the dpd-ssh-key header with the appropriate key; such as from the dashboard)

+ +
// Example: On PUT /users
+// Protect reputation property - should only be calculated by a custom script.
+
+if (!isRoot) protect('reputation');
+

console.log() #

+ +
console.log([arguments]...)
+
+ +

Logs the values provided to the command line. Useful for debugging.

+ + + + +

Accessing Collections Over HTTP #

+ +

Deployd exposes an HTTP API to your Collections which can be used by any platform or library that supports HTTP or AJAX. Though it does not strictly adhere to REST, it should also work with most libraries designed for REST.

Collection API #

+ +

The examples below use a Collection called /todos with the following schema:

+ +
    +
  • id
  • +
  • string title
  • +
  • string category
  • +
+ +

Your Collection is available at the URL you specified. If you are using the default development hostname of localhost:2403, for example, the /todos collection will be available at http://localhost:2403/todos.

Requests #

+ +

A request to the Deployd API should include the Content-Type header. The following content types are supported:

+ +
    +
  • application/json (recommended)
  • +
  • application/x-www-form-urlencoded (All values will be parsed as strings)
  • +
+ +

The Content-Type header is not necessary for GET or DELETE requests which have no body.

Responses #

+ +

Deployd will send standard HTTP status codes depending on the results on an operation. If the code is 200 (OK), the request was successful and the result is available in the body as JSON.

+ +

If the code is 204 (No Content), the request was successful, but there is no result.

+ +

If the code is 400 or greater, it will return the error message formatted as a JSON object:

+ +
    +
  • status (number): The HTTP status code of the request. Common codes include: +
    • 400 - Bad Request: The request contained invalid data and could not be completed
    • +
    • 401 - Unauthorized: The current session is not authorized to perform that action
    • +
    • 500 - Internal Server Error: Something went wrong on the server
  • +
  • message (string): A message describing the error. Not always present.
  • +
  • errors (object): A hash of error messages corresponding to the properties of the object that was sent - usually indicates validation errors. Not always present.
  • +
+ +

Examples of errors:

+ +
{
+  "status": 401,
+  "message": "You are not allowed to access that collection!"
+}
+
+ + + +
{
+  "status": 400,
+  "errors": {
+      "title": "Title must be less than 100 characters",
+      "category": "Not a valid category"
+  }
+}
+

Listing Data #

+ +

To retreive an array of objects in the collection, send a GET request to your collection's path:

+ +
GET /todos
+
+ +

The response will be an array of objects:

+ +
200 OK
+[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }, {
+    "id": "320d6151a9aad8ce"
+    "title": "Write autobiography",
+    "category": "writing"
+  }
+]
+
+ +

If the collection has no objects, it will be an empty array:

+ +
200 OK
+[]    
+

Querying Data #

+ +

To filter results by the specified query object, send a GET request to your collection's path with a query string. See Querying Collections for information on constructing a query.

+ +
GET /todos?category=pets
+
+ +

For more advanced queries, you will need to pass the query string as JSON instead:

+ +
GET /todos?{"category": "pets"}
+
+ +

The response body is an array of objects:

+ +
200 OK
+[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }
+]
+

Getting a Specific Object #

+ +

To retrieve a single object by its id property, send a GET request with the id value as the path.

+ +
GET /todos/320d6151a9aad8ce
+
+ +

The response body is the object that you requested:

+ +
200 OK
+{
+  "id": "320d6151a9aad8ce",
+  "title": "Wash the dog",
+  "category": "pets"
+}
+

Creating an Object #

+ +

To create an object in the collection, send a POST request with the object's properties in the body.

+ +
POST /todos
+{
+  "title": "Walk the dog"
+}
+
+ +

The response body is the object that you posted, with any additional calculated properties and the id:

+ +
{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the dog"
+}
+

Updating an Object #

+ +

To update an object that is already in the collection, send a POST or PUT request with the id value as the path and with the properties you wish to update in the body. It will only change the properties that are provided. It is also possible to incrementally update certain properties; see Updating Objects in Collections for details.

+ +
PUT /todos/91c621a3026ca8ef
+{
+  "title": "Walk the cat"
+}
+
+ + + +
POST /todos/91c621a3026ca8ef
+{
+  "title": "Walk the cat"
+}
+
+ +

You can also omit the id in the path if you provide an id property in the body:

+ +
PUT /todos
+{
+  "id": "91c621a3026ca8ef"
+  "title": "Walk the cat"
+}
+
+ +

Finally, you can provide a query string to ensure that the object you are updating has the correct properties. You must still provide an id. This can be useful as a failsafe.

+ +
PUT /todos/91c621a3026ca8ef?category=pets
+{
+  "title": "Walk the cat"
+}
+
+ +

The response body is the entire object after the update:

+ +
200 OK  
+{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the cat",
+  "category": "pets"
+}
+
+ +

The PUT verb will return an error if the id and/or query does not match any object in the collection:

+ +
400 Bad Request
+{
+  "status": 400,
+  "message": "No object exists that matches that query"
+}
+

Deleting an Object #

+ +

To delete an object from the collection, send a DELETE request with the id value as a path.

+ +
DELETE /todos/91c621a3026ca8ef
+
+ +

You can also pass a query string to ensure that you are removing the correct object:

+ +
DELETE /todos/91c621a3026ca8ef?title=Walk the dog
+
+ +

You can omit the id in the path if you provide it in the query string:

+ +
DELETE /todos?id=91c621a3026ca8ef&title=Walk the dog
+
+ +

The response body will always be empty.

Realtime API #

+ +

Deployd uses Socket.io for its realtime functionality. If you are not using dpd.js, you can use the Socket.io client library.

+ +
var socket = io.connect('/');
+socket.on('todos:create', function(todo) {
+  // Do something
+});
+
+ +

The Socket.io community has created client libraries for other languages and platforms as well.

Root Requests #

+ +

You can elevate your session to root access by adding the header dpd-ssh-key. It must have the value of your app's key (you can find this by typing dpd showkey into the command line); although in the development environment, the dpd-ssh-key header can have any value.

+ +

Sending a request as root has several effects. Most notably, you can use the {$skipEvents: true} property in either the query string or request body. This will cause events not to run. This is useful for bypassing authentication or validation.

+ +

Your front-end app should never gain root access, and you should never store the app's key in a place where it can be accessed by users, even if they understand the system. This is primarily useful for writing data management utilities for yourself, other developers, and system administrators.

Examples #

+ +

The examples below show how to use various JavaScript front-end libraries to access a Collection called /todos.

jQuery #

+ +
$.ajax('/todos', {
+  type: "GET",
+  success: function(todos) {
+    // Do something
+  },
+  error: function(xhr) {
+    alert(xhr.responseText);
+  }
+});
+
+$.ajax('/todos', {
+  type: "POST",
+  contentType: "application/json",
+  data: JSON.stringify({
+    title: "Walk the dog"
+  }),
+  success: function(todo) {
+    // Do something
+  }, 
+  error: function(xhr) {
+    alert(xhr.responseText);
+  }
+});
+
+ +

Note: When providing a request body, jQuery defaults to form encoding. Deployd works best with a JSON body, so you'll need to set the contentType option and manually convert to JSON.

Backbone.js #

+ +
var Todo = Backbone.Model.extend({});
+var Todos = Backbone.Collection.extend({
+  model: Todo,
+  url: "/todos"
+});
+
+var todos = new Todos();  
+
+todos.fetch({
+  success: function(collection, response) {
+    // Do something
+  }, error: function(collection, response) {
+    alert(response);
+  }
+});
+
+todos.create({
+  title: "Walk the dog"
+}, {
+  success: function(collection, response) {
+    // Do something
+  }, error: function(collection, response) {
+    alert(response);
+  }
+});
+

Angular.js #

+ +

Using $http:

+ +
function Controller($scope, $http) {
+  $http.get('/todos')
+    .success(function(todos) {
+      $scope.todos = todos;
+    })
+    .error(function(err) {
+      alert(err);
+    });
+
+  $http.post('/todos', {
+      title: "Walk the dog"
+    })
+    .success(function(todo) {
+      // Do something
+    })
+    .error(function(err) {
+      alert(err);
+    });
+}
+
+ +

Using ngResource:

+ +
var myApp = angular.module('myApp', ['ngResource']);
+
+myApp.factory('Todos', function($resource) {
+  return $resource('/todos/:todoId', {todoId: '@id'});
+});
+
+function Controller($scope, Todos) {
+  $scope.todos = Todos.query(function(response) {
+    // Do something
+  }, function(error) {
+    alert(error);
+  });
+
+  Todos.save({
+    title: "Walk the dog"
+  }, function(todo) {
+    // Do something
+  }, function(error) {
+    alert(error);
+  });
+}
+
+myApp.controller('Controller', Controller);
+

Cross-Origin Requests #

+ +

The most common bug when implementing a CORS client for Deploy is to include headers that are not allowed. A client must not send any custom headers besides the following:

+ +
Origin, Accept, Accept-Language, Content-Language, Content-Type, Last-Event-ID
+
+ +

This will not work on browsers that do not support Cross-Origin Resource Sharing (namely Internet Explorer 7 and below).

Cross-Origin Requests with dpd.js #

+ +

When using dpd.js, all the required CORS headers are sent by default to any domain. You don't have to make any changes to your requests. dpd.js takes care of it for you.

Cross-Origin Requests with jQuery #

+ +

When using jQuery.ajax() on cross-origin requests the credentials are not sent along with the request automatically. You have to add them to each ajax() request using the xhrFields parameter. Here is an example of login followed by getting some data.

+ +
// Logging a user in.
+$.ajax({
+  url: 'http://<domain>:<port>/users/login',
+  type: "POST",
+  data: {username:"un", password:"pw"},
+  cache: false,
+  xhrFields:{
+    withCredentials: true
+  },
+  success: function(data) {
+    console.log(data);
+  },
+  error: function(xhr) {
+    console.log(xhr.responseText);
+  }
+});
+
+// On subsequent requests or in the success callback above.  (After having logged in) 
+$.ajax({
+  url: 'http://<domain>:<port>/<collection>',
+  type: "GET",
+  cache: false,
+  xhrFields:{
+    withCredentials: true
+  },
+  success: function(data) {
+    console.log(data);
+  },
+  error: function(xhr) {
+    console.log(xhr.responseText);
+  }
+});
+

HTTP method override #

+ +

Provides faux HTTP method support.

+ +

Most browsers doesn’t support methods other than “GET” and “POST” when it comes to submitting forms. So It's support something like 'Rails'.

+ +

Pass an optional key to use when checking for a method override, othewise defaults to _method. The original method is available via req.originalMethod.

+ +

It's support both URL query and POST body

+ +
URL       : ?_method=METHOD_NAME or
+JSON body : { _method: 'METHOD_NAME' }
+
+ +

$.ajax({ + type: "POST", + url : "/todos/"+ todoId, + data: { _method:"DELETE" }, + success: function(res) {

Ajax Example #

+ +
$.ajax({
+  type : "POST",
+  url  : "/todos/OBJECT_ID"
+  data : { _method:"DELETE" },
+  success: function(todo) {
+    // Object was deleted. response body empty.
+  }, 
+  error: function(xhr) {}
+});
+
+or
+
+$.ajax({
+  type : "POST",
+  url  : "/todos/OBJECT_ID?_method=DELETE",
+  success: function(todo) {
+    // Object was deleted. response body empty.
+  }, 
+  error: function(xhr) {}
+});
+
+ + + + +

Querying Collections #

Simple Queries #

+ +

Collections can be queried over HTTP using the query string.

+ +

This example will return all the posts with an author "Joe":

+ +
GET /posts?author=Joe   
+

Advanced Queries #

+ +

When querying a Collection, you can use special commands to create a more advanced query.

+ +

Deployd supports all of MongoDB's conditional operators; only the common operators and Deployd's custom commands are documented here.

+ +

When using an advanced query in REST, you must pass JSON as the query string, for example:

+ +
GET /posts?{"likes": {"$gt": 10}}
+
+ +

If you are using dpd.js, this will be handled automatically.

Comparison ($gt, $lt, $gte, $lte) #

+ +

Compares a Number property to a given value.

+ +
    +
  • $gt - Greater than
  • +
  • $lt - Less than
  • +
  • $gte - Greater than or equal to
  • +
  • $lte - Less than or equal to

    + +
    // Finds all posts with more than 10 likes
    +{
    +    likes: {$gt: 10}
    +}
    +
  • +

$ne (Not Equal) #

+ +

The $ne command lets you choose a value to exclude.

+ +
// Get all posts except those posted by Bob
+{
+    author: {$ne: "Bob"}
+}
+

$in #

+ +

The $in command allows you to specify an array of possible matches.

+ +
// Get articles in the "food", "business", and "technology" categories
+{
+    category: {$in: ["food", "business", "technology"]}
+}
+

$regex #

+ +

The $regex command allows you to specify a regular expression to match a string property.

+ +

You can also use the $options command to specify regular expression flags.

+ +
// Get usernames that might be email addresses (x@y.z)
+{
+    "username": {$regex: "[a-z0-9\-]+@[a-z0-9\-]+\.[a-z0-9\-]+", $options: 'i' }
+}
+

Query commands #

+ +

Query commands apply to the entire query, not just a single property.

$fields #

+ +

The $fields command allows you to include or exclude properties from your results.

+ +
    // Exclude the "email" property
+    {
+        $fields: {email: 0}
+    }
+
+ + + +
    // Only include the "title" property
+    {
+        $fields: {title: 1}
+    }
+

$or #

+ +

The $or command allows you to specify multiple queries for an object to match in an array.

+ +
// Get all public posts and all posts by a specified user (even if those are private)
+{
+    $or: [{
+      isPublic: true
+    }, {
+      creator: "Bob"
+    }]
+}
+

$sort #

+ +

The $sort command allows you to order your results by the value of a property. The value can be 1 for ascending sort (lowest first; A-Z, 0-10) or -1 for descending (highest first; Z-A, 10-0)

+ +
// Sort posts by likes, descending
+{
+    $sort: {likes: -1}
+}
+

$limit #

+ +

The $limit command allows you to limit the amount of objects that are returned from a query. This is commonly used for paging, along with $skip.

+ +
// Return the top 10 scores
+{
+    $sort: {score: -1},
+    $limit: 10
+}
+

$skip #

+ +

The $skip command allows you to exclude a given number of the first objects returned from a query. This is commonly used for paging, along with $limit.

+ +
// Return the third page of posts, with 10 posts per page
+{
+    $skip: 20,
+    $limit: 10
+}
+

$limitRecursion #

+ +

The $limitRecursion command allows you to override the default recursive limits in Deployd. This is useful when you want to query a very deeply nested structure of data. Otherwise you can still query nested structures, but Deployd will stop the recursion after 2 levels. See the Collection Relationships guide for more info.

+ + + + +

Updating Objects in Collections #

+ +

When updating an object in a Collection, you can use special modifier commands to more granularly change property values.

$inc #

+ +

The $inc command increments the value of a given Number property.

+ +
// Give a player 5 points
+{
+  score: {$inc: 5}
+}
+

$push #

+ +

The $push command adds a value to an Array property.

+ +
// Add a follower to a user by storing their id.
+{
+  followers: {$push: 'a59551a90be9abd8'}
+}
+

$pushAll #

+ +

The $pushAll command adds multiple values to an Array property.

+ +
// Add mentions of users
+{
+  mentions: {
+    $pushAll: ['a59551a90be9abd8', 'd0be45d1445d3809']
+  }
+}
+

$pull #

+ +

The $pull command removes a value from an Array property.

+ +
// Remove a user from followers
+{
+  followers: {$pull: 'a59551a90be9abd8'}
+}
+
+ +

Note: If there is more than one matching value in the Array, this will remove all of them

$pullAll #

+ +

The $pullAll command removes multiple values from an Array property.

+ +
// Remove multiple users
+{
+  followers: {$pullAll: ['a59551a90be9abd8', 'd0be45d1445d3809']}
+}
+
+ +

Note: This will remove all of the matching values from the Array

+ + + + +

Dpd.js #

+ +

dpd.js is an auto-generated library that provides access to Collections and other Deployd features on the front-end. For a basic overview, see Accessing Collections with dpd.js.

Accessing the Collection #

+ +

The API for your Collection is automatically generated as dpd.[collectionname].

+ +

Examples:

+ +
dpd.todos
+dpd.users
+dpd.todolists
+
+ +

Note: If your Collection name has a dash in it (e.g. /todo-lists), the dash is removed when accessing it in this way (e.g. dpd.todolists).

+ +

You can also access your collection by using dpd(collectionName) as a function.

+ +

Examples:

+ +
dpd('todos')
+dpd('users')
+dpd('todo-lists')
+
+ +

Note: Collections accessed in this way will not have helper functions besides get, post, put, del, and exec (see Dpd.js for Custom Resources for details on these generic functions)

Collection API #

+ +

The examples below use a Collection called /todos with the following schema:

+ +
    +
  • id
  • +
  • string title
  • +
  • string category
  • +

Callbacks #

+ +

Every function in the Collection API takes a callback function (represented by fn in the docs) with the signature function(result, error).

+ +

The callback will be executed asynchronously when the API has received a response from the server.

+ +

The result argument differs depending on the function. If the result failed, it will be null and the error argument will contain the error message.

+ +

The error argument, if there was an error, is an object:

+ +
    +
  • status (number): The HTTP status code of the request. Common codes include: +
    • 400 - Bad Request: The request contained invalid data and could not be completed
    • +
    • 401 - Unauthorized: The current session is not authorized to perform that action
    • +
    • 500 - Internal Server Error: Something went wrong on the server
  • +
  • message (string): A message describing the error. Not always present.
  • +
  • errors (object): A hash of error messages corresponding to the properties of the object that were sent - usually indicates validation errors. Not always present.
  • +
+ +

Examples of errors:

+ +
{
+  "status": 401,
+  "message": "You are not allowed to access that collection!"
+}
+
+ + + +
{
+  "status": 400,
+  "errors": {
+      "title": "Title must be less than 100 characters",
+      "category": "Not a valid category"
+  }
+}
+

.get([id], [query], fn) #

Listing Data #
+ +

The .get(fn) function returns an array of objects in the collection.

+ +
// Get all todos
+dpd.todos.get(function(results, error) {
+  //Do something
+});
+
+ +

results is an array of objects:

+ +
[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }, {
+    "id": "320d6151a9aad8ce"
+    "title": "Write autobiography",
+    "category": "writing"
+  }
+]
+
+ +

If the collection has no objects, it will be an empty array:

+ +
[]    
+
Querying Data #
+ +

The .get(query, fn) function filters results by the specified query object. See Querying Collections for information on constructing a query.

+ +
// Get all todos that are in the pets category
+dpd.todos.get({category: 'pets'}, function(results, error) {
+  // Do something
+});
+
+ +

results is an array of objects:

+ +
[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }
+]
+
Getting a Specific Object #
+ +

The .get(id, fn) function returns a single object by its id property.

+ +
// Get a specific todo
+dpd.todos.get("320d6151a9aad8ce", function(result, error) {
+  // Do something
+});
+
+ +

result is the object that you requested:

+ +
{
+  "id": "320d6151a9aad8ce",
+  "title": "Wash the dog",
+  "category": "pets"
+}
+

.post([id], object, fn) #

Creating an Object #
+ +

The .post(object, fn) function creates an object in the collection with the specified properties.

+ +
// Create a todo
+dpd.todos.post({title: "Walk the dog"}, function(result, error)) {
+  // Do something
+});
+
+ +

result is the object that you posted, with any additional calculated properties and the id:

+ +
{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the dog"
+}
+
Updating an Object #
+ +

The .post(id, object, fn) function, or .post(object, fn) where object has an id property, will update an object. Using the .post() function in this way behaves the same as the put() function.

+ +

This is useful when you want to insert an object if it does not exist and update it if it does.

.put([id or query], object, fn) #

Updating an Object #
+ +

The .put(id, object, fn) function will update an object that is already in the collection. It will only change the properties that are provided. It is also possible to incrementally update certain properties; see Updating Objects in Collections for details.

+ +
// Update a todo
+dpd.todos.put("91c621a3026ca8ef", {title: "Walk the cat"}, function(result, error)) {
+  // Do something
+});
+
+ +

You can also use the syntax put(object, fn) if object has an id property:

+ +
// Update a todo
+dpd.todos.put({id: "91c621a3026ca8ef", title: "Walk the cat"}, function(result, error)) {
+  // Do something
+});
+
+ +

Finally, you can provide a query object to ensure that the object you are updating has the correct properties. You must still provide an id property. This can be useful as a failsafe.

+ +
// Update a todo only if it is in the "pets" category
+dpd.todos.put(
+  {id: "91c621a3026ca8ef", category: "pets"},
+  {title: "Walk the cat"},
+  function(result, error) {
+    // Do something
+  });
+
+ +

result is the entire object after the update:

+ +
{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the cat",
+  "category": "pets"
+}
+
+ +

The .put() function will return an error if the id and/or query does not match any object in the collection:

+ +
{
+  "status":400,
+  "message":"No object exists that matches that query"
+}
+

.del(id or query, fn) #

Deleting an Object #
+ +

The .del(id, fn) function will delete an object from the collection.

+ +
// Delete an object
+dpd.todos.del("91c621a3026ca8ef", function(result, error) {
+  // Do something
+});
+
+ +

You can also use the syntax .del(query, fn) if object has an id property. You can add additional properties to the query object to ensure that you are removing the correct object:

+ +
// Delete an object
+dpd.todos.del({id: "91c621a3026ca8ef", title: "Walk the dog"}, function(result, error) {
+  // Do something
+});
+
+ +

result will always be null.

Realtime API #

dpd.on(message, fn) #

+ +

The dpd.on(message, fn) function listens for realtime messages emitted from the server. See Notifying the Client of Changes for information on sending realtime messages with the emit() function.

+ +
    +
  • message - The name of the message to listen for
  • +
  • fn - Callback function(messageData). Called every time the message is received. There is no error argument.
  • +
+ + + +
// Listen for a new todo
+dpd.on('todos:create', function(post) {
+  // Do something
+});
+
+ +

In your Collection Event:

+ +
// On Post
+emit('todos:create', this); 
+
+ +

Calling .on() on the collection itself will namespace the message by the collection name:

+ +
// Same as dpd.on('todos:create', fn)
+dpd.todos.on('create', function(post) {
+  // Do something
+});
+

dpd.off(message, [fn]) #

+ +

The dpd.off(message) function stops listening for the specified message.

+ +
dpd.off('todos:create');
+
+ +

You can also provide a function that was originally set as a listener to remove only that function.

+ +
function onTodoCreated(post) {
+  // Do something
+}
+
+dpd.on('todos:create', onTodoCreated);
+
+dpd.off('todos:create', onTodoCreated);
+
+ +

Calling .off() on the collection itself will namespace the message by the collection name:

+ +
// Same as dpd.off('todos:create');
+dpd.todos.off('create');
+

dpd.once(message, fn) #

+ +

The dpd.once(message, fn) function listens for a realtime message emitted by the server and runs the fn callback exactly once.

+ +
dpd.once('todos:create', function(post) {
+  // Do something
+});
+
+ +

Calling .once() on the collection itself will namespace the message by the collection name:

+ +
// Same as dpd.once('todos:create');
+dpd.todos.once('create', function(post) {
+  // Do something
+});
+

dpd.socketReady(fn) #

+ +

The dpd.socketReady(fn) function waits for a connection to be established to the server and executes the fn callback with no arguments. If a connection has already been established, it will execute the fn callback immediately.

+ +

It can sometimes take a second or more to establish a connection, and messages sent during this time will not be received by your front end. This function is useful for ensuring that you will receive an message when it is broadcast.

+ +
dpd.socketReady(function() {
+  // Do something
+});
+

dpd.socket #

+ +

The dpd.socket object is a socket.io object. This is useful if you want to finely control how messages are received.

+ + + +

More

+ + + + +
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/reference/dpd-js.md.html b/docs/collections/reference/dpd-js.md.html new file mode 100644 index 0000000..7414de2 --- /dev/null +++ b/docs/collections/reference/dpd-js.md.html @@ -0,0 +1,757 @@ + + + + + + Using dpd.js - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Dpd.js #

+ +

dpd.js is an auto-generated library that provides access to Collections and other Deployd features on the front-end. For a basic overview, see Accessing Collections with dpd.js.

Accessing the Collection #

+ +

The API for your Collection is automatically generated as dpd.[collectionname].

+ +

Examples:

+ +
dpd.todos
+dpd.users
+dpd.todolists
+
+ +

Note: If your Collection name has a dash in it (e.g. /todo-lists), the dash is removed when accessing it in this way (e.g. dpd.todolists).

+ +

You can also access your collection by using dpd(collectionName) as a function.

+ +

Examples:

+ +
dpd('todos')
+dpd('users')
+dpd('todo-lists')
+
+ +

Note: Collections accessed in this way will not have helper functions besides get, post, put, del, and exec (see Dpd.js for Custom Resources for details on these generic functions)

Collection API #

+ +

The examples below use a Collection called /todos with the following schema:

+ +
    +
  • id
  • +
  • string title
  • +
  • string category
  • +

Callbacks #

+ +

Every function in the Collection API takes a callback function (represented by fn in the docs) with the signature function(result, error).

+ +

The callback will be executed asynchronously when the API has received a response from the server.

+ +

The result argument differs depending on the function. If the result failed, it will be null and the error argument will contain the error message.

+ +

The error argument, if there was an error, is an object:

+ +
    +
  • status (number): The HTTP status code of the request. Common codes include: +
    • 400 - Bad Request: The request contained invalid data and could not be completed
    • +
    • 401 - Unauthorized: The current session is not authorized to perform that action
    • +
    • 500 - Internal Server Error: Something went wrong on the server
  • +
  • message (string): A message describing the error. Not always present.
  • +
  • errors (object): A hash of error messages corresponding to the properties of the object that were sent - usually indicates validation errors. Not always present.
  • +
+ +

Examples of errors:

+ +
{
+  "status": 401,
+  "message": "You are not allowed to access that collection!"
+}
+
+ + + +
{
+  "status": 400,
+  "errors": {
+      "title": "Title must be less than 100 characters",
+      "category": "Not a valid category"
+  }
+}
+

.get([id], [query], fn) #

Listing Data #
+ +

The .get(fn) function returns an array of objects in the collection.

+ +
// Get all todos
+dpd.todos.get(function(results, error) {
+  //Do something
+});
+
+ +

results is an array of objects:

+ +
[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }, {
+    "id": "320d6151a9aad8ce"
+    "title": "Write autobiography",
+    "category": "writing"
+  }
+]
+
+ +

If the collection has no objects, it will be an empty array:

+ +
[]    
+
Querying Data #
+ +

The .get(query, fn) function filters results by the specified query object. See Querying Collections for information on constructing a query.

+ +
// Get all todos that are in the pets category
+dpd.todos.get({category: 'pets'}, function(results, error) {
+  // Do something
+});
+
+ +

results is an array of objects:

+ +
[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }
+]
+
Getting a Specific Object #
+ +

The .get(id, fn) function returns a single object by its id property.

+ +
// Get a specific todo
+dpd.todos.get("320d6151a9aad8ce", function(result, error) {
+  // Do something
+});
+
+ +

result is the object that you requested:

+ +
{
+  "id": "320d6151a9aad8ce",
+  "title": "Wash the dog",
+  "category": "pets"
+}
+

.post([id], object, fn) #

Creating an Object #
+ +

The .post(object, fn) function creates an object in the collection with the specified properties.

+ +
// Create a todo
+dpd.todos.post({title: "Walk the dog"}, function(result, error)) {
+  // Do something
+});
+
+ +

result is the object that you posted, with any additional calculated properties and the id:

+ +
{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the dog"
+}
+
Updating an Object #
+ +

The .post(id, object, fn) function, or .post(object, fn) where object has an id property, will update an object. Using the .post() function in this way behaves the same as the put() function.

+ +

This is useful when you want to insert an object if it does not exist and update it if it does.

.put([id or query], object, fn) #

Updating an Object #
+ +

The .put(id, object, fn) function will update an object that is already in the collection. It will only change the properties that are provided. It is also possible to incrementally update certain properties; see Updating Objects in Collections for details.

+ +
// Update a todo
+dpd.todos.put("91c621a3026ca8ef", {title: "Walk the cat"}, function(result, error)) {
+  // Do something
+});
+
+ +

You can also use the syntax put(object, fn) if object has an id property:

+ +
// Update a todo
+dpd.todos.put({id: "91c621a3026ca8ef", title: "Walk the cat"}, function(result, error)) {
+  // Do something
+});
+
+ +

Finally, you can provide a query object to ensure that the object you are updating has the correct properties. You must still provide an id property. This can be useful as a failsafe.

+ +
// Update a todo only if it is in the "pets" category
+dpd.todos.put(
+  {id: "91c621a3026ca8ef", category: "pets"},
+  {title: "Walk the cat"},
+  function(result, error) {
+    // Do something
+  });
+
+ +

result is the entire object after the update:

+ +
{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the cat",
+  "category": "pets"
+}
+
+ +

The .put() function will return an error if the id and/or query does not match any object in the collection:

+ +
{
+  "status":400,
+  "message":"No object exists that matches that query"
+}
+

.del(id or query, fn) #

Deleting an Object #
+ +

The .del(id, fn) function will delete an object from the collection.

+ +
// Delete an object
+dpd.todos.del("91c621a3026ca8ef", function(result, error) {
+  // Do something
+});
+
+ +

You can also use the syntax .del(query, fn) if object has an id property. You can add additional properties to the query object to ensure that you are removing the correct object:

+ +
// Delete an object
+dpd.todos.del({id: "91c621a3026ca8ef", title: "Walk the dog"}, function(result, error) {
+  // Do something
+});
+
+ +

result will always be null.

Realtime API #

dpd.on(message, fn) #

+ +

The dpd.on(message, fn) function listens for realtime messages emitted from the server. See Notifying the Client of Changes for information on sending realtime messages with the emit() function.

+ +
    +
  • message - The name of the message to listen for
  • +
  • fn - Callback function(messageData). Called every time the message is received. There is no error argument.
  • +
+ + + +
// Listen for a new todo
+dpd.on('todos:create', function(post) {
+  // Do something
+});
+
+ +

In your Collection Event:

+ +
// On Post
+emit('todos:create', this); 
+
+ +

Calling .on() on the collection itself will namespace the message by the collection name:

+ +
// Same as dpd.on('todos:create', fn)
+dpd.todos.on('create', function(post) {
+  // Do something
+});
+

dpd.off(message, [fn]) #

+ +

The dpd.off(message) function stops listening for the specified message.

+ +
dpd.off('todos:create');
+
+ +

You can also provide a function that was originally set as a listener to remove only that function.

+ +
function onTodoCreated(post) {
+  // Do something
+}
+
+dpd.on('todos:create', onTodoCreated);
+
+dpd.off('todos:create', onTodoCreated);
+
+ +

Calling .off() on the collection itself will namespace the message by the collection name:

+ +
// Same as dpd.off('todos:create');
+dpd.todos.off('create');
+

dpd.once(message, fn) #

+ +

The dpd.once(message, fn) function listens for a realtime message emitted by the server and runs the fn callback exactly once.

+ +
dpd.once('todos:create', function(post) {
+  // Do something
+});
+
+ +

Calling .once() on the collection itself will namespace the message by the collection name:

+ +
// Same as dpd.once('todos:create');
+dpd.todos.once('create', function(post) {
+  // Do something
+});
+

dpd.socketReady(fn) #

+ +

The dpd.socketReady(fn) function waits for a connection to be established to the server and executes the fn callback with no arguments. If a connection has already been established, it will execute the fn callback immediately.

+ +

It can sometimes take a second or more to establish a connection, and messages sent during this time will not be received by your front end. This function is useful for ensuring that you will receive an message when it is broadcast.

+ +
dpd.socketReady(function() {
+  // Do something
+});
+

dpd.socket #

+ +

The dpd.socket object is a socket.io object. This is useful if you want to finely control how messages are received.

+ + +

More

+ + + +
+
+
+

Other docs in "Reference"

+ +
+
+ + + +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/reference/event-api.md.html b/docs/collections/reference/event-api.md.html new file mode 100644 index 0000000..a9f860e --- /dev/null +++ b/docs/collections/reference/event-api.md.html @@ -0,0 +1,727 @@ + + + + + + Event API - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Event API #

this #

+ +

The current object is represented as this. You can always read its properties. Modifying its properties in an On Get request will change the result that the client receives, while modifying its properties in an On Post, On Put, or On Validate will change the value in the database.

+ +
// Example: On Validate
+// If a property is too long, truncate it
+if (this.message.length > 140) {
+  this.message = this.message.substring(0, 137) + '...';
+}
+
+ +

Note: In some cases, the meaning of this will change to something less useful inside of a function. If you are using functions such as Array.forEach(), you may need to bind another variable to this:

+ +
// Won't work - sum remains at 0
+this.sum = 0;
+this.targets.forEach(function(t) {
+  this.sum += t.points;
+});
+
+ + + +
//Works as expected
+var self = this;
+
+this.sum = 0;
+this.targets.forEach(function(t) {
+  self.sum += t.points;
+});
+

me #

+ +

The currently logged in User from a User Collection. undefined if no user is logged in.

+ +
// Example: On Post
+// Save the creator's information
+if (me) {
+    this.creatorId = me.id;
+    this.creatorName = me.name;
+}
+

isMe() #

+ +
isMe(id)
+
+ +

Checks whether the current user matches the provided id.

+ +
// Example: On Get /users
+// Hide properties unless this is the current user
+if (!isMe(this.id)) {
+    hide('privateVariable');
+}
+
+ + + +
// Example: On Put 
+// Make sure that only the creator can edit a post
+cancelUnless(isMe(this.id), "You are not authorized to edit that post", 401);
+

query #

+ +

The query string object. On a specific query (such as /posts/a59551a90be9abd8), this includes an id property.

+ +
// Example: On Get
+// Don't show the body of a post in a general query
+if (!query.id) {
+  hide(this.body);
+}
+

cancel() #

+ +
cancel(message, [statusCode])
+
+ +

Stops the current request with the provided error message and HTTP status code. Status code defaults to 400. Commonly used for security and authorization.

+ +

It is strongly recommended that you cancel() any events that are not accessible to your front-end, because your API is open to anyone.

+ +
// Example: On Post
+// Don't allow non-admins to create items
+if (!me.admin) {
+  cancel("You are not authorized to do that", 401);
+}
+
+ +

Note: In a GET event where multiple values are queried (such as on /posts), the cancel() function will remove the current item from the results without an error message.

cancelIf(), cancelUnless() #

+ +
cancelIf(condition, message, [statusCode])
+cancelUnless(condition, message, [statusCode])
+
+ +

Calls cancel(message, statusCode) if the provided condition is truthy (for cancelIf()) or falsy (for cancelUnless()).

+ +
Example: On Post
+// Prevent banned users from posting
+cancelUnless(me, "You are not logged in", 401);
+cancelIf(me.isBanned, "You are banned", 401);
+

error() #

+ +
error(key, message)
+
+ +

Adds an error message to an errors object in the response. Cancels the request, but continues running the event so it can collect multiple errors to display to the user. Commonly used for validation.

+ +
// Example: On Validate
+// Don't allow certain words
+// Returns response {"errors": {"name": "Contains forbidden words"}}
+if (!this.name.match(/(foo|bar)/)) {
+  error('name', "Contains forbidden words");
+}
+

errorIf(), errorUnless() #

+ +
errorIf(condition, key, message)
+errorUnless(condition, key, message)
+
+ +

Calls error(key, message) if the provided condition is truthy (for errorIf()) or falsy (for errorUnless()).

+ +
// Example: On Validate
+// Require message to be a certain length
+errorUnless(this.message && this.message.length > 2, 'message', "Must be at least 2 characters");
+

hide() #

+ +
hide(property)
+
+ +

Hides a property from the response.

+ +
// Example: On Get
+// Don't show private information
+if (!me || me.id !== this.creatorId) {
+  hide('secret');
+}
+

protect() #

+ +
protect(property)
+
+ +

Prevents a property from being updated. It is strongly recommended you protect() any properties that should not be modified after an object is created.

+ +
// Example: On Put
+// Protect a property
+protect('createdDate');
+
+ + + +
// Example: On Put
+// Only the creator can change the title
+if (!(me && me.id === this.creatorId)) {
+  protect('title');
+}
+

changed() #

+ +
changed(property)
+
+ +

Returns whether a property has been updated.

+ +
// Example: On Put
+// Validate the title when it changes
+if(changed('title') && this.title.length < 5) {
+  error('title', 'must be over 5 characters');
+}
+

previous #

+ +

An Object containing the previous values of the item to be updated.

+ +
// Example: On Put
+if(this.votes < previous.votes) {
+  emit('votes have decreased');
+}
+

emit() #

+ +
emit([userCollection, query], message, [data])
+
+ +

Emits a realtime message to the client.

+ +
// Example: On Post
+// Alert clients that a new post has been created
+emit('postCreated', this);
+
+ +

In the front end:

+ +
// Listen for new posts
+dpd.on('postCreated', function(post) {
+    //do something...
+});
+
+ +

You can use userCollection and query parameters to limit the message broadcast to specific users.

+ +
// Example: On Put
+// Alert the owner that their post has been modified
+if (me.id !== this.creatorId) {
+  emit(dpd.users, {id: this.creatorId}, 'postModified', this); 
+} 
+
+ +

See Notifying Clients of Changes with Sockets for an overview on realtime functionality.

dpd #

+ +

The entire dpd.js library, except for the realtime functions, is available in events. It will also properly bind this in callbacks.

+ +
// Example: On Get
+// If specific query, get comments
+dpd.comments.get({postId: this.id}, function(results) {
+  this.comments = results;
+});
+
+ + + +
// Example: On Delete
+// Log item elsewhere
+dpd.archived.post(this);
+
+ +

Dpd.js will prevent recursive requests if you set the $limitRecursion property. This works by returning null from a dpd function call that has already been called several times further up in the stack.

+ +
// Example: On Get /recursive
+// Call self
+dpd.recursive.get({$limitRecursion: 1}, function(results) {
+    if (results) this.recursive = results;
+});
+
+ + + +
// GET /recursive
+{
+    "id": "a59551a90be9abd8",
+    "recursive": [
+        {
+            "id": "a59551a90be9abd8"    
+        }
+    ]
+}
+

internal #

+ +

Equal to true if this request has been sent by another script.

+ +
// Example: On GET /posts
+// Posts with a parent are invisible, but are counted by their parent
+if (this.parentId && !internal) cancel();
+
+dpd.posts.get({parentId: this.id}, function(posts) {
+    this.childPosts = posts.length;
+});
+

isRoot #

+ +

Equal to true if this request has been authenticated as root (has the dpd-ssh-key header with the appropriate key; such as from the dashboard)

+ +
// Example: On PUT /users
+// Protect reputation property - should only be calculated by a custom script.
+
+if (!isRoot) protect('reputation');
+

console.log() #

+ +
console.log([arguments]...)
+
+ +

Logs the values provided to the command line. Useful for debugging.

+ + +

More

+ + + +
+
+
+

Other docs in "Reference"

+ +
+
+ + + +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/reference/http.md.html b/docs/collections/reference/http.md.html new file mode 100644 index 0000000..4dd4d0d --- /dev/null +++ b/docs/collections/reference/http.md.html @@ -0,0 +1,877 @@ + + + + + + Over HTTP - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Accessing Collections Over HTTP #

+ +

Deployd exposes an HTTP API to your Collections which can be used by any platform or library that supports HTTP or AJAX. Though it does not strictly adhere to REST, it should also work with most libraries designed for REST.

Collection API #

+ +

The examples below use a Collection called /todos with the following schema:

+ +
    +
  • id
  • +
  • string title
  • +
  • string category
  • +
+ +

Your Collection is available at the URL you specified. If you are using the default development hostname of localhost:2403, for example, the /todos collection will be available at http://localhost:2403/todos.

Requests #

+ +

A request to the Deployd API should include the Content-Type header. The following content types are supported:

+ +
    +
  • application/json (recommended)
  • +
  • application/x-www-form-urlencoded (All values will be parsed as strings)
  • +
+ +

The Content-Type header is not necessary for GET or DELETE requests which have no body.

Responses #

+ +

Deployd will send standard HTTP status codes depending on the results on an operation. If the code is 200 (OK), the request was successful and the result is available in the body as JSON.

+ +

If the code is 204 (No Content), the request was successful, but there is no result.

+ +

If the code is 400 or greater, it will return the error message formatted as a JSON object:

+ +
    +
  • status (number): The HTTP status code of the request. Common codes include: +
    • 400 - Bad Request: The request contained invalid data and could not be completed
    • +
    • 401 - Unauthorized: The current session is not authorized to perform that action
    • +
    • 500 - Internal Server Error: Something went wrong on the server
  • +
  • message (string): A message describing the error. Not always present.
  • +
  • errors (object): A hash of error messages corresponding to the properties of the object that was sent - usually indicates validation errors. Not always present.
  • +
+ +

Examples of errors:

+ +
{
+  "status": 401,
+  "message": "You are not allowed to access that collection!"
+}
+
+ + + +
{
+  "status": 400,
+  "errors": {
+      "title": "Title must be less than 100 characters",
+      "category": "Not a valid category"
+  }
+}
+

Listing Data #

+ +

To retreive an array of objects in the collection, send a GET request to your collection's path:

+ +
GET /todos
+
+ +

The response will be an array of objects:

+ +
200 OK
+[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }, {
+    "id": "320d6151a9aad8ce"
+    "title": "Write autobiography",
+    "category": "writing"
+  }
+]
+
+ +

If the collection has no objects, it will be an empty array:

+ +
200 OK
+[]    
+

Querying Data #

+ +

To filter results by the specified query object, send a GET request to your collection's path with a query string. See Querying Collections for information on constructing a query.

+ +
GET /todos?category=pets
+
+ +

For more advanced queries, you will need to pass the query string as JSON instead:

+ +
GET /todos?{"category": "pets"}
+
+ +

The response body is an array of objects:

+ +
200 OK
+[
+  {
+    "id": "320d6151a9aad8ce",
+    "title": "Wash the dog",
+    "category": "pets"
+  }
+]
+

Getting a Specific Object #

+ +

To retrieve a single object by its id property, send a GET request with the id value as the path.

+ +
GET /todos/320d6151a9aad8ce
+
+ +

The response body is the object that you requested:

+ +
200 OK
+{
+  "id": "320d6151a9aad8ce",
+  "title": "Wash the dog",
+  "category": "pets"
+}
+

Creating an Object #

+ +

To create an object in the collection, send a POST request with the object's properties in the body.

+ +
POST /todos
+{
+  "title": "Walk the dog"
+}
+
+ +

The response body is the object that you posted, with any additional calculated properties and the id:

+ +
{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the dog"
+}
+

Updating an Object #

+ +

To update an object that is already in the collection, send a POST or PUT request with the id value as the path and with the properties you wish to update in the body. It will only change the properties that are provided. It is also possible to incrementally update certain properties; see Updating Objects in Collections for details.

+ +
PUT /todos/91c621a3026ca8ef
+{
+  "title": "Walk the cat"
+}
+
+ + + +
POST /todos/91c621a3026ca8ef
+{
+  "title": "Walk the cat"
+}
+
+ +

You can also omit the id in the path if you provide an id property in the body:

+ +
PUT /todos
+{
+  "id": "91c621a3026ca8ef"
+  "title": "Walk the cat"
+}
+
+ +

Finally, you can provide a query string to ensure that the object you are updating has the correct properties. You must still provide an id. This can be useful as a failsafe.

+ +
PUT /todos/91c621a3026ca8ef?category=pets
+{
+  "title": "Walk the cat"
+}
+
+ +

The response body is the entire object after the update:

+ +
200 OK  
+{
+  "id": "91c621a3026ca8ef",
+  "title": "Walk the cat",
+  "category": "pets"
+}
+
+ +

The PUT verb will return an error if the id and/or query does not match any object in the collection:

+ +
400 Bad Request
+{
+  "status": 400,
+  "message": "No object exists that matches that query"
+}
+

Deleting an Object #

+ +

To delete an object from the collection, send a DELETE request with the id value as a path.

+ +
DELETE /todos/91c621a3026ca8ef
+
+ +

You can also pass a query string to ensure that you are removing the correct object:

+ +
DELETE /todos/91c621a3026ca8ef?title=Walk the dog
+
+ +

You can omit the id in the path if you provide it in the query string:

+ +
DELETE /todos?id=91c621a3026ca8ef&title=Walk the dog
+
+ +

The response body will always be empty.

Realtime API #

+ +

Deployd uses Socket.io for its realtime functionality. If you are not using dpd.js, you can use the Socket.io client library.

+ +
var socket = io.connect('/');
+socket.on('todos:create', function(todo) {
+  // Do something
+});
+
+ +

The Socket.io community has created client libraries for other languages and platforms as well.

Root Requests #

+ +

You can elevate your session to root access by adding the header dpd-ssh-key. It must have the value of your app's key (you can find this by typing dpd showkey into the command line); although in the development environment, the dpd-ssh-key header can have any value.

+ +

Sending a request as root has several effects. Most notably, you can use the {$skipEvents: true} property in either the query string or request body. This will cause events not to run. This is useful for bypassing authentication or validation.

+ +

Your front-end app should never gain root access, and you should never store the app's key in a place where it can be accessed by users, even if they understand the system. This is primarily useful for writing data management utilities for yourself, other developers, and system administrators.

Examples #

+ +

The examples below show how to use various JavaScript front-end libraries to access a Collection called /todos.

jQuery #

+ +
$.ajax('/todos', {
+  type: "GET",
+  success: function(todos) {
+    // Do something
+  },
+  error: function(xhr) {
+    alert(xhr.responseText);
+  }
+});
+
+$.ajax('/todos', {
+  type: "POST",
+  contentType: "application/json",
+  data: JSON.stringify({
+    title: "Walk the dog"
+  }),
+  success: function(todo) {
+    // Do something
+  }, 
+  error: function(xhr) {
+    alert(xhr.responseText);
+  }
+});
+
+ +

Note: When providing a request body, jQuery defaults to form encoding. Deployd works best with a JSON body, so you'll need to set the contentType option and manually convert to JSON.

Backbone.js #

+ +
var Todo = Backbone.Model.extend({});
+var Todos = Backbone.Collection.extend({
+  model: Todo,
+  url: "/todos"
+});
+
+var todos = new Todos();  
+
+todos.fetch({
+  success: function(collection, response) {
+    // Do something
+  }, error: function(collection, response) {
+    alert(response);
+  }
+});
+
+todos.create({
+  title: "Walk the dog"
+}, {
+  success: function(collection, response) {
+    // Do something
+  }, error: function(collection, response) {
+    alert(response);
+  }
+});
+

Angular.js #

+ +

Using $http:

+ +
function Controller($scope, $http) {
+  $http.get('/todos')
+    .success(function(todos) {
+      $scope.todos = todos;
+    })
+    .error(function(err) {
+      alert(err);
+    });
+
+  $http.post('/todos', {
+      title: "Walk the dog"
+    })
+    .success(function(todo) {
+      // Do something
+    })
+    .error(function(err) {
+      alert(err);
+    });
+}
+
+ +

Using ngResource:

+ +
var myApp = angular.module('myApp', ['ngResource']);
+
+myApp.factory('Todos', function($resource) {
+  return $resource('/todos/:todoId', {todoId: '@id'});
+});
+
+function Controller($scope, Todos) {
+  $scope.todos = Todos.query(function(response) {
+    // Do something
+  }, function(error) {
+    alert(error);
+  });
+
+  Todos.save({
+    title: "Walk the dog"
+  }, function(todo) {
+    // Do something
+  }, function(error) {
+    alert(error);
+  });
+}
+
+myApp.controller('Controller', Controller);
+

Cross-Origin Requests #

+ +

The most common bug when implementing a CORS client for Deploy is to include headers that are not allowed. A client must not send any custom headers besides the following:

+ +
Origin, Accept, Accept-Language, Content-Language, Content-Type, Last-Event-ID
+
+ +

This will not work on browsers that do not support Cross-Origin Resource Sharing (namely Internet Explorer 7 and below).

Cross-Origin Requests with dpd.js #

+ +

When using dpd.js, all the required CORS headers are sent by default to any domain. You don't have to make any changes to your requests. dpd.js takes care of it for you.

Cross-Origin Requests with jQuery #

+ +

When using jQuery.ajax() on cross-origin requests the credentials are not sent along with the request automatically. You have to add them to each ajax() request using the xhrFields parameter. Here is an example of login followed by getting some data.

+ +
// Logging a user in.
+$.ajax({
+  url: 'http://<domain>:<port>/users/login',
+  type: "POST",
+  data: {username:"un", password:"pw"},
+  cache: false,
+  xhrFields:{
+    withCredentials: true
+  },
+  success: function(data) {
+    console.log(data);
+  },
+  error: function(xhr) {
+    console.log(xhr.responseText);
+  }
+});
+
+// On subsequent requests or in the success callback above.  (After having logged in) 
+$.ajax({
+  url: 'http://<domain>:<port>/<collection>',
+  type: "GET",
+  cache: false,
+  xhrFields:{
+    withCredentials: true
+  },
+  success: function(data) {
+    console.log(data);
+  },
+  error: function(xhr) {
+    console.log(xhr.responseText);
+  }
+});
+

HTTP method override #

+ +

Provides faux HTTP method support.

+ +

Most browsers doesn’t support methods other than “GET” and “POST” when it comes to submitting forms. So It's support something like 'Rails'.

+ +

Pass an optional key to use when checking for a method override, othewise defaults to _method. The original method is available via req.originalMethod.

+ +

It's support both URL query and POST body

+ +
URL       : ?_method=METHOD_NAME or
+JSON body : { _method: 'METHOD_NAME' }
+
+ +

$.ajax({ + type: "POST", + url : "/todos/"+ todoId, + data: { _method:"DELETE" }, + success: function(res) {

Ajax Example #

+ +
$.ajax({
+  type : "POST",
+  url  : "/todos/OBJECT_ID"
+  data : { _method:"DELETE" },
+  success: function(todo) {
+    // Object was deleted. response body empty.
+  }, 
+  error: function(xhr) {}
+});
+
+or
+
+$.ajax({
+  type : "POST",
+  url  : "/todos/OBJECT_ID?_method=DELETE",
+  success: function(todo) {
+    // Object was deleted. response body empty.
+  }, 
+  error: function(xhr) {}
+});
+
+ + +

More

+ + + +
+
+
+

Other docs in "Reference"

+ +
+
+ + + +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/reference/querying-collections.md.html b/docs/collections/reference/querying-collections.md.html new file mode 100644 index 0000000..bf5ebff --- /dev/null +++ b/docs/collections/reference/querying-collections.md.html @@ -0,0 +1,583 @@ + + + + + + Querying Collections - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Querying Collections #

Simple Queries #

+ +

Collections can be queried over HTTP using the query string.

+ +

This example will return all the posts with an author "Joe":

+ +
GET /posts?author=Joe   
+

Advanced Queries #

+ +

When querying a Collection, you can use special commands to create a more advanced query.

+ +

Deployd supports all of MongoDB's conditional operators; only the common operators and Deployd's custom commands are documented here.

+ +

When using an advanced query in REST, you must pass JSON as the query string, for example:

+ +
GET /posts?{"likes": {"$gt": 10}}
+
+ +

If you are using dpd.js, this will be handled automatically.

Comparison ($gt, $lt, $gte, $lte) #

+ +

Compares a Number property to a given value.

+ +
    +
  • $gt - Greater than
  • +
  • $lt - Less than
  • +
  • $gte - Greater than or equal to
  • +
  • $lte - Less than or equal to

    + +
    // Finds all posts with more than 10 likes
    +{
    +    likes: {$gt: 10}
    +}
    +
  • +

$ne (Not Equal) #

+ +

The $ne command lets you choose a value to exclude.

+ +
// Get all posts except those posted by Bob
+{
+    author: {$ne: "Bob"}
+}
+

$in #

+ +

The $in command allows you to specify an array of possible matches.

+ +
// Get articles in the "food", "business", and "technology" categories
+{
+    category: {$in: ["food", "business", "technology"]}
+}
+

$regex #

+ +

The $regex command allows you to specify a regular expression to match a string property.

+ +

You can also use the $options command to specify regular expression flags.

+ +
// Get usernames that might be email addresses (x@y.z)
+{
+    "username": {$regex: "[a-z0-9\-]+@[a-z0-9\-]+\.[a-z0-9\-]+", $options: 'i' }
+}
+

Query commands #

+ +

Query commands apply to the entire query, not just a single property.

$fields #

+ +

The $fields command allows you to include or exclude properties from your results.

+ +
    // Exclude the "email" property
+    {
+        $fields: {email: 0}
+    }
+
+ + + +
    // Only include the "title" property
+    {
+        $fields: {title: 1}
+    }
+

$or #

+ +

The $or command allows you to specify multiple queries for an object to match in an array.

+ +
// Get all public posts and all posts by a specified user (even if those are private)
+{
+    $or: [{
+      isPublic: true
+    }, {
+      creator: "Bob"
+    }]
+}
+

$sort #

+ +

The $sort command allows you to order your results by the value of a property. The value can be 1 for ascending sort (lowest first; A-Z, 0-10) or -1 for descending (highest first; Z-A, 10-0)

+ +
// Sort posts by likes, descending
+{
+    $sort: {likes: -1}
+}
+

$limit #

+ +

The $limit command allows you to limit the amount of objects that are returned from a query. This is commonly used for paging, along with $skip.

+ +
// Return the top 10 scores
+{
+    $sort: {score: -1},
+    $limit: 10
+}
+

$skip #

+ +

The $skip command allows you to exclude a given number of the first objects returned from a query. This is commonly used for paging, along with $limit.

+ +
// Return the third page of posts, with 10 posts per page
+{
+    $skip: 20,
+    $limit: 10
+}
+

$limitRecursion #

+ +

The $limitRecursion command allows you to override the default recursive limits in Deployd. This is useful when you want to query a very deeply nested structure of data. Otherwise you can still query nested structures, but Deployd will stop the recursion after 2 levels. See the Collection Relationships guide for more info.

+ + +

More

+ + + +
+
+
+

Other docs in "Reference"

+ +
+
+ + + +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/reference/updating-objects.md.html b/docs/collections/reference/updating-objects.md.html new file mode 100644 index 0000000..5e21387 --- /dev/null +++ b/docs/collections/reference/updating-objects.md.html @@ -0,0 +1,514 @@ + + + + + + Updating Objects in Collections - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Updating Objects in Collections #

+ +

When updating an object in a Collection, you can use special modifier commands to more granularly change property values.

$inc #

+ +

The $inc command increments the value of a given Number property.

+ +
// Give a player 5 points
+{
+  score: {$inc: 5}
+}
+

$push #

+ +

The $push command adds a value to an Array property.

+ +
// Add a follower to a user by storing their id.
+{
+  followers: {$push: 'a59551a90be9abd8'}
+}
+

$pushAll #

+ +

The $pushAll command adds multiple values to an Array property.

+ +
// Add mentions of users
+{
+  mentions: {
+    $pushAll: ['a59551a90be9abd8', 'd0be45d1445d3809']
+  }
+}
+

$pull #

+ +

The $pull command removes a value from an Array property.

+ +
// Remove a user from followers
+{
+  followers: {$pull: 'a59551a90be9abd8'}
+}
+
+ +

Note: If there is more than one matching value in the Array, this will remove all of them

$pullAll #

+ +

The $pullAll command removes multiple values from an Array property.

+ +
// Remove multiple users
+{
+  followers: {$pullAll: ['a59551a90be9abd8', 'd0be45d1445d3809']}
+}
+
+ +

Note: This will remove all of the matching values from the Array

+ + +

More

+ + + +
+
+
+

Other docs in "Reference"

+ +
+
+ + + +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/collections/relationships-between-collections.md.html b/docs/collections/relationships-between-collections.md.html new file mode 100644 index 0000000..ae01df3 --- /dev/null +++ b/docs/collections/relationships-between-collections.md.html @@ -0,0 +1,609 @@ + + + + + + Relationships Between Collections with Events - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Relationships Between Collections with Events #

+ +

Designing the relationships between the collections in your application is crucial to a useful API. In typical databases, there are very specific ways to implement the relation of objects in one table (or collection) and another. Deployd lets you relate your data however your application requires and is flexible enough to allow you to easily change the way objects are related.

Types of Relationships #

+ +

When designing the collections in your application keep in mind the following strategies for relating data. There isn't a single best way to create relationships, so you will have to take into account how data will change in your collections.

Embedding Data #

+ +

Deployd allows your collection to store complex structures such as nested objects or arrays. This is useful if you want to embed data inside your collection's objects. Keep in mind this is only recommended when the embedded data is not likely to change. For example, a blog-posts collection could have an author property with a type set to Object.

+ +
{
+  "title": "Foo Bar Bat Baz?",
+  "author": {
+    "name": "Joe Bob",
+    "id": "5ef0f7d515764998"
+  }
+}
+
+ +

This style of relationship allows users of the collection to display the name of the author without running any other queries. The downside is an update event is required to keep the author name in sync if it ever changes. If your data changes often, this may not be the best approach.

Contains Many or One-to-Many #

+ +

Similarly to storing nested objects in your collection, you can also store arrays of arbitrary JSON. This is useful when you want to setup a contains relationship. For example, in a gradebook application, your classes collection objects could contain students.

+ +
{
+  "title": "Language Arts",
+  "students": ["5ef0f7d515764998", "5ef0f7d515764531", ...] 
+}
+
+ +

By storing an array of student ids you can easily query classes by student.

+ +
dpd.classes.get({students: '5ef0f7d515764998'}, function(classes) {
+  console.log(classes); // [...] - all the classes the student is in.
+});
+

Many-to-Many #

+ +

There are several ways to handle many-to-many relationships. The most common way is to include an Array property that stores the ids of the related objects on both collections.

+ +

Continuing with the gradebook example, a student may have many classes, and a class may have many students. The classes collection would have a students Array property containing the student ids and the students collection would have a classes Array property containing class ids.

+ +

This lets you query each collection to get the students in a class or the classes a student is taking by providing the id of the class or student.

+ +
dpd.students.get({id: {$in: class.students}}, function(students) {
+  console.log(students);
+}); 
+
+// or
+
+dpd.classes.get({id: {$in: student.classes}}, function(classes) {
+  console.log(classes);
+});
+
+ +

If you wanted to include the full objects when querying the API you could implement a simple GET event.

+ +
// on GET /students
+
+if(query.include === 'classes') {
+  dpd.classes.get({id: {$in: student.classes}}, function(classes) {
+    this.classes = classes;
+  });
+}
+
+ +

Then if you added the include param when querying from the browser, a student would come back with all of its classes.

+ +
dpd.students.get({id: '2ef0f7d515764991', include: 'classes'}, fn);
+
+ +

would output

+ +
{
+  "id": "2ef0f7d515764991",
+  "name": "Joe Bob",
+  "classes": [{
+    "id": "...",
+    "title": "Language Arts"
+  }, ...]
+}
+

Parent-Child #

+ +

Some collections contain objects related to other objects in the same collection. A simple example of this is threaded comments. Where a comment can be in reply to another comment, creating a tree-like structure when rendered.

+ +

To accomplish this, all you need is a parent property containing the id of a parent object if one exists. Since Deployd supports recursive queries in a collection's GET event, the following works as you would expect.

+ +
// on GET /comments
+var comment = this;
+
+dpd.comments.get({parent: comment.id}, function(comments) {
+  if(comments && comments.length) comment.children = comments;
+});
+
+ +

Running the following query from the browser would result in a nested structure of all possible comments:

+ +
// from the browser
+dpd.comments.get({id: '2ef0f7d515764991'}, console.log);
+
+ +

would output

+ +
{
+  "id": "2ef0f7d515764991"
+  "text": "Hello, World!",
+  "children": [
+    {
+      "id": "tef0f7d515761234",
+      "text": "Foo bar...",
+      "children": [
+        {
+          "id": "ff00f7d515764642",
+          "text": "I agree!"
+        },
+        {
+          "id": "2200f7d51576123",
+          "text": "I do not agree!"
+        },
+      ]
+    }
+  ]
+}
+
+ +

If you expect that a query could become an infinite loop (or if it already is an infinite loop; a good sign of this is requests that time out before returning a result), put a $limitRecursion property on your query with the maximum number of levels to iterate:

+ +
// on GET /comments
+var comment = this;
+
+dpd.comments.get({parent: comment.id, $limitRecursion: 10}, function(comments) {
+  if(comments && comments.length) comments.children = comments;
+});
+
+ + +

More

+ + + + +
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules-include=all.html b/docs/developing-modules-include=all.html new file mode 100644 index 0000000..6a8bff5 --- /dev/null +++ b/docs/developing-modules-include=all.html @@ -0,0 +1,1632 @@ + + + + + + Developing Modules - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Creating a Module #

Background #

+ +

Deployd modules are 100% compatible with regular node modules. This means you can use any of the 17,000+ node modules when building your Deployd app.

Hello World #

+ +

Any module in your app's node_modules folder will be loaded when the Deployd server starts.

+ +

You don't have to require() or load anything to instantiate your module. The following will log 'hello world' when you run dpd.

+ +
// /my-app/node_modules/hello.js
+console.log('hello world');
+

Accessing the Server #

+ +

In order to do anything interesting you need a reference to the current Deployd server object. The server is always available at process.server. This means you don't need to require anything to use most of the internal APIs.

One Off Modules #

+ +

The simplest kind of module is a one-off module. These are easy to create but hard to reuse. Typically any behavior that is specific to just your app that can't be implemented using an existing module can be built with a simple one-off module.

+ +

Here's an example one off module that maintains a count of requests to the url /hits and writes it to a file every minute.

+ +
// /my-app/node_modules/hits.js
+var fs = require('fs');
+process.server.hits = 0;
+
+process.server.on('request', function(req) {
+  if(req.url === '/hits') {
+    process.server.hits++;
+  }
+});
+
+// write a file every minute
+setInterval(function() {
+  fs.writeFile('hits.json', JSON.stringify({hits: process.server.hits}));
+}, 60000);
+

Reusable Modules #

+ +

Modules can also expose useful APIs of their own. The simplest way to create reusable modules is to define a Resource Type. Resource Types are exposed in the dashboard and are much easier to reuse, and you can share them with other Deployd developers. See the custom resource type guide for more info.

+ + + + +

Creating a Custom Resource Type #

+ +

Deployd modules can register new Resource Types, which can be created with a route and configured per instance. Deployd comes with two built-in Resource Types: "Collection" and "User Collection". You can create your own custom resource types by extending the Resource constructor and implementing a handle() method. Deployd will automatically load any Resource Types that are exported by a module.

+ +

Here is a simple custom resource type:

+ +
var Resource = require('deployd/lib/resource')
+    , util = require('util');
+
+function Hello(name, options) {
+    Resource.apply(this, arguments);
+}
+util.inherits(Hello, Resource);
+module.exports = Hello;
+
+Hello.prototype.clientGeneration = true;
+
+Hello.prototype.handle = function (ctx, next) {
+    if(ctx.req && ctx.req.method !== 'GET') return next();
+
+    ctx.done(null, {hello: 'world'});
+}
+
+ +

This will allow you to add a "Hello" resource in the Dashboard. This resource will respond to every GET request with {"hello": "world"}.

Example Resource Type #

+ +

The most basic Custom Resource Type that is useful is the Event Resource, which will simply execute an On GET event when it receives a GET request and an On POST event when it receives a POST request.

+ +

This is the source for that module:

+ +
var Resource = require('deployd/lib/resource')
+    , util = require('util');
+
+function EventResource() {
+    Resource.apply(this, arguments);
+}
+util.inherits(EventResource, Resource);
+
+EventResource.label = "Event";
+EventResource.events = ["get", "post"];
+
+module.exports = EventResource;
+
+EventResource.prototype.clientGeneration = true;
+
+EventResource.prototype.handle = function (ctx, next) {
+    var parts = ctx.url.split('/').filter(function(p) { return p; });
+
+    var result = {};
+
+    var domain = {
+            url: ctx.url
+        , parts: parts
+        , query: ctx.query
+        , body: ctx.body
+        , 'this': result
+        , setResult: function(val) {
+            result = val;
+        }
+    };
+
+    if (ctx.method === "POST" && this.events.post) {
+        this.events.post.run(ctx, domain, function(err) {
+            ctx.done(err, result);
+        });
+    } else if (ctx.method === "GET" && this.events.get) {
+        this.events.get.run(ctx, domain, function(err) {
+            ctx.done(err, domain.result);
+        });
+    } else {
+        next();
+    }
+};
+
+ +

Let's look at it line-by-line:

+ +
var Resource = require('deployd/lib/resource')
+    , util = require('util');
+
+ +

To create a Resource, you'll need the Resource module and Node's util module.

+ +
function EventResource() {
+    Resource.apply(this, arguments);
+}
+
+ +

Creates the constructor for the EventResource, also applying the base Resource constructor.

+ +
util.inherits(EventResource, Resource);
+
+ +

Causes EventResource to inherit its prototype from Resource using Node's util.inherits() function.

+ +
EventResource.label = "Event";
+
+ +

Changes the Resource.label property to set how the EventResource appears in the "Add Resource" menu in the Dashboard. Without this setting, it would appear using the constructor name, EventResource.

+ +
EventResource.events = ["get", "post"];
+
+ +

Configures two events for the Resource type: get and post. These will appear on the "Events" page in the Dashboard with no extra configuration.

+ +

Note: The Dashboard provides the "On" prefix, e.g. "On Get"

+ +
module.exports = EventResource;
+
+ +

Exports the EventResource constructor. This is how Deployd finds and loads the resource type.

+ +
EventResource.prototype.clientGeneration = true;
+
+ +

Sets the clientGeneration flag, which ensures that resources created with this resource type will be generated into dpd.js.

+ +
EventResource.prototype.handle = function (ctx, next) {
+
+ +

Defines a handle() function. This function will be called whenever a request is routed to this resource. The ctx object is a Context, which includes useful properties (body, query, etc.) and functions (particularly done()) to simplify working with HTTP.

+ +

The next function gives control back to the router.

+ +
var parts = ctx.url.split('/').filter(function(p) { return p; });
+
+var result = {};
+
+ +

Set up some local variables; parts is an array of the /-separated parts in the URL.

+ +
var domain = {
+        url: ctx.url
+    , parts: parts
+    , query: ctx.query
+    , body: ctx.body
+    , 'this': result
+    , setResult: function(val) {
+        result = val;
+    }
+};
+
+ +

Create a domain for the events. These are objects and functions that will be accessible from the event. Notice that the setResult function is a closure that assigns its argument to the local result variable.

+ +
if (ctx.method === "POST" && this.events.post) {
+    this.events.post.run(ctx, domain, function(err) {
+        ctx.done(err, result);
+    });
+}
+
+ +

Run the POST event using the Script.run() function if applicable, passing it the current context and domain.

+ +

The this.events object contains all of the available events; if the user has not written a POST event, though, this.events.post might be null.

+ +

The callback for Script.run returns an error err if something went wrong in the script (or if the script writer called cancel())

+ +

Finally, call ctx.done() with both the error and result (result is the local variable we set up earlier which the scriptwriter can change using setResult(). The response body is always the second parameter, but it is ignored if an error is passed.

+ +
} else if (ctx.method === "GET" && this.events.get) {
+    this.events.get.run(ctx, domain, function(err) {
+        ctx.done(err, domain.result);
+    });
+}
+
+ +

Do the same thing for the GET event.

+ +
} else {
+    next();
+}
+
+ +

If no event applies, call next(). This tells the router that this resource cannot handle the current request, and the router will allow other resources to handle it. If every resource calls next(), then Deployd will return a 404 status code.

+ + + + +

Email Resource Type #

+ +

This module demonstrates how to use a Node module such as Nodemailer to make a reusable resource type.

+ +

For information on how to use this module in your app, see the Email Resource documentation.

+ +

Download View Source

Useful files #

+ +

Event Resource Type #

+ +

This module demonstrates how to run user-defined Events in your resource. See the Creating Custom Resource Types page for an analysis of the source.

+ +

For information on how to use this module in your app, see the Event Resource documentation.

+ +

Download View Source

Useful files #

+ +

S3 Bucket Resource Type #

+ +

This module demonstrates how to receive file uploads in a custom resource type.

+ +

For information on how to use this module in your app, see the S3 Bucket Resource documentation.

+ +

Download View Source

Useful files #

+ +
+ + + + + + + + + +

Collection Resource Type #

+ +

Collections are the most common Resource Type in Deployd. They allow the user to store and load data from their app's Store. Behind the scenes, they validate incoming requests and execute event scripts for get, post, put, delete, and validate. If all event scripts execute without error (or cancel()ing), the request is proxied to the collection's Store.

Class: Collection #

+ +

A Collection inherits from Resource. Any constructor that inherits from Collection must include its own Collection.external prototype object.

+ +

Example inheriting from Collection:

+ +
var Collection = require('deployd/lib/resources/collection');
+var util = require('util');
+
+function MyCollection(name, options) {
+  Collection.apply(this, arguments);
+}
+MyCollection.external = Collection.external;
+
+util.inherits(MyCollection, Collection);
+

collection.store #

+ +
    +
  • {Store}
  • +
+ +

The backing persistence abstraction layer. Supports saving and reading data from a database. See Store for more info.

collection.validate(body, create) #

+ +

Validate the request body against the Collection's properties +and return an object containing any errors.

+ +
    +
  • body {Object}
  • +
+ +

The object to validate

+ +
    +
  • create {Boolean}
  • +
+ +

Should validate a new object being created

+ +
    +
  • return errors {Object}
  • +

collection.sanitize(body) #

+ +

Sanitize the request body against the Collection's properties +object and return an object containing only properties that exist in the +collection.config.properties object.

+ +
    +
  • body {Object}
  • +
  • return sanitized {Object}
  • +

collection.sanitizeQuery(query) #

+ +

Sanitize the request query against the collection.properties +and return an object containing only properties that exist in the +collection.properties object.

+ +
    +
  • query {Object}
  • +
  • return sanitizedQuery {Object}
  • +

collection.parseId(ctx) #

+ +

Parse the ctx.url for an id. Override this to change how an object's id is parsed out of a url.

+ +
    +
  • ctx {Context}
  • +

collection.find(ctx, fn) #

+ +

Find all the objects in a collection that match the given ctx.query. Then execute a get event script, if one exists, using each object found. Finally call fn(err) passing an error if one occurred.

+ +
    +
  • ctx {Context}
  • +
  • fn(err)
  • +

collection.remove(ctx, fn) #

+ +

Execute a delete event script, if one exists, using each object found. Then remove a single object that matches the ctx.query.id. Finally call fn(err) passing an error if one occurred.

+ +
    +
  • ctx {Context}
  • +
  • fn(err)
  • +

collection.save(ctx, fn) #

+ +

First execute a validate event script if one exists. If the event does not error, try to save the ctx.body into the store. If ctx.body.id exists, perform an update and execute the put event script. Otherwise perform an insert and execute the post event script. Finally call fn(err), passing an error if one occurred.

+ +
    +
  • ctx {Context}
  • +
  • fn(err)
  • +

Context #

+ +

Contexts are a thin abstraction between http requests, Resources, and Scripts. They provide utility methods to simplify interacting with node's http.ServerRequest and http.ServerResponse objects.

+ +

A Context is built from a request and response and passed to a matching Resource by the Router. This might originate from an external http request or a call to an internal client from a Script.

Mock Contexts #

+ +

Contexts may be created without a real request and response such as during an internal request using the dpd object. See Internal Client for more info.

Class: Context #

+ +
var Context = require('deployd/lib/context');
+var ctx = new Context(resource, req, res, server);
+

ctx.done(err, result) #

+ +

Continuous callback sugar for easily calling res.end(). Conforms to the idiomatic callback signature for most node APIs. It can be passed directly to most APIs that require a callback in node.

+ +
fs.readFile('bar.txt', ctx.done);
+
+ +
    +
  • err {Error | Object}
  • +
+ +

An error if one occurred during handling of the ctx. Otherwise it should be null.

+ +
    +
  • result {Object}
  • +
+ +

The result of executing the ctx. This should be an object that is serializable as JSON.

ctx.body #

+ +
    +
  • {Object}
  • +
+ +

The body of the request if sent as application/json or application/x-www-form-urlencoded.

ctx.query #

+ +
    +
  • {Object}
  • +
+ +

The query string of the request serialized as an Object. Supports both ?key=value as well as ?{"key":"value"}.

ctx.method #

+ +
    +
  • {Object}
  • +
+ +

An alias to the request's method.

Event Scripts #

+ +

A Script provides a mechanism to run JavaScript source in a sandbox. A Script is executed with a Context and a domain object using the node vm module. Each Script runs independently. They do not share global scope or state with other scripts or modules.

Async Mode #

+ +

Scripts can be run in an async mode. This mode is triggered when a Script is run(ctx, domain, fn) with a callback (fn). When run in this mode a Script will try scrub all functions in the domain for operations that require a callback. If a callback is required, the function is re-written to count the callbacks completion and notify the script. When all pending callbacks are complete the script is considered finished.

Async Errors #

+ +

If a script is run with a callback (in async mode), any error will emit an internal error event. This will stop the execution of the script and pass the error to the script's callback.

Class: Script #

+ +
var Script = require('deployd/lib/script');
+var script = new Script('hello()', 'hello.js');
+
+ +

A Script's source is compiled when its constructor is called. It can be run() many times with independent Contexts and domains.

script.run(ctx, domain, [fn]) #

+ +
    +
  • ctx {Context}
  • +
+ +

A Context with a session, query, req and res.

+ +
    +
  • domain {Object}
  • +
+ +

An Object containing functions to be injected into the Scripts sandbox. This will override any existing functions or objects in the Scripts sandbox / global scope.

+ +

This example domain provides a log function to a script.

+ +
var script = new Script('log("hello world")');
+var context = {};
+var domain = {};
+var msg;
+
+domain.log = function(str) {
+  console.log(msg = str);
+}
+
+script.run(ctx, domain, function(err) {
+  console.log(msg); // 'hello world'
+});
+
+ +
    +
  • fn(err) optional
  • +
+ +

If a callback is provided the script will be run in async mode. The callback will receive any error even if the error occurs asynchronously. Otherwise it will be called without any arguments when the script is finished executing (see: async mode).

+ +
var s = new Script('setTimeout(function() { throw "test err" }, 22)');
+
+// give the script access to setTimeout
+var domain = {setTimeout: setTimeout};
+
+s.run({}, domain, function (e) {
+  console.log(e); // test err
+});
+

Script.load(path, fn) #

+ +
    +
  • path {String}

  • +
  • fn(err, script)

  • +
+ +

Load a new script at the given file path. Runs the callback with an error if one occurred, or a new Script loaded from the contents of the file.

Default Domain #

+ +

Scripts are executed with a default sandbox and set of domain functions. These are functions that every Script usually needs, and are available to every Script. These can be overridden by passing a value such as {cancel: ...} in a domain. See Event API for Custom Resources for documentation on this default domain.

Internal Client #

+ +

The internal-client module is responsible for building a server-side version of dpd.js. It is intended for use in Scripts but can be used by resources to access other resources' REST APIs.

+ +

Note: As in dpd.js, the callback for an internal client request receives the arguments (data, err), which is different than the Node convention of (err, data).

internalClient.build(server, [session], [stack]) #

+ +
var internalClient = require('deployd/lib/internal-client');
+
+process.server.on('listening', function() {
+  var dpd = internalClient.build(process.server);
+  dpd.todos.get(function(data, err) {
+    // Do something
+  });  
+});
+
+ +
    +
  • server {Server}
  • +
+ +

The Deployd server to build a client for.

+ +
    +
  • session {Session} (optional)
  • +
+ +

The Session object on the current request.

+ +
    +
  • stack {Array} (optional)
  • +
+ +

Used internally to prevent recursive calls to resources.

Mock context #

+ +

In order to make requests on resources within the Deployd server, internal-client creates mock req and res objects. These objects are not Streams and cannot be treated exactly like the standard http.ServerRequest and http.ServerResponse objects in Node, but they imitate their interfaces with the following properties:

req #

+ +
    +
  • url {String}
  • +
+ +

The URL of the request, i.e. "/hello"

+ +
    +
  • method {String}
  • +
+ +

The method of the request, i.e. "GET", "POST"

+ +
    +
  • query {Object}
  • +
+ +

The query object.

+ +
    +
  • body {Object}
  • +
+ +

The body of the request.

+ +
    +
  • session {Session}
  • +
+ +

The current session, if any.

+ +
    +
  • internal {Boolean}
  • +
+ +

Always equal to true to indicate an internal request and a mock req object.

res #

+ +
    +
  • statusCode {Number}
  • +
+ +

Set this to a standard HTTP response code.

+ +
    +
  • setHeader() {Function}
  • +
+ +

No-op.

+ +
    +
  • end(data) {Function}
  • +
+ +

Returns data to the internal client call. If data is JSON, it will be parsed into an object, otherwise it will simply be passed as a string. If the res.statusCode is not 200 or 204, data will be passed as an error.

+ +
    +
  • internal {Boolean}
  • +
+ +

Always equal to true to indicate an internal request and a mock res object.

Resource Types #

+ +

Resources are the building block of a Deployd app. They provide a way to handle http requests at a root url. They must implement a handle(ctx, next) method that either handles a request or calls next() to give the request back to the router.

+ +

Resources can also be attributed with meta-data to allow the dashboard to dynamically render an editor gui for configuring a resource instance.

Events / Scripts #

+ +

A Resource can execute Scripts during the handling of an http request when certain events occur. This allows users of the resource to inject logic during specific events during an http request without having to extend the resource or create their own.

+ +

For example, the Collection resource executes the get.js event script when it retrieves each object from its store. If a get.js file exists in the instance folder of a resource (eg. /my-project/resources/my-collection/get.js), it will be pulled in by the resource and exposed as myResource.scripts.get.

Class: Resource #

+ +

A Resource inherits from EventEmitter. The following events are available.

+ +
    +
  • changed after a resource config has changed
  • +
  • deleted after a resource config has been deleted
  • +
+ +

Inheriting from Resource:

+ +
var Resource = require('deployd/lib/resource')
+  , util = require('util');
+
+function MyResource(name, options) {
+  // run the parent constructor
+  // before using any properties/methods
+  Resource.apply(this, arguments);
+}
+util.inherits(MyResource, Resource);
+module.exports = MyResource;
+
+ +
    +
  • name {String}
  • +
+ +

The name of the resource.

+ +
    +
  • options {Object}

    + +
    • configPath the project relative path to the resource instance
    • +
    • path the base path a resource should handle
    • +
    • db (optional) the database a resource will use for persistence
    • +
    • config the instance configuration object
    • +
    • server the server object
  • +
+ +

The following resource would respond with a file at the url /my-file.html.

+ +
function MyFileResource(name, options) {
+  Resource.apply(this, arguments);
+
+  this.on('changed', function(config) {
+    console.log('MyFileResource changed', config);
+  });
+}
+util.inherits(MyFileResource, Resource);
+
+MyFileResource.prototype.handle = function (ctx, next) {
+  if (ctx.url === '/my-file.html') {
+    fs.createReadStream('my-file.html').pipe(ctx.res);
+  } else {
+    next();
+  }
+}
+

Overriding Behavior #

+ +

Certain methods on a Resource prototype are called by the runtime. Their default behavior should be overridden to define an inherited Resources behavior.

resource.handle(ctx, next) #

+ +

Handle an incoming request. This gets called by the router.

+ +

The resource can either handle this context and call ctx.done(err, obj) with an error or result JSON object, or call next() to give the context back to the router. If a resource calls next() the router might find another match for the request, or respond with a 404.

+ + + +

The http context created by the Router. This provides an abstraction between the actual request and response. A Resource should call ctx.done or pipe to ctx.res if it can handle a request. Otherwise it should call next().

+ +

Override the handle method to return a string:

+ +
function MyResource(settings) {
+  Resource.apply(this, arguments);
+}
+util.inherits(MyResource, Resource);
+
+MyResource.prototype.handle = function (ctx, next) {
+  // respond with the file contents (or an error if one occurs)
+  fs.readFile('myfile.txt', ctx.done);
+}
+

resource.load(fn) #

+ +

Load any dependencies and call fn(err) with any errors that occur. This is automatically called by the runtime to support asynchronous construction of a resource (such as loading files).

+ +

Note: If this method is overridden, the super method must be called to support loading of the MyResource.events array.

resource.clientGeneration #

+ +

If true, ensures that this resource is included in dpd.js.

+ +
MyResource.prototype.clientGeneration = true;
+

resource.config #

+ +

The instance configuration object; used to access the resource's configuration from member functions.

+ +
MyResource.prototype.handle = function (ctx, next) {
+  fs.readFile(this.config.filePath, ctx.done);
+}
+

External Prototype #

+ +

This is a special type of prototype object that is used to build the dpd object. Each function on the Resource.external prototype Object are exposed externally in two places

+ +
    +
  1. To the generated dpd.js browser JavaScript client
  2. +
  3. To the Context.dpd object generated for inter-resource calls
  4. +
+ +

Here is an example of a simple resource that exposes a method on the external prototype.

+ +

/my-project/node_modules/example.js

+ +
var util = require('util');
+var Resource = require('deployd/lib/resource');
+function Example(name, options) {
+  Resource.apply(this, arguments);
+}
+util.inherits(Example, Resource);
+
+Example.external = {};
+
+Example.external.hello = function(options, ctx, fn) {
+  console.log(options.msg); // 'hello world'
+}
+
+ +

When the hello() method is called, a context does not need to be provided as the dpd object is built with a context. A callback may be provided which will be executed with results of fn(err, result).

+ +

/my-project/public/hello.js

+ +
dpd.example.hello({msg: 'hello world'});
+
+ +

/my-project/resources/other-resource/get.js

+ +
dpd.example.hello({msg: 'hello world'});
+

Resource.events #

+ +
    +
  • {Array}
  • +
+ +

If a Resource constructor includes an array of events, it will try to load the scripts in its instance folder (eg. /my-project/resources/my-resource/get.js) using resource.loadScripts(eventNames, fn).

+ +
MyResource.events = ['get'];
+
+ +

This will be available to each instance of this resource as this.events.

+ +

/my-project/node_modules/my-resource.js

+ +
MyResource.prototype.handle = function(ctx, next) {
+  if(this.events && this.events.get) {
+    var domain = {
+      say: function(msg) {
+        console.log(msg); // 'hello world'
+      }
+    }
+    this.events.get.run(ctx, domain, ctx.done);
+  }
+}
+
+ +

/my-project/resources/my-resource/get.js

+ +
say('hello world');
+

Resource.label #

+ +

The resource type's name as it appears in the dashboard. If this is not set, it will appear with its constructor name.

+ +
Hello.label = 'Hello World';
+

Resource.defaultPath #

+ +

The default path suggested to users creating a resource. If this is not set, it will use the constructor's name in lowercase.

+ +
Hello.defaultPath = '/hello-world'; 
+

Collection.basicDashboard #

+ +

Set this property to an object to create a custom configuration page for your resource type.

+ +
    +
  • settings - An array of objects describing which properties to display.
  • +
  • name - The name of the property. This is how the value will be passed into the config object, so make sure it's something JavaScript-friendly, e.g. maxItems.
  • +
  • type - The type of control to edit this property. Allowed types are text, textarea, number, and checkbox.
  • +
  • description (Optional) - Explanatory text to appear below the field.
  • +
+ + + +
Hello.basicDashboard = {
+  settings: [{
+      name: 'propertyName',
+      type: 'text',
+      description: "This description appears below the text field"
+  }, {
+      name: 'longTextProperty',
+      type: 'textarea'
+  }, {
+      name: 'numericProperty',
+      type: 'number'
+  }, {
+      name: 'booleanProperty',
+      type: 'checkbox'
+  }]
+};
+
+ +

The above sample will produce the following dashboard page:

+ +

Example basic dashboard

Collection.dashboard #

+ +

A resource can describe the dependencies of a fully custom dashboard editor UI. This will be passed to the dashboard during rendering to create a custom UI.

+ +

This example creates the custom dashboard for the Collection resource. It automatically includes pages and page-specific scripts:

+ +
Collection.dashboard = {
+    path: path.join(__dirname, 'dashboard')
+  , pages: ['Properties', 'Data', 'Events', 'API']
+  , scripts: [
+      '/js/ui.js'
+    , '/js/util.js'
+  ]
+}
+
+ +
    +
  • path {String}
  • +
+ +

The absolute path to this resource's dashboard

+ +
    +
  • pages {Array} (optional)
  • +
+ +

An array of pages to appear in the sidebar. If this is not provided, the only page available will be "Config" (and "Events", if MyResource.events is set).

+ +

The dashboard will load content from [current-page].html and js/[current-page].js.

+ +

Note: The "Config" page will load from index.html and js/index.js.

+ +
    +
  • scripts {Array} (optional)
  • +
+ +

An array of extra JavaScript files to load with the dashboard pages.

Dashboard asset loading #

+ +

When you request a page from a custom dashboard, it will load the following files, if they are available, from the dashboard.path:

+ +
    +
  • [current-page].html
  • +
  • js/[current-page].js
  • +
  • style.css
  • +
+ +

The default page is index; the config page will also redirect to index.

+ +

The config or index page will load the basic dashboard if no index.html file is provided. +The events page will load the default event editor if no events.html file is provided.

+ +

It will also load the JavaScript files in the dashboard.scripts property.

Creating a custom dashboard #

Event editor control #
+ +

To embed the event editor in your dashboard, include this empty div:

+ +
<div id="event-editor" class="default-editor"></div>
+
Styling #
+ +

For styling, the dashboard uses a re-skinned version of Twitter Bootstrap 2.0.2.

JavaScript #
+ +

The dashboard provides several JavaScript libraries by default:

+ + + +

Within the dashboard, a Context object is available:

+ +
//Automatically generated by Deployd:
+window.Context = {
+  resourceId: '/hello', // The id of the current resource
+  resourceType: 'Hello', // The type of the current resource
+  page: 'properties', // The current page, in multi-page dashboards
+  basicDashboard: {} // The configuration of the basic dashboard
+};
+
+ +

You can use this to query the current resource:

+ +
dpd(Context.resourceId).get(function(result, err) {
+  //Do something
+});
+
+ +

In the dashboard, you also have access to the special __resources resource, which lets you update your app's configuration files:

+ +
// Get the config for the current resource
+dpd('__resources').get(Context.resourceId, function(result, err) {
+  //Do something
+});
+
+// Set a property for the current resource
+dpd('__resources').put(Context.resourceId, {someProperty: true}, function(result, err) {
+  //Do something
+});
+
+// Set all properties for the current resource, deleting any that are not provided
+dpd('__resources').put(Context.resourceId, {someProperty: true, $setAll: true}, function(result, err) {
+  //Do something
+});
+
+// Save another file, which will be loaded by the resource
+dpd('__resources').post(Context.resourceId + '/content.md', {value: "# Hello World!"}, function(result, err)) {
+  //Do something
+});
+

Server #

+ +

Deployd's Server extends node's http.Server. A Server is created with an options object that tells Deployd what port to serve on and which database to connect to.

+ +

The Server object is also the main entry point for modules. After it is started, the Server instance is available at process.server.

Class: Server #

+ +

Servers are created when calling the Deployd exported function.

+ +
var deployd = require('deployd')
+  , options = {port: 3000}
+  , server = deployd(options);
+
+ +
    +
  • options {Object}

    + +
    • port {Number} - the port to listen on
    • +
    • db {Object} - the database to connect to
    • +
    • port {Number} - the port of the database server
    • +
    • host {String} - the ip or domain of the database server
    • +
    • name {String} - the name of the database
    • +
    • credentials {Object} - credentials for the server +
      • username {String}
      • +
      • password {String}
    • +
    • env {String} - the environment to run in.
  • +
+ +

Note: If options.env is "development", the dashboard will not require authentication and configuration will not be cached. Make sure to change this to "production" or something similar when deploying.

Server.listen([port], [host]) #

+ +

Load any configuration and start listening for incoming connections.

+ +
var dpd = require('deployd')
+  , server = dpd()
+
+dpd.listen();
+dpd.on('listening', function() {
+  console.log(server.options.port); // 2403
+});
+

Server.createStore(namespace) #

+ +

Create a new Store for persisting data using the database info that was passed to the server when it was created.

+ +
// Create a new server
+var server = new Server({port: 3000, db: {host: 'localhost', port: 27015, name: 'my-db'}});
+
+// Attach a store to the server
+var todos = server.createStore('todos');
+
+// Use the store to CRUD data
+todos.insert({name: 'go to the store', done: true}, ...); // see `Store` for more info
+

Server.sockets #

+ +

The socket.io sockets Manager object (view source).

Server.sessions #

+ +

The server's SessionStore.

Server.router #

+ +

The server's Router.

Server.resources #

+ +

An Array of the server's Resource instances. These are built from the config and type loaders.

Session #

+ +

An in-memory representation of a client or user connection that can be saved to disk. Data will be passed around via a Context to resources.

Class: Session #

+ +

A store for persisting sessions in-between connection and disconnection. Automatically creates session IDs on inserted objects.

+ +
var session = new Session({id: 'my-sid', new SessionStore('sessions', db)});
+session.set({uid: 'my-uid'}).save();
+
+ +
    +
  • data {Object}
  • +
+ +

The data used to construct the session.

+ +
    +
  • store {SessionStore}
  • +
+ +

The store used to persist the session.

+ +
    +
  • sockets {Socket.IO.sockets}
  • +
+ +

The Socket.IO sockets object used to attach an existing socket.

Session.set(changes) #

+ +
    +
  • changes {Object}
  • +
+ +

An object containing changes to the session's data.

Session.save(fn) #

+ +
    +
  • fn(err, data) {Function} optional
  • +
+ +

Save the in memory representation of a session to its store.

Session.fetch(fn) #

+ +
    +
  • fn(err, data) {Function} optional
  • +
+ +

Reset the session using the data persisted in its store.

Session.remove(fn) #

+ +
    +
  • fn(err, data) {Function} optional
  • +
+ +

Remove the session.

Session.emitToAll(event, data) #

+ +
    +
  • event {String}
  • +
+ +

The event to emit to all session's sockets.

+ +
    +
  • data {Object} optional
  • +
+ +

The data to send to sockets listening to the given event.

Session.emitToUsers(collection, query, event, data) #

+ +
    +
  • collection {Collection}
  • +
+ +

The user-collection instance (eg. dpd.todos) to use to find users.

+ +
    +
  • query {Object}
  • +
+ +

Only emit the event to users that match this query.

+ +
    +
  • event {String}
  • +
+ +

The event to emit to all session's sockets.

+ +
    +
  • data {Object} optional
  • +
+ +

The data to send to sockets listening to the given event.

Session Store #

+ +

Sessions are persisted in a modified store. This store has several methods to help create and manage sessions.

Class: SessionStore #

+ +

A store for persisting sessions in-between connection and disconnection. Automatically creates session IDs on inserted objects.

+ +
var db = process.server.db;
+var sockets = process.server.sockets;
+var name = 'sessions';
+var store = new SessionStore(name, db, sockets);
+
+ +
    +
  • name {String}
  • +
+ +

The name of the db store.

+ +
    +
  • db {Db}
  • +
+ +

The server db instance

+ +
    +
  • sockets {Socket.IO.sockets}
  • +
+ +

The socket.io sockets object.

SessionStore.createSession(sid, fn) #

+ +
    +
  • sid {String} optional
  • +
+ +

An existing session id.

+ +
    +
  • fn(err, session) {Function}
  • +
+ +

Called once the session has been created.

Store #

+ +

An abstraction of a collection of objects in a database. Collections are HTTP wrappers around a Store. You can access or create a store the same way.

+ +
var myStore = process.server.createStore('my-store');
+

Class: Store #

+ +

You shouldn't construct Stores directly. Instead use the process.server.createStore() method.

Store.insert(object, fn) #

+ +
    +
  • object {Object}
  • +
+ +

The data to insert into the store.

+ +
    +
  • fn(err, result) {Function}
  • +
+ +

Called once the insert operation is finished.

Store.count(query, fn) #

+ +
    +
  • query {Object}
  • +
+ +

Only count objects that match this query.

+ +
    +
  • fn(err, count) {Function}
  • +
+ +

Called once the count operation is finished. count is a number.

Store.find(query, fn) #

+ +
    +
  • query {Object}
  • +
+ +

Only returns objects that match this query.

+ +
    +
  • fn(err, results) {Function}
  • +
+ +

Called once the find operation is finished.

Store.first(query, fn) #

+ +
    +
  • query {Object}

  • +
  • fn(err, result) {Function}

  • +
+ +

Find the first object in the store that match the given query.

Store.update(query, changes, fn) #

+ +
    +
  • query {Object}

  • +
  • changes {Object}

  • +
  • fn(err, updated) {Function}

  • +
+ +

Update an object or objects in the store that match the given query only modifying the values in the given changes object.

Store.remove(query, fn) #

+ +
    +
  • query {Object}

  • +
  • fn(err, updated) {Function}

  • +
+ +

Remove an object or objects in the store that match the given query.

Store.rename(name, fn) #

+ +
    +
  • name {String}

  • +
  • fn(err) {Function}

  • +
+ +

Rename the store.

+ + + +

More

+ + + +
+
+
+

Other docs in "Docs"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/creating-modules.md.html b/docs/developing-modules/creating-modules.md.html new file mode 100644 index 0000000..19fcd6f --- /dev/null +++ b/docs/developing-modules/creating-modules.md.html @@ -0,0 +1,522 @@ + + + + + + Creating a Module - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Creating a Module #

Background #

+ +

Deployd modules are 100% compatible with regular node modules. This means you can use any of the 17,000+ node modules when building your Deployd app.

Hello World #

+ +

Any module in your app's node_modules folder will be loaded when the Deployd server starts.

+ +

You don't have to require() or load anything to instantiate your module. The following will log 'hello world' when you run dpd.

+ +
// /my-app/node_modules/hello.js
+console.log('hello world');
+

Accessing the Server #

+ +

In order to do anything interesting you need a reference to the current Deployd server object. The server is always available at process.server. This means you don't need to require anything to use most of the internal APIs.

One Off Modules #

+ +

The simplest kind of module is a one-off module. These are easy to create but hard to reuse. Typically any behavior that is specific to just your app that can't be implemented using an existing module can be built with a simple one-off module.

+ +

Here's an example one off module that maintains a count of requests to the url /hits and writes it to a file every minute.

+ +
// /my-app/node_modules/hits.js
+var fs = require('fs');
+process.server.hits = 0;
+
+process.server.on('request', function(req) {
+  if(req.url === '/hits') {
+    process.server.hits++;
+  }
+});
+
+// write a file every minute
+setInterval(function() {
+  fs.writeFile('hits.json', JSON.stringify({hits: process.server.hits}));
+}, 60000);
+

Reusable Modules #

+ +

Modules can also expose useful APIs of their own. The simplest way to create reusable modules is to define a Resource Type. Resource Types are exposed in the dashboard and are much easier to reuse, and you can share them with other Deployd developers. See the custom resource type guide for more info.

+ + +

More

+ + + +
+
+
+

Other docs in "Developing Modules"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/custom-resource-types.md.html b/docs/developing-modules/custom-resource-types.md.html new file mode 100644 index 0000000..4ba983c --- /dev/null +++ b/docs/developing-modules/custom-resource-types.md.html @@ -0,0 +1,662 @@ + + + + + + Creating a Custom Resource Type - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Creating a Custom Resource Type #

+ +

Deployd modules can register new Resource Types, which can be created with a route and configured per instance. Deployd comes with two built-in Resource Types: "Collection" and "User Collection". You can create your own custom resource types by extending the Resource constructor and implementing a handle() method. Deployd will automatically load any Resource Types that are exported by a module.

+ +

Here is a simple custom resource type:

+ +
var Resource = require('deployd/lib/resource')
+    , util = require('util');
+
+function Hello(name, options) {
+    Resource.apply(this, arguments);
+}
+util.inherits(Hello, Resource);
+module.exports = Hello;
+
+Hello.prototype.clientGeneration = true;
+
+Hello.prototype.handle = function (ctx, next) {
+    if(ctx.req && ctx.req.method !== 'GET') return next();
+
+    ctx.done(null, {hello: 'world'});
+}
+
+ +

This will allow you to add a "Hello" resource in the Dashboard. This resource will respond to every GET request with {"hello": "world"}.

Example Resource Type #

+ +

The most basic Custom Resource Type that is useful is the Event Resource, which will simply execute an On GET event when it receives a GET request and an On POST event when it receives a POST request.

+ +

This is the source for that module:

+ +
var Resource = require('deployd/lib/resource')
+    , util = require('util');
+
+function EventResource() {
+    Resource.apply(this, arguments);
+}
+util.inherits(EventResource, Resource);
+
+EventResource.label = "Event";
+EventResource.events = ["get", "post"];
+
+module.exports = EventResource;
+
+EventResource.prototype.clientGeneration = true;
+
+EventResource.prototype.handle = function (ctx, next) {
+    var parts = ctx.url.split('/').filter(function(p) { return p; });
+
+    var result = {};
+
+    var domain = {
+            url: ctx.url
+        , parts: parts
+        , query: ctx.query
+        , body: ctx.body
+        , 'this': result
+        , setResult: function(val) {
+            result = val;
+        }
+    };
+
+    if (ctx.method === "POST" && this.events.post) {
+        this.events.post.run(ctx, domain, function(err) {
+            ctx.done(err, result);
+        });
+    } else if (ctx.method === "GET" && this.events.get) {
+        this.events.get.run(ctx, domain, function(err) {
+            ctx.done(err, domain.result);
+        });
+    } else {
+        next();
+    }
+};
+
+ +

Let's look at it line-by-line:

+ +
var Resource = require('deployd/lib/resource')
+    , util = require('util');
+
+ +

To create a Resource, you'll need the Resource module and Node's util module.

+ +
function EventResource() {
+    Resource.apply(this, arguments);
+}
+
+ +

Creates the constructor for the EventResource, also applying the base Resource constructor.

+ +
util.inherits(EventResource, Resource);
+
+ +

Causes EventResource to inherit its prototype from Resource using Node's util.inherits() function.

+ +
EventResource.label = "Event";
+
+ +

Changes the Resource.label property to set how the EventResource appears in the "Add Resource" menu in the Dashboard. Without this setting, it would appear using the constructor name, EventResource.

+ +
EventResource.events = ["get", "post"];
+
+ +

Configures two events for the Resource type: get and post. These will appear on the "Events" page in the Dashboard with no extra configuration.

+ +

Note: The Dashboard provides the "On" prefix, e.g. "On Get"

+ +
module.exports = EventResource;
+
+ +

Exports the EventResource constructor. This is how Deployd finds and loads the resource type.

+ +
EventResource.prototype.clientGeneration = true;
+
+ +

Sets the clientGeneration flag, which ensures that resources created with this resource type will be generated into dpd.js.

+ +
EventResource.prototype.handle = function (ctx, next) {
+
+ +

Defines a handle() function. This function will be called whenever a request is routed to this resource. The ctx object is a Context, which includes useful properties (body, query, etc.) and functions (particularly done()) to simplify working with HTTP.

+ +

The next function gives control back to the router.

+ +
var parts = ctx.url.split('/').filter(function(p) { return p; });
+
+var result = {};
+
+ +

Set up some local variables; parts is an array of the /-separated parts in the URL.

+ +
var domain = {
+        url: ctx.url
+    , parts: parts
+    , query: ctx.query
+    , body: ctx.body
+    , 'this': result
+    , setResult: function(val) {
+        result = val;
+    }
+};
+
+ +

Create a domain for the events. These are objects and functions that will be accessible from the event. Notice that the setResult function is a closure that assigns its argument to the local result variable.

+ +
if (ctx.method === "POST" && this.events.post) {
+    this.events.post.run(ctx, domain, function(err) {
+        ctx.done(err, result);
+    });
+}
+
+ +

Run the POST event using the Script.run() function if applicable, passing it the current context and domain.

+ +

The this.events object contains all of the available events; if the user has not written a POST event, though, this.events.post might be null.

+ +

The callback for Script.run returns an error err if something went wrong in the script (or if the script writer called cancel())

+ +

Finally, call ctx.done() with both the error and result (result is the local variable we set up earlier which the scriptwriter can change using setResult(). The response body is always the second parameter, but it is ignored if an error is passed.

+ +
} else if (ctx.method === "GET" && this.events.get) {
+    this.events.get.run(ctx, domain, function(err) {
+        ctx.done(err, domain.result);
+    });
+}
+
+ +

Do the same thing for the GET event.

+ +
} else {
+    next();
+}
+
+ +

If no event applies, call next(). This tells the router that this resource cannot handle the current request, and the router will allow other resources to handle it. If every resource calls next(), then Deployd will return a 404 status code.

+ + +

More

+ + + +
+
+
+

Other docs in "Developing Modules"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/examples-include=all.html b/docs/developing-modules/examples-include=all.html new file mode 100644 index 0000000..58b501e --- /dev/null +++ b/docs/developing-modules/examples-include=all.html @@ -0,0 +1,525 @@ + + + + + + Examples - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Email Resource Type #

+ +

This module demonstrates how to use a Node module such as Nodemailer to make a reusable resource type.

+ +

For information on how to use this module in your app, see the Email Resource documentation.

+ +

Download View Source

Useful files #

+ +
+ + + + +

Event Resource Type #

+ +

This module demonstrates how to run user-defined Events in your resource. See the Creating Custom Resource Types page for an analysis of the source.

+ +

For information on how to use this module in your app, see the Event Resource documentation.

+ +

Download View Source

Useful files #

+ +
+ + + + +

S3 Bucket Resource Type #

+ +

This module demonstrates how to receive file uploads in a custom resource type.

+ +

For information on how to use this module in your app, see the S3 Bucket Resource documentation.

+ +

Download View Source

Useful files #

+ +
+ + + +

More

+ + + +
+
+
+

Other docs in "Developing Modules"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/examples/email.md.html b/docs/developing-modules/examples/email.md.html new file mode 100644 index 0000000..936f058 --- /dev/null +++ b/docs/developing-modules/examples/email.md.html @@ -0,0 +1,490 @@ + + + + + + Email Resource - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Email Resource Type #

+ +

This module demonstrates how to use a Node module such as Nodemailer to make a reusable resource type.

+ +

For information on how to use this module in your app, see the Email Resource documentation.

+ +

Download View Source

Useful files #

+ +
+ + +

More

+ + + +
+
+
+

Other docs in "Examples"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/examples/event.md.html b/docs/developing-modules/examples/event.md.html new file mode 100644 index 0000000..0bee0b9 --- /dev/null +++ b/docs/developing-modules/examples/event.md.html @@ -0,0 +1,490 @@ + + + + + + Event Resource - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Event Resource Type #

+ +

This module demonstrates how to run user-defined Events in your resource. See the Creating Custom Resource Types page for an analysis of the source.

+ +

For information on how to use this module in your app, see the Event Resource documentation.

+ +

Download View Source

Useful files #

+ +
+ + +

More

+ + + +
+
+
+

Other docs in "Examples"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/examples/s3.md.html b/docs/developing-modules/examples/s3.md.html new file mode 100644 index 0000000..338a865 --- /dev/null +++ b/docs/developing-modules/examples/s3.md.html @@ -0,0 +1,490 @@ + + + + + + S3 Bucket Resource - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

S3 Bucket Resource Type #

+ +

This module demonstrates how to receive file uploads in a custom resource type.

+ +

For information on how to use this module in your app, see the S3 Bucket Resource documentation.

+ +

Download View Source

Useful files #

+ +
+ + +

More

+ + + +
+
+
+

Other docs in "Examples"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/internal-api-include=all.html b/docs/developing-modules/internal-api-include=all.html new file mode 100644 index 0000000..2edad89 --- /dev/null +++ b/docs/developing-modules/internal-api-include=all.html @@ -0,0 +1,1416 @@ + + + + + + Internal API Reference - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Collection Resource Type #

+ +

Collections are the most common Resource Type in Deployd. They allow the user to store and load data from their app's Store. Behind the scenes, they validate incoming requests and execute event scripts for get, post, put, delete, and validate. If all event scripts execute without error (or cancel()ing), the request is proxied to the collection's Store.

Class: Collection #

+ +

A Collection inherits from Resource. Any constructor that inherits from Collection must include its own Collection.external prototype object.

+ +

Example inheriting from Collection:

+ +
var Collection = require('deployd/lib/resources/collection');
+var util = require('util');
+
+function MyCollection(name, options) {
+  Collection.apply(this, arguments);
+}
+MyCollection.external = Collection.external;
+
+util.inherits(MyCollection, Collection);
+

collection.store #

+ +
    +
  • {Store}
  • +
+ +

The backing persistence abstraction layer. Supports saving and reading data from a database. See Store for more info.

collection.validate(body, create) #

+ +

Validate the request body against the Collection's properties +and return an object containing any errors.

+ +
    +
  • body {Object}
  • +
+ +

The object to validate

+ +
    +
  • create {Boolean}
  • +
+ +

Should validate a new object being created

+ +
    +
  • return errors {Object}
  • +

collection.sanitize(body) #

+ +

Sanitize the request body against the Collection's properties +object and return an object containing only properties that exist in the +collection.config.properties object.

+ +
    +
  • body {Object}
  • +
  • return sanitized {Object}
  • +

collection.sanitizeQuery(query) #

+ +

Sanitize the request query against the collection.properties +and return an object containing only properties that exist in the +collection.properties object.

+ +
    +
  • query {Object}
  • +
  • return sanitizedQuery {Object}
  • +

collection.parseId(ctx) #

+ +

Parse the ctx.url for an id. Override this to change how an object's id is parsed out of a url.

+ +
    +
  • ctx {Context}
  • +

collection.find(ctx, fn) #

+ +

Find all the objects in a collection that match the given ctx.query. Then execute a get event script, if one exists, using each object found. Finally call fn(err) passing an error if one occurred.

+ +
    +
  • ctx {Context}
  • +
  • fn(err)
  • +

collection.remove(ctx, fn) #

+ +

Execute a delete event script, if one exists, using each object found. Then remove a single object that matches the ctx.query.id. Finally call fn(err) passing an error if one occurred.

+ +
    +
  • ctx {Context}
  • +
  • fn(err)
  • +

collection.save(ctx, fn) #

+ +

First execute a validate event script if one exists. If the event does not error, try to save the ctx.body into the store. If ctx.body.id exists, perform an update and execute the put event script. Otherwise perform an insert and execute the post event script. Finally call fn(err), passing an error if one occurred.

+ +
    +
  • ctx {Context}
  • +
  • fn(err)
  • +
+ + + + +

Context #

+ +

Contexts are a thin abstraction between http requests, Resources, and Scripts. They provide utility methods to simplify interacting with node's http.ServerRequest and http.ServerResponse objects.

+ +

A Context is built from a request and response and passed to a matching Resource by the Router. This might originate from an external http request or a call to an internal client from a Script.

Mock Contexts #

+ +

Contexts may be created without a real request and response such as during an internal request using the dpd object. See Internal Client for more info.

Class: Context #

+ +
var Context = require('deployd/lib/context');
+var ctx = new Context(resource, req, res, server);
+

ctx.done(err, result) #

+ +

Continuous callback sugar for easily calling res.end(). Conforms to the idiomatic callback signature for most node APIs. It can be passed directly to most APIs that require a callback in node.

+ +
fs.readFile('bar.txt', ctx.done);
+
+ +
    +
  • err {Error | Object}
  • +
+ +

An error if one occurred during handling of the ctx. Otherwise it should be null.

+ +
    +
  • result {Object}
  • +
+ +

The result of executing the ctx. This should be an object that is serializable as JSON.

ctx.body #

+ +
    +
  • {Object}
  • +
+ +

The body of the request if sent as application/json or application/x-www-form-urlencoded.

ctx.query #

+ +
    +
  • {Object}
  • +
+ +

The query string of the request serialized as an Object. Supports both ?key=value as well as ?{"key":"value"}.

ctx.method #

+ +
    +
  • {Object}
  • +
+ +

An alias to the request's method.

+ + + + +

Event Scripts #

+ +

A Script provides a mechanism to run JavaScript source in a sandbox. A Script is executed with a Context and a domain object using the node vm module. Each Script runs independently. They do not share global scope or state with other scripts or modules.

Async Mode #

+ +

Scripts can be run in an async mode. This mode is triggered when a Script is run(ctx, domain, fn) with a callback (fn). When run in this mode a Script will try scrub all functions in the domain for operations that require a callback. If a callback is required, the function is re-written to count the callbacks completion and notify the script. When all pending callbacks are complete the script is considered finished.

Async Errors #

+ +

If a script is run with a callback (in async mode), any error will emit an internal error event. This will stop the execution of the script and pass the error to the script's callback.

Class: Script #

+ +
var Script = require('deployd/lib/script');
+var script = new Script('hello()', 'hello.js');
+
+ +

A Script's source is compiled when its constructor is called. It can be run() many times with independent Contexts and domains.

script.run(ctx, domain, [fn]) #

+ +
    +
  • ctx {Context}
  • +
+ +

A Context with a session, query, req and res.

+ +
    +
  • domain {Object}
  • +
+ +

An Object containing functions to be injected into the Scripts sandbox. This will override any existing functions or objects in the Scripts sandbox / global scope.

+ +

This example domain provides a log function to a script.

+ +
var script = new Script('log("hello world")');
+var context = {};
+var domain = {};
+var msg;
+
+domain.log = function(str) {
+  console.log(msg = str);
+}
+
+script.run(ctx, domain, function(err) {
+  console.log(msg); // 'hello world'
+});
+
+ +
    +
  • fn(err) optional
  • +
+ +

If a callback is provided the script will be run in async mode. The callback will receive any error even if the error occurs asynchronously. Otherwise it will be called without any arguments when the script is finished executing (see: async mode).

+ +
var s = new Script('setTimeout(function() { throw "test err" }, 22)');
+
+// give the script access to setTimeout
+var domain = {setTimeout: setTimeout};
+
+s.run({}, domain, function (e) {
+  console.log(e); // test err
+});
+

Script.load(path, fn) #

+ +
    +
  • path {String}

  • +
  • fn(err, script)

  • +
+ +

Load a new script at the given file path. Runs the callback with an error if one occurred, or a new Script loaded from the contents of the file.

Default Domain #

+ +

Scripts are executed with a default sandbox and set of domain functions. These are functions that every Script usually needs, and are available to every Script. These can be overridden by passing a value such as {cancel: ...} in a domain. See Event API for Custom Resources for documentation on this default domain.

+ + + + +

Internal Client #

+ +

The internal-client module is responsible for building a server-side version of dpd.js. It is intended for use in Scripts but can be used by resources to access other resources' REST APIs.

+ +

Note: As in dpd.js, the callback for an internal client request receives the arguments (data, err), which is different than the Node convention of (err, data).

internalClient.build(server, [session], [stack]) #

+ +
var internalClient = require('deployd/lib/internal-client');
+
+process.server.on('listening', function() {
+  var dpd = internalClient.build(process.server);
+  dpd.todos.get(function(data, err) {
+    // Do something
+  });  
+});
+
+ +
    +
  • server {Server}
  • +
+ +

The Deployd server to build a client for.

+ +
    +
  • session {Session} (optional)
  • +
+ +

The Session object on the current request.

+ +
    +
  • stack {Array} (optional)
  • +
+ +

Used internally to prevent recursive calls to resources.

Mock context #

+ +

In order to make requests on resources within the Deployd server, internal-client creates mock req and res objects. These objects are not Streams and cannot be treated exactly like the standard http.ServerRequest and http.ServerResponse objects in Node, but they imitate their interfaces with the following properties:

req #

+ +
    +
  • url {String}
  • +
+ +

The URL of the request, i.e. "/hello"

+ +
    +
  • method {String}
  • +
+ +

The method of the request, i.e. "GET", "POST"

+ +
    +
  • query {Object}
  • +
+ +

The query object.

+ +
    +
  • body {Object}
  • +
+ +

The body of the request.

+ +
    +
  • session {Session}
  • +
+ +

The current session, if any.

+ +
    +
  • internal {Boolean}
  • +
+ +

Always equal to true to indicate an internal request and a mock req object.

res #

+ +
    +
  • statusCode {Number}
  • +
+ +

Set this to a standard HTTP response code.

+ +
    +
  • setHeader() {Function}
  • +
+ +

No-op.

+ +
    +
  • end(data) {Function}
  • +
+ +

Returns data to the internal client call. If data is JSON, it will be parsed into an object, otherwise it will simply be passed as a string. If the res.statusCode is not 200 or 204, data will be passed as an error.

+ +
    +
  • internal {Boolean}
  • +
+ +

Always equal to true to indicate an internal request and a mock res object.

+ + + + +

Resource Types #

+ +

Resources are the building block of a Deployd app. They provide a way to handle http requests at a root url. They must implement a handle(ctx, next) method that either handles a request or calls next() to give the request back to the router.

+ +

Resources can also be attributed with meta-data to allow the dashboard to dynamically render an editor gui for configuring a resource instance.

Events / Scripts #

+ +

A Resource can execute Scripts during the handling of an http request when certain events occur. This allows users of the resource to inject logic during specific events during an http request without having to extend the resource or create their own.

+ +

For example, the Collection resource executes the get.js event script when it retrieves each object from its store. If a get.js file exists in the instance folder of a resource (eg. /my-project/resources/my-collection/get.js), it will be pulled in by the resource and exposed as myResource.scripts.get.

Class: Resource #

+ +

A Resource inherits from EventEmitter. The following events are available.

+ +
    +
  • changed after a resource config has changed
  • +
  • deleted after a resource config has been deleted
  • +
+ +

Inheriting from Resource:

+ +
var Resource = require('deployd/lib/resource')
+  , util = require('util');
+
+function MyResource(name, options) {
+  // run the parent constructor
+  // before using any properties/methods
+  Resource.apply(this, arguments);
+}
+util.inherits(MyResource, Resource);
+module.exports = MyResource;
+
+ +
    +
  • name {String}
  • +
+ +

The name of the resource.

+ +
    +
  • options {Object}

    + +
    • configPath the project relative path to the resource instance
    • +
    • path the base path a resource should handle
    • +
    • db (optional) the database a resource will use for persistence
    • +
    • config the instance configuration object
    • +
    • server the server object
  • +
+ +

The following resource would respond with a file at the url /my-file.html.

+ +
function MyFileResource(name, options) {
+  Resource.apply(this, arguments);
+
+  this.on('changed', function(config) {
+    console.log('MyFileResource changed', config);
+  });
+}
+util.inherits(MyFileResource, Resource);
+
+MyFileResource.prototype.handle = function (ctx, next) {
+  if (ctx.url === '/my-file.html') {
+    fs.createReadStream('my-file.html').pipe(ctx.res);
+  } else {
+    next();
+  }
+}
+

Overriding Behavior #

+ +

Certain methods on a Resource prototype are called by the runtime. Their default behavior should be overridden to define an inherited Resources behavior.

resource.handle(ctx, next) #

+ +

Handle an incoming request. This gets called by the router.

+ +

The resource can either handle this context and call ctx.done(err, obj) with an error or result JSON object, or call next() to give the context back to the router. If a resource calls next() the router might find another match for the request, or respond with a 404.

+ + + +

The http context created by the Router. This provides an abstraction between the actual request and response. A Resource should call ctx.done or pipe to ctx.res if it can handle a request. Otherwise it should call next().

+ +

Override the handle method to return a string:

+ +
function MyResource(settings) {
+  Resource.apply(this, arguments);
+}
+util.inherits(MyResource, Resource);
+
+MyResource.prototype.handle = function (ctx, next) {
+  // respond with the file contents (or an error if one occurs)
+  fs.readFile('myfile.txt', ctx.done);
+}
+

resource.load(fn) #

+ +

Load any dependencies and call fn(err) with any errors that occur. This is automatically called by the runtime to support asynchronous construction of a resource (such as loading files).

+ +

Note: If this method is overridden, the super method must be called to support loading of the MyResource.events array.

resource.clientGeneration #

+ +

If true, ensures that this resource is included in dpd.js.

+ +
MyResource.prototype.clientGeneration = true;
+

resource.config #

+ +

The instance configuration object; used to access the resource's configuration from member functions.

+ +
MyResource.prototype.handle = function (ctx, next) {
+  fs.readFile(this.config.filePath, ctx.done);
+}
+

External Prototype #

+ +

This is a special type of prototype object that is used to build the dpd object. Each function on the Resource.external prototype Object are exposed externally in two places

+ +
    +
  1. To the generated dpd.js browser JavaScript client
  2. +
  3. To the Context.dpd object generated for inter-resource calls
  4. +
+ +

Here is an example of a simple resource that exposes a method on the external prototype.

+ +

/my-project/node_modules/example.js

+ +
var util = require('util');
+var Resource = require('deployd/lib/resource');
+function Example(name, options) {
+  Resource.apply(this, arguments);
+}
+util.inherits(Example, Resource);
+
+Example.external = {};
+
+Example.external.hello = function(options, ctx, fn) {
+  console.log(options.msg); // 'hello world'
+}
+
+ +

When the hello() method is called, a context does not need to be provided as the dpd object is built with a context. A callback may be provided which will be executed with results of fn(err, result).

+ +

/my-project/public/hello.js

+ +
dpd.example.hello({msg: 'hello world'});
+
+ +

/my-project/resources/other-resource/get.js

+ +
dpd.example.hello({msg: 'hello world'});
+

Resource.events #

+ +
    +
  • {Array}
  • +
+ +

If a Resource constructor includes an array of events, it will try to load the scripts in its instance folder (eg. /my-project/resources/my-resource/get.js) using resource.loadScripts(eventNames, fn).

+ +
MyResource.events = ['get'];
+
+ +

This will be available to each instance of this resource as this.events.

+ +

/my-project/node_modules/my-resource.js

+ +
MyResource.prototype.handle = function(ctx, next) {
+  if(this.events && this.events.get) {
+    var domain = {
+      say: function(msg) {
+        console.log(msg); // 'hello world'
+      }
+    }
+    this.events.get.run(ctx, domain, ctx.done);
+  }
+}
+
+ +

/my-project/resources/my-resource/get.js

+ +
say('hello world');
+

Resource.label #

+ +

The resource type's name as it appears in the dashboard. If this is not set, it will appear with its constructor name.

+ +
Hello.label = 'Hello World';
+

Resource.defaultPath #

+ +

The default path suggested to users creating a resource. If this is not set, it will use the constructor's name in lowercase.

+ +
Hello.defaultPath = '/hello-world'; 
+

Collection.basicDashboard #

+ +

Set this property to an object to create a custom configuration page for your resource type.

+ +
    +
  • settings - An array of objects describing which properties to display.
  • +
  • name - The name of the property. This is how the value will be passed into the config object, so make sure it's something JavaScript-friendly, e.g. maxItems.
  • +
  • type - The type of control to edit this property. Allowed types are text, textarea, number, and checkbox.
  • +
  • description (Optional) - Explanatory text to appear below the field.
  • +
+ + + +
Hello.basicDashboard = {
+  settings: [{
+      name: 'propertyName',
+      type: 'text',
+      description: "This description appears below the text field"
+  }, {
+      name: 'longTextProperty',
+      type: 'textarea'
+  }, {
+      name: 'numericProperty',
+      type: 'number'
+  }, {
+      name: 'booleanProperty',
+      type: 'checkbox'
+  }]
+};
+
+ +

The above sample will produce the following dashboard page:

+ +

Example basic dashboard

Collection.dashboard #

+ +

A resource can describe the dependencies of a fully custom dashboard editor UI. This will be passed to the dashboard during rendering to create a custom UI.

+ +

This example creates the custom dashboard for the Collection resource. It automatically includes pages and page-specific scripts:

+ +
Collection.dashboard = {
+    path: path.join(__dirname, 'dashboard')
+  , pages: ['Properties', 'Data', 'Events', 'API']
+  , scripts: [
+      '/js/ui.js'
+    , '/js/util.js'
+  ]
+}
+
+ +
    +
  • path {String}
  • +
+ +

The absolute path to this resource's dashboard

+ +
    +
  • pages {Array} (optional)
  • +
+ +

An array of pages to appear in the sidebar. If this is not provided, the only page available will be "Config" (and "Events", if MyResource.events is set).

+ +

The dashboard will load content from [current-page].html and js/[current-page].js.

+ +

Note: The "Config" page will load from index.html and js/index.js.

+ +
    +
  • scripts {Array} (optional)
  • +
+ +

An array of extra JavaScript files to load with the dashboard pages.

Dashboard asset loading #

+ +

When you request a page from a custom dashboard, it will load the following files, if they are available, from the dashboard.path:

+ +
    +
  • [current-page].html
  • +
  • js/[current-page].js
  • +
  • style.css
  • +
+ +

The default page is index; the config page will also redirect to index.

+ +

The config or index page will load the basic dashboard if no index.html file is provided. +The events page will load the default event editor if no events.html file is provided.

+ +

It will also load the JavaScript files in the dashboard.scripts property.

Creating a custom dashboard #

Event editor control #
+ +

To embed the event editor in your dashboard, include this empty div:

+ +
<div id="event-editor" class="default-editor"></div>
+
Styling #
+ +

For styling, the dashboard uses a re-skinned version of Twitter Bootstrap 2.0.2.

JavaScript #
+ +

The dashboard provides several JavaScript libraries by default:

+ + + +

Within the dashboard, a Context object is available:

+ +
//Automatically generated by Deployd:
+window.Context = {
+  resourceId: '/hello', // The id of the current resource
+  resourceType: 'Hello', // The type of the current resource
+  page: 'properties', // The current page, in multi-page dashboards
+  basicDashboard: {} // The configuration of the basic dashboard
+};
+
+ +

You can use this to query the current resource:

+ +
dpd(Context.resourceId).get(function(result, err) {
+  //Do something
+});
+
+ +

In the dashboard, you also have access to the special __resources resource, which lets you update your app's configuration files:

+ +
// Get the config for the current resource
+dpd('__resources').get(Context.resourceId, function(result, err) {
+  //Do something
+});
+
+// Set a property for the current resource
+dpd('__resources').put(Context.resourceId, {someProperty: true}, function(result, err) {
+  //Do something
+});
+
+// Set all properties for the current resource, deleting any that are not provided
+dpd('__resources').put(Context.resourceId, {someProperty: true, $setAll: true}, function(result, err) {
+  //Do something
+});
+
+// Save another file, which will be loaded by the resource
+dpd('__resources').post(Context.resourceId + '/content.md', {value: "# Hello World!"}, function(result, err)) {
+  //Do something
+});
+
+ + + + +

Server #

+ +

Deployd's Server extends node's http.Server. A Server is created with an options object that tells Deployd what port to serve on and which database to connect to.

+ +

The Server object is also the main entry point for modules. After it is started, the Server instance is available at process.server.

Class: Server #

+ +

Servers are created when calling the Deployd exported function.

+ +
var deployd = require('deployd')
+  , options = {port: 3000}
+  , server = deployd(options);
+
+ +
    +
  • options {Object}

    + +
    • port {Number} - the port to listen on
    • +
    • db {Object} - the database to connect to
    • +
    • port {Number} - the port of the database server
    • +
    • host {String} - the ip or domain of the database server
    • +
    • name {String} - the name of the database
    • +
    • credentials {Object} - credentials for the server +
      • username {String}
      • +
      • password {String}
    • +
    • env {String} - the environment to run in.
  • +
+ +

Note: If options.env is "development", the dashboard will not require authentication and configuration will not be cached. Make sure to change this to "production" or something similar when deploying.

Server.listen([port], [host]) #

+ +

Load any configuration and start listening for incoming connections.

+ +
var dpd = require('deployd')
+  , server = dpd()
+
+dpd.listen();
+dpd.on('listening', function() {
+  console.log(server.options.port); // 2403
+});
+

Server.createStore(namespace) #

+ +

Create a new Store for persisting data using the database info that was passed to the server when it was created.

+ +
// Create a new server
+var server = new Server({port: 3000, db: {host: 'localhost', port: 27015, name: 'my-db'}});
+
+// Attach a store to the server
+var todos = server.createStore('todos');
+
+// Use the store to CRUD data
+todos.insert({name: 'go to the store', done: true}, ...); // see `Store` for more info
+

Server.sockets #

+ +

The socket.io sockets Manager object (view source).

Server.sessions #

+ +

The server's SessionStore.

Server.router #

+ +

The server's Router.

Server.resources #

+ +

An Array of the server's Resource instances. These are built from the config and type loaders.

+ + + + +

Session #

+ +

An in-memory representation of a client or user connection that can be saved to disk. Data will be passed around via a Context to resources.

Class: Session #

+ +

A store for persisting sessions in-between connection and disconnection. Automatically creates session IDs on inserted objects.

+ +
var session = new Session({id: 'my-sid', new SessionStore('sessions', db)});
+session.set({uid: 'my-uid'}).save();
+
+ +
    +
  • data {Object}
  • +
+ +

The data used to construct the session.

+ +
    +
  • store {SessionStore}
  • +
+ +

The store used to persist the session.

+ +
    +
  • sockets {Socket.IO.sockets}
  • +
+ +

The Socket.IO sockets object used to attach an existing socket.

Session.set(changes) #

+ +
    +
  • changes {Object}
  • +
+ +

An object containing changes to the session's data.

Session.save(fn) #

+ +
    +
  • fn(err, data) {Function} optional
  • +
+ +

Save the in memory representation of a session to its store.

Session.fetch(fn) #

+ +
    +
  • fn(err, data) {Function} optional
  • +
+ +

Reset the session using the data persisted in its store.

Session.remove(fn) #

+ +
    +
  • fn(err, data) {Function} optional
  • +
+ +

Remove the session.

Session.emitToAll(event, data) #

+ +
    +
  • event {String}
  • +
+ +

The event to emit to all session's sockets.

+ +
    +
  • data {Object} optional
  • +
+ +

The data to send to sockets listening to the given event.

Session.emitToUsers(collection, query, event, data) #

+ +
    +
  • collection {Collection}
  • +
+ +

The user-collection instance (eg. dpd.todos) to use to find users.

+ +
    +
  • query {Object}
  • +
+ +

Only emit the event to users that match this query.

+ +
    +
  • event {String}
  • +
+ +

The event to emit to all session's sockets.

+ +
    +
  • data {Object} optional
  • +
+ +

The data to send to sockets listening to the given event.

+ + + + +

Session Store #

+ +

Sessions are persisted in a modified store. This store has several methods to help create and manage sessions.

Class: SessionStore #

+ +

A store for persisting sessions in-between connection and disconnection. Automatically creates session IDs on inserted objects.

+ +
var db = process.server.db;
+var sockets = process.server.sockets;
+var name = 'sessions';
+var store = new SessionStore(name, db, sockets);
+
+ +
    +
  • name {String}
  • +
+ +

The name of the db store.

+ +
    +
  • db {Db}
  • +
+ +

The server db instance

+ +
    +
  • sockets {Socket.IO.sockets}
  • +
+ +

The socket.io sockets object.

SessionStore.createSession(sid, fn) #

+ +
    +
  • sid {String} optional
  • +
+ +

An existing session id.

+ +
    +
  • fn(err, session) {Function}
  • +
+ +

Called once the session has been created.

+ + + + +

Store #

+ +

An abstraction of a collection of objects in a database. Collections are HTTP wrappers around a Store. You can access or create a store the same way.

+ +
var myStore = process.server.createStore('my-store');
+

Class: Store #

+ +

You shouldn't construct Stores directly. Instead use the process.server.createStore() method.

Store.insert(object, fn) #

+ +
    +
  • object {Object}
  • +
+ +

The data to insert into the store.

+ +
    +
  • fn(err, result) {Function}
  • +
+ +

Called once the insert operation is finished.

Store.count(query, fn) #

+ +
    +
  • query {Object}
  • +
+ +

Only count objects that match this query.

+ +
    +
  • fn(err, count) {Function}
  • +
+ +

Called once the count operation is finished. count is a number.

Store.find(query, fn) #

+ +
    +
  • query {Object}
  • +
+ +

Only returns objects that match this query.

+ +
    +
  • fn(err, results) {Function}
  • +
+ +

Called once the find operation is finished.

Store.first(query, fn) #

+ +
    +
  • query {Object}

  • +
  • fn(err, result) {Function}

  • +
+ +

Find the first object in the store that match the given query.

Store.update(query, changes, fn) #

+ +
    +
  • query {Object}

  • +
  • changes {Object}

  • +
  • fn(err, updated) {Function}

  • +
+ +

Update an object or objects in the store that match the given query only modifying the values in the given changes object.

Store.remove(query, fn) #

+ +
    +
  • query {Object}

  • +
  • fn(err, updated) {Function}

  • +
+ +

Remove an object or objects in the store that match the given query.

Store.rename(name, fn) #

+ +
    +
  • name {String}

  • +
  • fn(err) {Function}

  • +
+ +

Rename the store.

+ + + +

More

+ + + +
+
+
+

Other docs in "Developing Modules"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/internal-api/collection.md.html b/docs/developing-modules/internal-api/collection.md.html new file mode 100644 index 0000000..3c90eff --- /dev/null +++ b/docs/developing-modules/internal-api/collection.md.html @@ -0,0 +1,593 @@ + + + + + + Collection Resource Type - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Collection Resource Type #

+ +

Collections are the most common Resource Type in Deployd. They allow the user to store and load data from their app's Store. Behind the scenes, they validate incoming requests and execute event scripts for get, post, put, delete, and validate. If all event scripts execute without error (or cancel()ing), the request is proxied to the collection's Store.

Class: Collection #

+ +

A Collection inherits from Resource. Any constructor that inherits from Collection must include its own Collection.external prototype object.

+ +

Example inheriting from Collection:

+ +
var Collection = require('deployd/lib/resources/collection');
+var util = require('util');
+
+function MyCollection(name, options) {
+  Collection.apply(this, arguments);
+}
+MyCollection.external = Collection.external;
+
+util.inherits(MyCollection, Collection);
+

collection.store #

+ +
    +
  • {Store}
  • +
+ +

The backing persistence abstraction layer. Supports saving and reading data from a database. See Store for more info.

collection.validate(body, create) #

+ +

Validate the request body against the Collection's properties +and return an object containing any errors.

+ +
    +
  • body {Object}
  • +
+ +

The object to validate

+ +
    +
  • create {Boolean}
  • +
+ +

Should validate a new object being created

+ +
    +
  • return errors {Object}
  • +

collection.sanitize(body) #

+ +

Sanitize the request body against the Collection's properties +object and return an object containing only properties that exist in the +collection.config.properties object.

+ +
    +
  • body {Object}
  • +
  • return sanitized {Object}
  • +

collection.sanitizeQuery(query) #

+ +

Sanitize the request query against the collection.properties +and return an object containing only properties that exist in the +collection.properties object.

+ +
    +
  • query {Object}
  • +
  • return sanitizedQuery {Object}
  • +

collection.parseId(ctx) #

+ +

Parse the ctx.url for an id. Override this to change how an object's id is parsed out of a url.

+ +
    +
  • ctx {Context}
  • +

collection.find(ctx, fn) #

+ +

Find all the objects in a collection that match the given ctx.query. Then execute a get event script, if one exists, using each object found. Finally call fn(err) passing an error if one occurred.

+ +
    +
  • ctx {Context}
  • +
  • fn(err)
  • +

collection.remove(ctx, fn) #

+ +

Execute a delete event script, if one exists, using each object found. Then remove a single object that matches the ctx.query.id. Finally call fn(err) passing an error if one occurred.

+ +
    +
  • ctx {Context}
  • +
  • fn(err)
  • +

collection.save(ctx, fn) #

+ +

First execute a validate event script if one exists. If the event does not error, try to save the ctx.body into the store. If ctx.body.id exists, perform an update and execute the put event script. Otherwise perform an insert and execute the post event script. Finally call fn(err), passing an error if one occurred.

+ +
    +
  • ctx {Context}
  • +
  • fn(err)
  • +
+ + +

More

+ + + +
+
+
+

Other docs in "Internal API Reference"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/internal-api/context.md.html b/docs/developing-modules/internal-api/context.md.html new file mode 100644 index 0000000..a5c0ab8 --- /dev/null +++ b/docs/developing-modules/internal-api/context.md.html @@ -0,0 +1,551 @@ + + + + + + Context - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Context #

+ +

Contexts are a thin abstraction between http requests, Resources, and Scripts. They provide utility methods to simplify interacting with node's http.ServerRequest and http.ServerResponse objects.

+ +

A Context is built from a request and response and passed to a matching Resource by the Router. This might originate from an external http request or a call to an internal client from a Script.

Mock Contexts #

+ +

Contexts may be created without a real request and response such as during an internal request using the dpd object. See Internal Client for more info.

Class: Context #

+ +
var Context = require('deployd/lib/context');
+var ctx = new Context(resource, req, res, server);
+

ctx.done(err, result) #

+ +

Continuous callback sugar for easily calling res.end(). Conforms to the idiomatic callback signature for most node APIs. It can be passed directly to most APIs that require a callback in node.

+ +
fs.readFile('bar.txt', ctx.done);
+
+ +
    +
  • err {Error | Object}
  • +
+ +

An error if one occurred during handling of the ctx. Otherwise it should be null.

+ +
    +
  • result {Object}
  • +
+ +

The result of executing the ctx. This should be an object that is serializable as JSON.

ctx.body #

+ +
    +
  • {Object}
  • +
+ +

The body of the request if sent as application/json or application/x-www-form-urlencoded.

ctx.query #

+ +
    +
  • {Object}
  • +
+ +

The query string of the request serialized as an Object. Supports both ?key=value as well as ?{"key":"value"}.

ctx.method #

+ +
    +
  • {Object}
  • +
+ +

An alias to the request's method.

+ + +

More

+ + + +
+
+
+

Other docs in "Internal API Reference"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/internal-api/internal-client.md.html b/docs/developing-modules/internal-api/internal-client.md.html new file mode 100644 index 0000000..3065439 --- /dev/null +++ b/docs/developing-modules/internal-api/internal-client.md.html @@ -0,0 +1,600 @@ + + + + + + Internal Client - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Internal Client #

+ +

The internal-client module is responsible for building a server-side version of dpd.js. It is intended for use in Scripts but can be used by resources to access other resources' REST APIs.

+ +

Note: As in dpd.js, the callback for an internal client request receives the arguments (data, err), which is different than the Node convention of (err, data).

internalClient.build(server, [session], [stack]) #

+ +
var internalClient = require('deployd/lib/internal-client');
+
+process.server.on('listening', function() {
+  var dpd = internalClient.build(process.server);
+  dpd.todos.get(function(data, err) {
+    // Do something
+  });  
+});
+
+ +
    +
  • server {Server}
  • +
+ +

The Deployd server to build a client for.

+ +
    +
  • session {Session} (optional)
  • +
+ +

The Session object on the current request.

+ +
    +
  • stack {Array} (optional)
  • +
+ +

Used internally to prevent recursive calls to resources.

Mock context #

+ +

In order to make requests on resources within the Deployd server, internal-client creates mock req and res objects. These objects are not Streams and cannot be treated exactly like the standard http.ServerRequest and http.ServerResponse objects in Node, but they imitate their interfaces with the following properties:

req #

+ +
    +
  • url {String}
  • +
+ +

The URL of the request, i.e. "/hello"

+ +
    +
  • method {String}
  • +
+ +

The method of the request, i.e. "GET", "POST"

+ +
    +
  • query {Object}
  • +
+ +

The query object.

+ +
    +
  • body {Object}
  • +
+ +

The body of the request.

+ +
    +
  • session {Session}
  • +
+ +

The current session, if any.

+ +
    +
  • internal {Boolean}
  • +
+ +

Always equal to true to indicate an internal request and a mock req object.

res #

+ +
    +
  • statusCode {Number}
  • +
+ +

Set this to a standard HTTP response code.

+ +
    +
  • setHeader() {Function}
  • +
+ +

No-op.

+ +
    +
  • end(data) {Function}
  • +
+ +

Returns data to the internal client call. If data is JSON, it will be parsed into an object, otherwise it will simply be passed as a string. If the res.statusCode is not 200 or 204, data will be passed as an error.

+ +
    +
  • internal {Boolean}
  • +
+ +

Always equal to true to indicate an internal request and a mock res object.

+ + +

More

+ + + +
+
+
+

Other docs in "Internal API Reference"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/internal-api/resource.md.html b/docs/developing-modules/internal-api/resource.md.html new file mode 100644 index 0000000..40546c8 --- /dev/null +++ b/docs/developing-modules/internal-api/resource.md.html @@ -0,0 +1,838 @@ + + + + + + Resource Types - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Resource Types #

+ +

Resources are the building block of a Deployd app. They provide a way to handle http requests at a root url. They must implement a handle(ctx, next) method that either handles a request or calls next() to give the request back to the router.

+ +

Resources can also be attributed with meta-data to allow the dashboard to dynamically render an editor gui for configuring a resource instance.

Events / Scripts #

+ +

A Resource can execute Scripts during the handling of an http request when certain events occur. This allows users of the resource to inject logic during specific events during an http request without having to extend the resource or create their own.

+ +

For example, the Collection resource executes the get.js event script when it retrieves each object from its store. If a get.js file exists in the instance folder of a resource (eg. /my-project/resources/my-collection/get.js), it will be pulled in by the resource and exposed as myResource.scripts.get.

Class: Resource #

+ +

A Resource inherits from EventEmitter. The following events are available.

+ +
    +
  • changed after a resource config has changed
  • +
  • deleted after a resource config has been deleted
  • +
+ +

Inheriting from Resource:

+ +
var Resource = require('deployd/lib/resource')
+  , util = require('util');
+
+function MyResource(name, options) {
+  // run the parent constructor
+  // before using any properties/methods
+  Resource.apply(this, arguments);
+}
+util.inherits(MyResource, Resource);
+module.exports = MyResource;
+
+ +
    +
  • name {String}
  • +
+ +

The name of the resource.

+ +
    +
  • options {Object}

    + +
    • configPath the project relative path to the resource instance
    • +
    • path the base path a resource should handle
    • +
    • db (optional) the database a resource will use for persistence
    • +
    • config the instance configuration object
    • +
    • server the server object
  • +
+ +

The following resource would respond with a file at the url /my-file.html.

+ +
function MyFileResource(name, options) {
+  Resource.apply(this, arguments);
+
+  this.on('changed', function(config) {
+    console.log('MyFileResource changed', config);
+  });
+}
+util.inherits(MyFileResource, Resource);
+
+MyFileResource.prototype.handle = function (ctx, next) {
+  if (ctx.url === '/my-file.html') {
+    fs.createReadStream('my-file.html').pipe(ctx.res);
+  } else {
+    next();
+  }
+}
+

Overriding Behavior #

+ +

Certain methods on a Resource prototype are called by the runtime. Their default behavior should be overridden to define an inherited Resources behavior.

resource.handle(ctx, next) #

+ +

Handle an incoming request. This gets called by the router.

+ +

The resource can either handle this context and call ctx.done(err, obj) with an error or result JSON object, or call next() to give the context back to the router. If a resource calls next() the router might find another match for the request, or respond with a 404.

+ + + +

The http context created by the Router. This provides an abstraction between the actual request and response. A Resource should call ctx.done or pipe to ctx.res if it can handle a request. Otherwise it should call next().

+ +

Override the handle method to return a string:

+ +
function MyResource(settings) {
+  Resource.apply(this, arguments);
+}
+util.inherits(MyResource, Resource);
+
+MyResource.prototype.handle = function (ctx, next) {
+  // respond with the file contents (or an error if one occurs)
+  fs.readFile('myfile.txt', ctx.done);
+}
+

resource.load(fn) #

+ +

Load any dependencies and call fn(err) with any errors that occur. This is automatically called by the runtime to support asynchronous construction of a resource (such as loading files).

+ +

Note: If this method is overridden, the super method must be called to support loading of the MyResource.events array.

resource.clientGeneration #

+ +

If true, ensures that this resource is included in dpd.js.

+ +
MyResource.prototype.clientGeneration = true;
+

resource.config #

+ +

The instance configuration object; used to access the resource's configuration from member functions.

+ +
MyResource.prototype.handle = function (ctx, next) {
+  fs.readFile(this.config.filePath, ctx.done);
+}
+

External Prototype #

+ +

This is a special type of prototype object that is used to build the dpd object. Each function on the Resource.external prototype Object are exposed externally in two places

+ +
    +
  1. To the generated dpd.js browser JavaScript client
  2. +
  3. To the Context.dpd object generated for inter-resource calls
  4. +
+ +

Here is an example of a simple resource that exposes a method on the external prototype.

+ +

/my-project/node_modules/example.js

+ +
var util = require('util');
+var Resource = require('deployd/lib/resource');
+function Example(name, options) {
+  Resource.apply(this, arguments);
+}
+util.inherits(Example, Resource);
+
+Example.external = {};
+
+Example.external.hello = function(options, ctx, fn) {
+  console.log(options.msg); // 'hello world'
+}
+
+ +

When the hello() method is called, a context does not need to be provided as the dpd object is built with a context. A callback may be provided which will be executed with results of fn(err, result).

+ +

/my-project/public/hello.js

+ +
dpd.example.hello({msg: 'hello world'});
+
+ +

/my-project/resources/other-resource/get.js

+ +
dpd.example.hello({msg: 'hello world'});
+

Resource.events #

+ +
    +
  • {Array}
  • +
+ +

If a Resource constructor includes an array of events, it will try to load the scripts in its instance folder (eg. /my-project/resources/my-resource/get.js) using resource.loadScripts(eventNames, fn).

+ +
MyResource.events = ['get'];
+
+ +

This will be available to each instance of this resource as this.events.

+ +

/my-project/node_modules/my-resource.js

+ +
MyResource.prototype.handle = function(ctx, next) {
+  if(this.events && this.events.get) {
+    var domain = {
+      say: function(msg) {
+        console.log(msg); // 'hello world'
+      }
+    }
+    this.events.get.run(ctx, domain, ctx.done);
+  }
+}
+
+ +

/my-project/resources/my-resource/get.js

+ +
say('hello world');
+

Resource.label #

+ +

The resource type's name as it appears in the dashboard. If this is not set, it will appear with its constructor name.

+ +
Hello.label = 'Hello World';
+

Resource.defaultPath #

+ +

The default path suggested to users creating a resource. If this is not set, it will use the constructor's name in lowercase.

+ +
Hello.defaultPath = '/hello-world'; 
+

Collection.basicDashboard #

+ +

Set this property to an object to create a custom configuration page for your resource type.

+ +
    +
  • settings - An array of objects describing which properties to display.
  • +
  • name - The name of the property. This is how the value will be passed into the config object, so make sure it's something JavaScript-friendly, e.g. maxItems.
  • +
  • type - The type of control to edit this property. Allowed types are text, textarea, number, and checkbox.
  • +
  • description (Optional) - Explanatory text to appear below the field.
  • +
+ + + +
Hello.basicDashboard = {
+  settings: [{
+      name: 'propertyName',
+      type: 'text',
+      description: "This description appears below the text field"
+  }, {
+      name: 'longTextProperty',
+      type: 'textarea'
+  }, {
+      name: 'numericProperty',
+      type: 'number'
+  }, {
+      name: 'booleanProperty',
+      type: 'checkbox'
+  }]
+};
+
+ +

The above sample will produce the following dashboard page:

+ +

Example basic dashboard

Collection.dashboard #

+ +

A resource can describe the dependencies of a fully custom dashboard editor UI. This will be passed to the dashboard during rendering to create a custom UI.

+ +

This example creates the custom dashboard for the Collection resource. It automatically includes pages and page-specific scripts:

+ +
Collection.dashboard = {
+    path: path.join(__dirname, 'dashboard')
+  , pages: ['Properties', 'Data', 'Events', 'API']
+  , scripts: [
+      '/js/ui.js'
+    , '/js/util.js'
+  ]
+}
+
+ +
    +
  • path {String}
  • +
+ +

The absolute path to this resource's dashboard

+ +
    +
  • pages {Array} (optional)
  • +
+ +

An array of pages to appear in the sidebar. If this is not provided, the only page available will be "Config" (and "Events", if MyResource.events is set).

+ +

The dashboard will load content from [current-page].html and js/[current-page].js.

+ +

Note: The "Config" page will load from index.html and js/index.js.

+ +
    +
  • scripts {Array} (optional)
  • +
+ +

An array of extra JavaScript files to load with the dashboard pages.

Dashboard asset loading #

+ +

When you request a page from a custom dashboard, it will load the following files, if they are available, from the dashboard.path:

+ +
    +
  • [current-page].html
  • +
  • js/[current-page].js
  • +
  • style.css
  • +
+ +

The default page is index; the config page will also redirect to index.

+ +

The config or index page will load the basic dashboard if no index.html file is provided. +The events page will load the default event editor if no events.html file is provided.

+ +

It will also load the JavaScript files in the dashboard.scripts property.

Creating a custom dashboard #

Event editor control #
+ +

To embed the event editor in your dashboard, include this empty div:

+ +
<div id="event-editor" class="default-editor"></div>
+
Styling #
+ +

For styling, the dashboard uses a re-skinned version of Twitter Bootstrap 2.0.2.

JavaScript #
+ +

The dashboard provides several JavaScript libraries by default:

+ + + +

Within the dashboard, a Context object is available:

+ +
//Automatically generated by Deployd:
+window.Context = {
+  resourceId: '/hello', // The id of the current resource
+  resourceType: 'Hello', // The type of the current resource
+  page: 'properties', // The current page, in multi-page dashboards
+  basicDashboard: {} // The configuration of the basic dashboard
+};
+
+ +

You can use this to query the current resource:

+ +
dpd(Context.resourceId).get(function(result, err) {
+  //Do something
+});
+
+ +

In the dashboard, you also have access to the special __resources resource, which lets you update your app's configuration files:

+ +
// Get the config for the current resource
+dpd('__resources').get(Context.resourceId, function(result, err) {
+  //Do something
+});
+
+// Set a property for the current resource
+dpd('__resources').put(Context.resourceId, {someProperty: true}, function(result, err) {
+  //Do something
+});
+
+// Set all properties for the current resource, deleting any that are not provided
+dpd('__resources').put(Context.resourceId, {someProperty: true, $setAll: true}, function(result, err) {
+  //Do something
+});
+
+// Save another file, which will be loaded by the resource
+dpd('__resources').post(Context.resourceId + '/content.md', {value: "# Hello World!"}, function(result, err)) {
+  //Do something
+});
+
+ + +

More

+ + + +
+
+
+

Other docs in "Internal API Reference"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/internal-api/script.md.html b/docs/developing-modules/internal-api/script.md.html new file mode 100644 index 0000000..7aa615c --- /dev/null +++ b/docs/developing-modules/internal-api/script.md.html @@ -0,0 +1,571 @@ + + + + + + Event Scripts - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Event Scripts #

+ +

A Script provides a mechanism to run JavaScript source in a sandbox. A Script is executed with a Context and a domain object using the node vm module. Each Script runs independently. They do not share global scope or state with other scripts or modules.

Async Mode #

+ +

Scripts can be run in an async mode. This mode is triggered when a Script is run(ctx, domain, fn) with a callback (fn). When run in this mode a Script will try scrub all functions in the domain for operations that require a callback. If a callback is required, the function is re-written to count the callbacks completion and notify the script. When all pending callbacks are complete the script is considered finished.

Async Errors #

+ +

If a script is run with a callback (in async mode), any error will emit an internal error event. This will stop the execution of the script and pass the error to the script's callback.

Class: Script #

+ +
var Script = require('deployd/lib/script');
+var script = new Script('hello()', 'hello.js');
+
+ +

A Script's source is compiled when its constructor is called. It can be run() many times with independent Contexts and domains.

script.run(ctx, domain, [fn]) #

+ +
    +
  • ctx {Context}
  • +
+ +

A Context with a session, query, req and res.

+ +
    +
  • domain {Object}
  • +
+ +

An Object containing functions to be injected into the Scripts sandbox. This will override any existing functions or objects in the Scripts sandbox / global scope.

+ +

This example domain provides a log function to a script.

+ +
var script = new Script('log("hello world")');
+var context = {};
+var domain = {};
+var msg;
+
+domain.log = function(str) {
+  console.log(msg = str);
+}
+
+script.run(ctx, domain, function(err) {
+  console.log(msg); // 'hello world'
+});
+
+ +
    +
  • fn(err) optional
  • +
+ +

If a callback is provided the script will be run in async mode. The callback will receive any error even if the error occurs asynchronously. Otherwise it will be called without any arguments when the script is finished executing (see: async mode).

+ +
var s = new Script('setTimeout(function() { throw "test err" }, 22)');
+
+// give the script access to setTimeout
+var domain = {setTimeout: setTimeout};
+
+s.run({}, domain, function (e) {
+  console.log(e); // test err
+});
+

Script.load(path, fn) #

+ +
    +
  • path {String}

  • +
  • fn(err, script)

  • +
+ +

Load a new script at the given file path. Runs the callback with an error if one occurred, or a new Script loaded from the contents of the file.

Default Domain #

+ +

Scripts are executed with a default sandbox and set of domain functions. These are functions that every Script usually needs, and are available to every Script. These can be overridden by passing a value such as {cancel: ...} in a domain. See Event API for Custom Resources for documentation on this default domain.

+ + +

More

+ + + +
+
+
+

Other docs in "Internal API Reference"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/internal-api/server.md.html b/docs/developing-modules/internal-api/server.md.html new file mode 100644 index 0000000..fbb8887 --- /dev/null +++ b/docs/developing-modules/internal-api/server.md.html @@ -0,0 +1,564 @@ + + + + + + Server - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Server #

+ +

Deployd's Server extends node's http.Server. A Server is created with an options object that tells Deployd what port to serve on and which database to connect to.

+ +

The Server object is also the main entry point for modules. After it is started, the Server instance is available at process.server.

Class: Server #

+ +

Servers are created when calling the Deployd exported function.

+ +
var deployd = require('deployd')
+  , options = {port: 3000}
+  , server = deployd(options);
+
+ +
    +
  • options {Object}

    + +
    • port {Number} - the port to listen on
    • +
    • db {Object} - the database to connect to
    • +
    • port {Number} - the port of the database server
    • +
    • host {String} - the ip or domain of the database server
    • +
    • name {String} - the name of the database
    • +
    • credentials {Object} - credentials for the server +
      • username {String}
      • +
      • password {String}
    • +
    • env {String} - the environment to run in.
  • +
+ +

Note: If options.env is "development", the dashboard will not require authentication and configuration will not be cached. Make sure to change this to "production" or something similar when deploying.

Server.listen([port], [host]) #

+ +

Load any configuration and start listening for incoming connections.

+ +
var dpd = require('deployd')
+  , server = dpd()
+
+dpd.listen();
+dpd.on('listening', function() {
+  console.log(server.options.port); // 2403
+});
+

Server.createStore(namespace) #

+ +

Create a new Store for persisting data using the database info that was passed to the server when it was created.

+ +
// Create a new server
+var server = new Server({port: 3000, db: {host: 'localhost', port: 27015, name: 'my-db'}});
+
+// Attach a store to the server
+var todos = server.createStore('todos');
+
+// Use the store to CRUD data
+todos.insert({name: 'go to the store', done: true}, ...); // see `Store` for more info
+

Server.sockets #

+ +

The socket.io sockets Manager object (view source).

Server.sessions #

+ +

The server's SessionStore.

Server.router #

+ +

The server's Router.

Server.resources #

+ +

An Array of the server's Resource instances. These are built from the config and type loaders.

+ + +

More

+ + + +
+
+
+

Other docs in "Internal API Reference"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/internal-api/session-store.md.html b/docs/developing-modules/internal-api/session-store.md.html new file mode 100644 index 0000000..17195ca --- /dev/null +++ b/docs/developing-modules/internal-api/session-store.md.html @@ -0,0 +1,546 @@ + + + + + + Session Store - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Session Store #

+ +

Sessions are persisted in a modified store. This store has several methods to help create and manage sessions.

Class: SessionStore #

+ +

A store for persisting sessions in-between connection and disconnection. Automatically creates session IDs on inserted objects.

+ +
var db = process.server.db;
+var sockets = process.server.sockets;
+var name = 'sessions';
+var store = new SessionStore(name, db, sockets);
+
+ +
    +
  • name {String}
  • +
+ +

The name of the db store.

+ +
    +
  • db {Db}
  • +
+ +

The server db instance

+ +
    +
  • sockets {Socket.IO.sockets}
  • +
+ +

The socket.io sockets object.

SessionStore.createSession(sid, fn) #

+ +
    +
  • sid {String} optional
  • +
+ +

An existing session id.

+ +
    +
  • fn(err, session) {Function}
  • +
+ +

Called once the session has been created.

+ + +

More

+ + + +
+
+
+

Other docs in "Internal API Reference"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/internal-api/session.md.html b/docs/developing-modules/internal-api/session.md.html new file mode 100644 index 0000000..61fe89d --- /dev/null +++ b/docs/developing-modules/internal-api/session.md.html @@ -0,0 +1,592 @@ + + + + + + Session - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Session #

+ +

An in-memory representation of a client or user connection that can be saved to disk. Data will be passed around via a Context to resources.

Class: Session #

+ +

A store for persisting sessions in-between connection and disconnection. Automatically creates session IDs on inserted objects.

+ +
var session = new Session({id: 'my-sid', new SessionStore('sessions', db)});
+session.set({uid: 'my-uid'}).save();
+
+ +
    +
  • data {Object}
  • +
+ +

The data used to construct the session.

+ +
    +
  • store {SessionStore}
  • +
+ +

The store used to persist the session.

+ +
    +
  • sockets {Socket.IO.sockets}
  • +
+ +

The Socket.IO sockets object used to attach an existing socket.

Session.set(changes) #

+ +
    +
  • changes {Object}
  • +
+ +

An object containing changes to the session's data.

Session.save(fn) #

+ +
    +
  • fn(err, data) {Function} optional
  • +
+ +

Save the in memory representation of a session to its store.

Session.fetch(fn) #

+ +
    +
  • fn(err, data) {Function} optional
  • +
+ +

Reset the session using the data persisted in its store.

Session.remove(fn) #

+ +
    +
  • fn(err, data) {Function} optional
  • +
+ +

Remove the session.

Session.emitToAll(event, data) #

+ +
    +
  • event {String}
  • +
+ +

The event to emit to all session's sockets.

+ +
    +
  • data {Object} optional
  • +
+ +

The data to send to sockets listening to the given event.

Session.emitToUsers(collection, query, event, data) #

+ +
    +
  • collection {Collection}
  • +
+ +

The user-collection instance (eg. dpd.todos) to use to find users.

+ +
    +
  • query {Object}
  • +
+ +

Only emit the event to users that match this query.

+ +
    +
  • event {String}
  • +
+ +

The event to emit to all session's sockets.

+ +
    +
  • data {Object} optional
  • +
+ +

The data to send to sockets listening to the given event.

+ + +

More

+ + + +
+
+
+

Other docs in "Internal API Reference"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/developing-modules/internal-api/store.md.html b/docs/developing-modules/internal-api/store.md.html new file mode 100644 index 0000000..7221a8c --- /dev/null +++ b/docs/developing-modules/internal-api/store.md.html @@ -0,0 +1,578 @@ + + + + + + Store - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Store #

+ +

An abstraction of a collection of objects in a database. Collections are HTTP wrappers around a Store. You can access or create a store the same way.

+ +
var myStore = process.server.createStore('my-store');
+

Class: Store #

+ +

You shouldn't construct Stores directly. Instead use the process.server.createStore() method.

Store.insert(object, fn) #

+ +
    +
  • object {Object}
  • +
+ +

The data to insert into the store.

+ +
    +
  • fn(err, result) {Function}
  • +
+ +

Called once the insert operation is finished.

Store.count(query, fn) #

+ +
    +
  • query {Object}
  • +
+ +

Only count objects that match this query.

+ +
    +
  • fn(err, count) {Function}
  • +
+ +

Called once the count operation is finished. count is a number.

Store.find(query, fn) #

+ +
    +
  • query {Object}
  • +
+ +

Only returns objects that match this query.

+ +
    +
  • fn(err, results) {Function}
  • +
+ +

Called once the find operation is finished.

Store.first(query, fn) #

+ +
    +
  • query {Object}

  • +
  • fn(err, result) {Function}

  • +
+ +

Find the first object in the store that match the given query.

Store.update(query, changes, fn) #

+ +
    +
  • query {Object}

  • +
  • changes {Object}

  • +
  • fn(err, updated) {Function}

  • +
+ +

Update an object or objects in the store that match the given query only modifying the values in the given changes object.

Store.remove(query, fn) #

+ +
    +
  • query {Object}

  • +
  • fn(err, updated) {Function}

  • +
+ +

Remove an object or objects in the store that match the given query.

Store.rename(name, fn) #

+ +
    +
  • name {String}

  • +
  • fn(err) {Function}

  • +
+ +

Rename the store.

+ + +

More

+ + + +
+
+
+

Other docs in "Internal API Reference"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/getting-started-include=all.html b/docs/getting-started-include=all.html new file mode 100644 index 0000000..bc0d04a --- /dev/null +++ b/docs/getting-started-include=all.html @@ -0,0 +1,734 @@ + + + + + + Getting Started - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

FAQ #

Can I host Deployd on my own server? #

+ +

Yes. See the deploying to your own server guide for more info.

Can I use Deployd without the JavaScript library? (e.g. for mobile apps) #

+ +

Yes, you can use Deployd as a JSON API over HTTP.

Can I use Deployd with front-end frameworks like Backbone, AngularJS, Ember, Knockout, etc? #

+ +

Yes, Deployd is unopinionated on the front-end and you can use any libraries that you like. For frameworks that provide their own AJAX implementation (particularly Backbone), you should probably use the HTTP API rather than dpd.js in most cases. Dpd.js is still useful for realtime and user authentication, as most of those frameworks don't provide any built-in way to do this.

+ +

If you're interested, some of Deployd.com (such as the community page and the documentation's search feature) was built with AngularJS and certain parts of the Dashboard (such as the data and property editor) were built with Knockout.

Is Deployd anything like Meteor? #

+ +

Yes and no. Deployd is often compared to Meteor, since they are similar in several ways:

+ +
    +
  • They're both open source frameworks useful for building rich front-end web apps.
  • +
  • They both simplify backend or API development.
  • +
  • They both provide realtime functionality.
  • +
+ +

However, they are different in a few significant ways:

+ +
    +
  • Deployd creates APIs that can be used by web apps, mobile apps, and other web servers. Meteor, at the time of this writing, focuses exclusively on web development.
  • +
  • Deployd provides a dashboard to let you define collections and manage data. Meteor simply exposes the MongoDB API.
  • +
  • Deployd is unopinionated on the front-end, letting you use whatever libraries you're familiar with; or no libraries at all. Meteor's realtime templating system unifies back-end and front-end development, but it dictates how you write your front-end code.
  • +
+ +

Deployd and Meteor solve many of the same problems in very different ways. You should try both frameworks to see which one better meets your needs.

+ +

In the future, the two frameworks may not be mutually exclusive. Deployd focuses on data management and business logic while Meteor focuses on front-end rendering in real time; it may be possible to integrate the two for the best of both worlds.

+ + + + + + + + + +

What is Deployd? #

Deployd is a tool that makes building APIs simple by providing important ready-made functionality out of the box that meet the demands of complex applications. #

Configuration should feel like creation #

+ +

In a tool like Deployd, where its purpose is to provide ready-made functionality, a lot of configuration is necessary to make sure the end result behaves the way you need it to. We didn’t want to send users to a configuration file, though. That’s not inspiring, and it’s tedious. When you’re making an app, it should feel like you’re creating something, not just selecting values.

+ +

Some frameworks bypass this by allowing you to configure the app with code. In Deployd, you might have created your API by writing a class that inherits from a Collection base class. This is better than writing configuration files, but ultimately it leads to a lot of boilerplate code. In a Convention Over Configuration environment, when you want to use the default functionality, you write an essentially empty file. When you want to override the default functionality, you write everything from scratch.

+ +

Our solution is the Dashboard. Simply put, it’s a web-based IDE for Deployd configuration files. It’s an expressive interface that lets you create your app’s API visually.

Logic should be code #

+ +

Though we didn’t want to have our users write code for the structural setup that’s better handled in a custom interface, we realized that we can’t have users add business logic in this way. Business logic is different for every app, and we can’t account for every use case.

+ +

At the same time, we can’t force business logic out of the server-side and onto the client; that would leave your app open to attack by people who figure out your API.

+ +

We decided that there’s no better way to define logic than by writing code, so we made Deployd scriptable. By writing events, or hooks into the default functionality (such as creating objects, updating them, and querying them), you can create almost any app with any rules: validation, security, query optimizations, relationships, and more.

An API Engine #

+ +

We call Deployd an API Engine - because we think its closest relative is actually a video game engine.

+ +

A game engine assumes that every game has levels (or maps, or rooms, or scenes) which contain game objects, which need to be rendered to the screen and interact with each other. Most engines have a level editor, where you can build up these levels without any programming or code generation; when you’re finished with your level, it’s not exactly a playable game, but it works and you can walk around in a map that you built - this is the creation over configuration principle in effect.

+ +

Similarly, Deployd assumes that every API you build has collections of data objects which need to support CRUD operations, (Create, Read, Update, Delete). Collections are created in Deployd's version of a level editor called the dashboard.

+ +

Continuing with the analogy, a game engine also knows that your game will need things like collision detection and movement, but it doesn’t know exactly how you want to implement that, so it allows you to write scripts at strategic points like “on collision” or “on tick”.

+ +

How a rocket is rendered to the screen is pretty consistent for any game, but what happens when that rocket hits an enemy is always different, so you write the latter behavior as a short script, and the game engine runs it at the right time. This strategy spares you from boilerplate without taking away the power and flexibility of writing custom code.

+ +

In Deployd, the low-level, redundant parts are routing and database access, so those are built into the core and you don’t have to worry about them. Business logic, which is different for every app, is scripted in Events - hooks into the CRUD operations.

+ +

For some people, this isn’t the right approach for a final app; they prefer to have full control over the backend to tweak the performance and low-level functionality as they see fit and feel uncomfortable being limited to business logic. (Many game developers choose not to use a game engine and prefer a lower-level rendering library for virtually the same reasons) In those cases, we recommend Deployd as a prototyping tool rather than a full backend framework.

+ +

For the developers who prefer to spend their time building user interfaces, though, the scriptable engine approach is liberating.

+ + + + +

Installing Deployd #

Mac #

+ +

Download the latest OSX installer.

+ +

If everything installed correctly you should be able to open a terminal (/Applications/Utilities/Terminal.app) and type the following:

+ +
dpd -V
+
+ +

If you see something like 0.6.8 then Deployd has been successfully installed.

Troubleshooting #

"command not found" #
+ +

The terminal is not able to find the dpd program. There are a couple things you can try:

+ +
    +
  • restart the terminal app or open a new tab
  • +
  • add /usr/local/deployd/bin to your PATH (instructions)
  • +

Windows #

+ +

Download the latest Windows installer.

+ +

To verify that Deployd installed correctly, open a command prompt (Windows-R, cmd) and type dpd -V. You should see a version number such as 0.6.8.

Troubleshooting #

"'dpd' is not recognized as an internal or external command" #
+ +

Windows is unable to find the dpd command line tool. There are a couple of things you can try:

+ +
    +
  • restart the command line or open a new cmd window
  • +
  • Add the Deployd path to your PATH variable (instructions) +
    • For 64-bit systems, use the path C:\Program Files (x86)\Deployd\bin
    • +
    • For 32-bit systems, use the path C:\Program Files\Deployd\bin.
  • +
"' + +`$` is not part of the syntax for the `dpd` command; it's only used as a placeholder for the command prompt throughout the Deployd documentation. If you see something like this: + +`$ dpd create my-app` + +You only need to type `dpd create my-app`. + is not recognized as an internal or external command" #
+ +

$ is not part of the syntax for the dpd command; it's only used as a placeholder for the command prompt throughout the Deployd documentation. If you see something like this:

+ +

$ dpd create my-app

+ +

You only need to type dpd create my-app.

From NPM #

+ +

You can install Deployd as a node module using npm. Just run the following:

+ +
npm install deployd -g
+
+ +

The dpd program should be available. Try dpd -V.

From Source #

+ +

You can download the latest source here or on github.

+ +
git clone https://github.com/deployd/deployd.git
+npm install
+npm link
+

Note - When installing from NPM or Source #

+ +

You must have mongod 2.0.x and node 0.8.x installed and available in your PATH.

+ + + + +

Your first Deployd API #

+ +

If you haven't already, install Deployd.

+ +

You can create a new project by running the following commands in your terminal/command prompt (using terminal on mac / cmd on windows).

+ +
dpd create hello-world
+cd hello-world
+dpd -d
+
+ +

This will create your API, run Deployd, and open up your dashboard.

+ +

Dashboard

+ +

Create a new collection by selecting it from the Resource + dropdown. In the "Create New Collection" prompt, enter /things.

+ +

Give your 'things' collection a property of name and press enter. Note - Most screens in the dashboard have keyboard shortcuts.

+ +

Add some data to the collection by opening up the data editor. Click the "Data" menu item under "Things". With the data editor open and the new row selected, you can just start typing a name. Type "foo", then hit enter, "bat", enter, "baz", enter.

+ +

Now you should have a data editor that looks like this.

+ +

Dashboard

+ +

Click the "API" menu item to see documentation for accessing your collection. If you open up http://localhost:2403/things in a browser, you should see the following JSON:

+ +

Dashboard

+ +

Open up http://localhost:2403 in your browser and pull up your console. Try the following:

+ +
dpd.things.get(console.log);
+dpd.things.get({$limit: 1}, console.log);
+dpd.things.get({name: 'foo'}, console.log);
+
+ +

You should see something like the following:

+ +

Dashboard

More Tutorials and Examples #

+ +
+ + + + +

Building your first app with Deployd #

+ +

In this tutorial, you'll see how to create a simple app from the ground up in Deployd. This tutorial assumes a working knowledge of jQuery. It doesn't assume any knowledge of Deployd, but it's recommended to read Your First API with Deployd if you haven't already.

Getting started #

+ +

Create a new app in the command line:

+ +
$ dpd create comments
+$ cd comments
+
+ +

Using your text editor of choice, replace the default index.html file in the public folder:

+ +
<!DOCTYPE html>
+<html>
+<head>
+    <title>Deployd Tutorial</title>
+    <style type="text/css">
+        body { font-size: 16pt; }
+        .container { width: 960px; margin-left: auto; margin-right: auto; }
+        form { border: #cccccc 1px solid; padding: 20px; margin-bottom: 10px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }
+        .form-element { margin-bottom: 10px; }
+        #refresh-btn { margin-bottom: 20px; }
+        .comment { padding: 10px; margin-bottom: 10px; border-bottom: #cccccc 1px solid; }
+        .comment .links { float: right; }
+        .comment .links a { margin-left: 10px; }
+        .comment .author { font-style: italic; }
+    </style>
+</head>
+<body>
+    <div class="container">
+        <div id="comments">
+        </div>
+        <form id="comment-form">
+            <div class="form-element">
+                <label for="name">Name: </label>
+                <input type="text" id="name" name="name" />
+            </div>
+            <div class="form-element">
+                <textarea id="comment" name="comment" rows="5" cols="50">
+                </textarea>
+            </div>
+            <div class="form-element">
+                <button type="submit">Add New Comment</button>
+            </div>
+        </form>
+    </div>
+
+    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
+    <script type="text/javascript" src="script.js"></script>
+</body>
+</html>
+
+ +

Also add a file script.js and paste this code:

+ +
$(document).ready(function() {
+
+    $('#comment-form').submit(function() {
+        //Get the data from the form
+        var name = $('#name').val();
+        var comment = $('#comment').val();
+
+        //Clear the form elements
+        $('#name').val('');
+        $('#comment').val('');
+
+        addComment({
+            name: name,
+            comment: comment
+        });
+
+        return false;
+    });
+
+    function addComment(comment) {
+        $('<div class="comment">')
+            .append('<div class="author">Posted by: ' + comment.name + '</div>')
+            .append('<p>' + comment.comment + '</p>')
+            .appendTo('#comments');
+    }
+
+});
+
+ +

Run the app:

+ +
$ dpd --open
+dpd>
+
+ +

The open command will automatically open http://localhost:2403 in your browser.

+ +

App Preview

+ +

This basic app asks for a name and message body to post a comment. Take a moment to read the code and see how it works.

+ +

Next, we'll add a Deployd backend to this app, so that users can interact with each other and post comments.

Creating a backend #

+ +

Open the dashboard by typing dashboard into the dpd> prompt.

+ +
    +
  1. Create a new Collection Resource and call it /comments.
  2. +
  3. On the Properties editor, add two "string" properties called name and comment.
  4. +
  5. In the Data editor, add a couple of comments so you can start testing right away.
  6. +
+ +

That's all you have to do in the backend for now!

Integrating in the frontend #

+ +

In index.html, add the following script reference in between jQuery and script.js (near line 37):

+ +
<script type="text/javascript" src="/dpd.js"></script>
+
+ +

This will add a reference to dpd.js, a simple library dynamically built specifically for your app's backend. Dpd.js will automatically detect what resources you have added to your app and add them to the dpd object. Each resource object has asynchronous functions to communicate with your Deployd app.

+ +

In script.js, add a loadComments() function inside of $(document).ready:

+ +
function loadComments() {
+    dpd.comments.get(function(comments, error) { //Use dpd.js to access the API
+        $('#comments').empty(); //Empty the list
+        comments.forEach(function(comment) { //Loop through the result
+            addComment(comment); //Add it to the DOM.
+        });
+    });
+}
+
+ +

And call it when the page loads:

+ +
$(document).ready(function() {
+
+    loadComments();
+
+    //...
+
+});
+
+ +

If you run the app now, you should see the comments that you created in the Dashboard.

+ +

The get() function that makes this work sends an HTTP GET request to /comments, and returns an array of objects in the resource. There's nothing magical happening in dpd.js; you can use standard AJAX or HTTP requests if you prefer, or if you're unable to use dpd.js. (e.g. for mobile apps)

+ +

Note: If you haven't used AJAX much, note that all dpd.js functions are asynchronous and don't directly return a value.

+ +
//Won't work: 
+var comments = dpd.comments.get(); 
+
+ +

This means that your JavaScript will continue to execute and respond to user input while data is loading, which will make your app feel much faster to your users.

Saving data #

+ +

Notice that any comments you add through the app's form are still gone when you refresh. Let's make the form save comments to the database.

+ +

Delete these lines from script.js (near line 10, depending on where you put your loadComments() function):

+ +
//Clear the form elements
+$('#name').val('');
+$('#comment').val('');
+
+addComment({
+    name: name,
+    comment: comment
+});
+
+ +

And replace them with:

+ +
dpd.comments.post({
+        name: name,
+        comment: comment
+}, function(comment, error) {
+        if (error) return showError(error);
+
+        addComment(comment);
+        $('#name').val('');
+        $('#comment').val('');
+});
+
+ +

Add a utility function at the very top of script.js to alert any errors we get:

+ +
function showError(error) {
+        var message = "An error occurred";
+        if (error.message) {
+                message = error.message;
+        } else if (error.errors) {
+                var errors = error.errors;
+                message = "";
+                Object.keys(errors).forEach(function(k) {
+                        message += k + ": " + errors[k] + "\n";
+                });
+        }
+
+        alert(message);
+}
+
+ +

An error object can include either a message property or an errors object containing validation errors.

+ +

If you load the page now, you should be able to submit a comment that appears even after you refresh.

Conclusion #

+ +

In this tutorial, you saw how to create a simple app in Deployd. In the next part (coming soon), you'll see how to secure this app with Events.

+ +

The source code for this chapter includes a few extra features. If you're feeling adventurous, try adding them yourself:

+ +
    +
  • A refresh button that reloads the comments without refreshing the page
  • +
  • Edit and Delete links next to each comment. Hint: use the put() and del() functions from dpd.js.
  • +
+ +

Download Source

+ + + +

More

+ + + +
+
+
+

Other docs in "Docs"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/getting-started/faq.md.html b/docs/getting-started/faq.md.html new file mode 100644 index 0000000..5f600dc --- /dev/null +++ b/docs/getting-started/faq.md.html @@ -0,0 +1,360 @@ + + + + + + FAQ - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

FAQ #

Can I host Deployd on my own server? #

+ +

Yes. See the deploying to your own server guide for more info.

Can I use Deployd without the JavaScript library? (e.g. for mobile apps) #

+ +

Yes, you can use Deployd as a JSON API over HTTP.

Can I use Deployd with front-end frameworks like Backbone, AngularJS, Ember, Knockout, etc? #

+ +

Yes, Deployd is unopinionated on the front-end and you can use any libraries that you like. For frameworks that provide their own AJAX implementation (particularly Backbone), you should probably use the HTTP API rather than dpd.js in most cases. Dpd.js is still useful for realtime and user authentication, as most of those frameworks don't provide any built-in way to do this.

+ +

If you're interested, some of Deployd.com (such as the community page and the documentation's search feature) was built with AngularJS and certain parts of the Dashboard (such as the data and property editor) were built with Knockout.

Is Deployd anything like Meteor? #

+ +

Yes and no. Deployd is often compared to Meteor, since they are similar in several ways:

+ +
    +
  • They're both open source frameworks useful for building rich front-end web apps.
  • +
  • They both simplify backend or API development.
  • +
  • They both provide realtime functionality.
  • +
+ +

However, they are different in a few significant ways:

+ +
    +
  • Deployd creates APIs that can be used by web apps, mobile apps, and other web servers. Meteor, at the time of this writing, focuses exclusively on web development.
  • +
  • Deployd provides a dashboard to let you define collections and manage data. Meteor simply exposes the MongoDB API.
  • +
  • Deployd is unopinionated on the front-end, letting you use whatever libraries you're familiar with; or no libraries at all. Meteor's realtime templating system unifies back-end and front-end development, but it dictates how you write your front-end code.
  • +
+ +

Deployd and Meteor solve many of the same problems in very different ways. You should try both frameworks to see which one better meets your needs.

+ +

In the future, the two frameworks may not be mutually exclusive. Deployd focuses on data management and business logic while Meteor focuses on front-end rendering in real time; it may be possible to integrate the two for the best of both worlds.

+ + +

More

+ + + +
+
+
+

Other docs in "Getting Started"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/getting-started/installing-deployd.md.html b/docs/getting-started/installing-deployd.md.html new file mode 100644 index 0000000..2672f32 --- /dev/null +++ b/docs/getting-started/installing-deployd.md.html @@ -0,0 +1,397 @@ + + + + + + Installing Deployd - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Installing Deployd #

Mac #

+ +

Download the latest OSX installer.

+ +

If everything installed correctly you should be able to open a terminal (/Applications/Utilities/Terminal.app) and type the following:

+ +
dpd -V
+
+ +

If you see something like 0.6.8 then Deployd has been successfully installed.

Troubleshooting #

"command not found" #
+ +

The terminal is not able to find the dpd program. There are a couple things you can try:

+ +
    +
  • restart the terminal app or open a new tab
  • +
  • add /usr/local/deployd/bin to your PATH (instructions)
  • +

Windows #

+ +

Download the latest Windows installer.

+ +

To verify that Deployd installed correctly, open a command prompt (Windows-R, cmd) and type dpd -V. You should see a version number such as 0.6.8.

Troubleshooting #

"'dpd' is not recognized as an internal or external command" #
+ +

Windows is unable to find the dpd command line tool. There are a couple of things you can try:

+ +
    +
  • restart the command line or open a new cmd window
  • +
  • Add the Deployd path to your PATH variable (instructions) +
    • For 64-bit systems, use the path C:\Program Files (x86)\Deployd\bin
    • +
    • For 32-bit systems, use the path C:\Program Files\Deployd\bin.
  • +
"' + +`$` is not part of the syntax for the `dpd` command; it's only used as a placeholder for the command prompt throughout the Deployd documentation. If you see something like this: + +`$ dpd create my-app` + +You only need to type `dpd create my-app`. + is not recognized as an internal or external command" #
+ +

$ is not part of the syntax for the dpd command; it's only used as a placeholder for the command prompt throughout the Deployd documentation. If you see something like this:

+ +

$ dpd create my-app

+ +

You only need to type dpd create my-app.

From NPM #

+ +

You can install Deployd as a node module using npm. Just run the following:

+ +
npm install deployd -g
+
+ +

The dpd program should be available. Try dpd -V.

From Source #

+ +

You can download the latest source here or on github.

+ +
git clone https://github.com/deployd/deployd.git
+npm install
+npm link
+

Note - When installing from NPM or Source #

+ +

You must have mongod 2.0.x and node 0.8.x installed and available in your PATH.

+ + +

More

+ + + +
+
+
+

Other docs in "Getting Started"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/getting-started/what-is-deployd.md.html b/docs/getting-started/what-is-deployd.md.html new file mode 100644 index 0000000..72fc9cf --- /dev/null +++ b/docs/getting-started/what-is-deployd.md.html @@ -0,0 +1,360 @@ + + + + + + What is Deployd? - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

What is Deployd? #

Deployd is a tool that makes building APIs simple by providing important ready-made functionality out of the box that meet the demands of complex applications. #

Configuration should feel like creation #

+ +

In a tool like Deployd, where its purpose is to provide ready-made functionality, a lot of configuration is necessary to make sure the end result behaves the way you need it to. We didn’t want to send users to a configuration file, though. That’s not inspiring, and it’s tedious. When you’re making an app, it should feel like you’re creating something, not just selecting values.

+ +

Some frameworks bypass this by allowing you to configure the app with code. In Deployd, you might have created your API by writing a class that inherits from a Collection base class. This is better than writing configuration files, but ultimately it leads to a lot of boilerplate code. In a Convention Over Configuration environment, when you want to use the default functionality, you write an essentially empty file. When you want to override the default functionality, you write everything from scratch.

+ +

Our solution is the Dashboard. Simply put, it’s a web-based IDE for Deployd configuration files. It’s an expressive interface that lets you create your app’s API visually.

Logic should be code #

+ +

Though we didn’t want to have our users write code for the structural setup that’s better handled in a custom interface, we realized that we can’t have users add business logic in this way. Business logic is different for every app, and we can’t account for every use case.

+ +

At the same time, we can’t force business logic out of the server-side and onto the client; that would leave your app open to attack by people who figure out your API.

+ +

We decided that there’s no better way to define logic than by writing code, so we made Deployd scriptable. By writing events, or hooks into the default functionality (such as creating objects, updating them, and querying them), you can create almost any app with any rules: validation, security, query optimizations, relationships, and more.

An API Engine #

+ +

We call Deployd an API Engine - because we think its closest relative is actually a video game engine.

+ +

A game engine assumes that every game has levels (or maps, or rooms, or scenes) which contain game objects, which need to be rendered to the screen and interact with each other. Most engines have a level editor, where you can build up these levels without any programming or code generation; when you’re finished with your level, it’s not exactly a playable game, but it works and you can walk around in a map that you built - this is the creation over configuration principle in effect.

+ +

Similarly, Deployd assumes that every API you build has collections of data objects which need to support CRUD operations, (Create, Read, Update, Delete). Collections are created in Deployd's version of a level editor called the dashboard.

+ +

Continuing with the analogy, a game engine also knows that your game will need things like collision detection and movement, but it doesn’t know exactly how you want to implement that, so it allows you to write scripts at strategic points like “on collision” or “on tick”.

+ +

How a rocket is rendered to the screen is pretty consistent for any game, but what happens when that rocket hits an enemy is always different, so you write the latter behavior as a short script, and the game engine runs it at the right time. This strategy spares you from boilerplate without taking away the power and flexibility of writing custom code.

+ +

In Deployd, the low-level, redundant parts are routing and database access, so those are built into the core and you don’t have to worry about them. Business logic, which is different for every app, is scripted in Events - hooks into the CRUD operations.

+ +

For some people, this isn’t the right approach for a final app; they prefer to have full control over the backend to tweak the performance and low-level functionality as they see fit and feel uncomfortable being limited to business logic. (Many game developers choose not to use a game engine and prefer a lower-level rendering library for virtually the same reasons) In those cases, we recommend Deployd as a prototyping tool rather than a full backend framework.

+ +

For the developers who prefer to spend their time building user interfaces, though, the scriptable engine approach is liberating.

+ + +

More

+ + + +
+
+
+

Other docs in "Getting Started"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/getting-started/your-first-api.md.html b/docs/getting-started/your-first-api.md.html new file mode 100644 index 0000000..7d6cb02 --- /dev/null +++ b/docs/getting-started/your-first-api.md.html @@ -0,0 +1,374 @@ + + + + + + Your first Deployd API - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Your first Deployd API #

+ +

If you haven't already, install Deployd.

+ +

You can create a new project by running the following commands in your terminal/command prompt (using terminal on mac / cmd on windows).

+ +
dpd create hello-world
+cd hello-world
+dpd -d
+
+ +

This will create your API, run Deployd, and open up your dashboard.

+ +

Dashboard

+ +

Create a new collection by selecting it from the Resource + dropdown. In the "Create New Collection" prompt, enter /things.

+ +

Give your 'things' collection a property of name and press enter. Note - Most screens in the dashboard have keyboard shortcuts.

+ +

Add some data to the collection by opening up the data editor. Click the "Data" menu item under "Things". With the data editor open and the new row selected, you can just start typing a name. Type "foo", then hit enter, "bat", enter, "baz", enter.

+ +

Now you should have a data editor that looks like this.

+ +

Dashboard

+ +

Click the "API" menu item to see documentation for accessing your collection. If you open up http://localhost:2403/things in a browser, you should see the following JSON:

+ +

Dashboard

+ +

Open up http://localhost:2403 in your browser and pull up your console. Try the following:

+ +
dpd.things.get(console.log);
+dpd.things.get({$limit: 1}, console.log);
+dpd.things.get({name: 'foo'}, console.log);
+
+ +

You should see something like the following:

+ +

Dashboard

More Tutorials and Examples #

+ +
+ + +

More

+ + + +
+
+
+

Other docs in "Getting Started"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/getting-started/your-first-app.md.html b/docs/getting-started/your-first-app.md.html new file mode 100644 index 0000000..57f7778 --- /dev/null +++ b/docs/getting-started/your-first-app.md.html @@ -0,0 +1,541 @@ + + + + + + Your first app with Deployd - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Building your first app with Deployd #

+ +

In this tutorial, you'll see how to create a simple app from the ground up in Deployd. This tutorial assumes a working knowledge of jQuery. It doesn't assume any knowledge of Deployd, but it's recommended to read Your First API with Deployd if you haven't already.

Getting started #

+ +

Create a new app in the command line:

+ +
$ dpd create comments
+$ cd comments
+
+ +

Using your text editor of choice, replace the default index.html file in the public folder:

+ +
<!DOCTYPE html>
+<html>
+<head>
+    <title>Deployd Tutorial</title>
+    <style type="text/css">
+        body { font-size: 16pt; }
+        .container { width: 960px; margin-left: auto; margin-right: auto; }
+        form { border: #cccccc 1px solid; padding: 20px; margin-bottom: 10px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }
+        .form-element { margin-bottom: 10px; }
+        #refresh-btn { margin-bottom: 20px; }
+        .comment { padding: 10px; margin-bottom: 10px; border-bottom: #cccccc 1px solid; }
+        .comment .links { float: right; }
+        .comment .links a { margin-left: 10px; }
+        .comment .author { font-style: italic; }
+    </style>
+</head>
+<body>
+    <div class="container">
+        <div id="comments">
+        </div>
+        <form id="comment-form">
+            <div class="form-element">
+                <label for="name">Name: </label>
+                <input type="text" id="name" name="name" />
+            </div>
+            <div class="form-element">
+                <textarea id="comment" name="comment" rows="5" cols="50">
+                </textarea>
+            </div>
+            <div class="form-element">
+                <button type="submit">Add New Comment</button>
+            </div>
+        </form>
+    </div>
+
+    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
+    <script type="text/javascript" src="script.js"></script>
+</body>
+</html>
+
+ +

Also add a file script.js and paste this code:

+ +
$(document).ready(function() {
+
+    $('#comment-form').submit(function() {
+        //Get the data from the form
+        var name = $('#name').val();
+        var comment = $('#comment').val();
+
+        //Clear the form elements
+        $('#name').val('');
+        $('#comment').val('');
+
+        addComment({
+            name: name,
+            comment: comment
+        });
+
+        return false;
+    });
+
+    function addComment(comment) {
+        $('<div class="comment">')
+            .append('<div class="author">Posted by: ' + comment.name + '</div>')
+            .append('<p>' + comment.comment + '</p>')
+            .appendTo('#comments');
+    }
+
+});
+
+ +

Run the app:

+ +
$ dpd --open
+dpd>
+
+ +

The open command will automatically open http://localhost:2403 in your browser.

+ +

App Preview

+ +

This basic app asks for a name and message body to post a comment. Take a moment to read the code and see how it works.

+ +

Next, we'll add a Deployd backend to this app, so that users can interact with each other and post comments.

Creating a backend #

+ +

Open the dashboard by typing dashboard into the dpd> prompt.

+ +
    +
  1. Create a new Collection Resource and call it /comments.
  2. +
  3. On the Properties editor, add two "string" properties called name and comment.
  4. +
  5. In the Data editor, add a couple of comments so you can start testing right away.
  6. +
+ +

That's all you have to do in the backend for now!

Integrating in the frontend #

+ +

In index.html, add the following script reference in between jQuery and script.js (near line 37):

+ +
<script type="text/javascript" src="/dpd.js"></script>
+
+ +

This will add a reference to dpd.js, a simple library dynamically built specifically for your app's backend. Dpd.js will automatically detect what resources you have added to your app and add them to the dpd object. Each resource object has asynchronous functions to communicate with your Deployd app.

+ +

In script.js, add a loadComments() function inside of $(document).ready:

+ +
function loadComments() {
+    dpd.comments.get(function(comments, error) { //Use dpd.js to access the API
+        $('#comments').empty(); //Empty the list
+        comments.forEach(function(comment) { //Loop through the result
+            addComment(comment); //Add it to the DOM.
+        });
+    });
+}
+
+ +

And call it when the page loads:

+ +
$(document).ready(function() {
+
+    loadComments();
+
+    //...
+
+});
+
+ +

If you run the app now, you should see the comments that you created in the Dashboard.

+ +

The get() function that makes this work sends an HTTP GET request to /comments, and returns an array of objects in the resource. There's nothing magical happening in dpd.js; you can use standard AJAX or HTTP requests if you prefer, or if you're unable to use dpd.js. (e.g. for mobile apps)

+ +

Note: If you haven't used AJAX much, note that all dpd.js functions are asynchronous and don't directly return a value.

+ +
//Won't work: 
+var comments = dpd.comments.get(); 
+
+ +

This means that your JavaScript will continue to execute and respond to user input while data is loading, which will make your app feel much faster to your users.

Saving data #

+ +

Notice that any comments you add through the app's form are still gone when you refresh. Let's make the form save comments to the database.

+ +

Delete these lines from script.js (near line 10, depending on where you put your loadComments() function):

+ +
//Clear the form elements
+$('#name').val('');
+$('#comment').val('');
+
+addComment({
+    name: name,
+    comment: comment
+});
+
+ +

And replace them with:

+ +
dpd.comments.post({
+        name: name,
+        comment: comment
+}, function(comment, error) {
+        if (error) return showError(error);
+
+        addComment(comment);
+        $('#name').val('');
+        $('#comment').val('');
+});
+
+ +

Add a utility function at the very top of script.js to alert any errors we get:

+ +
function showError(error) {
+        var message = "An error occurred";
+        if (error.message) {
+                message = error.message;
+        } else if (error.errors) {
+                var errors = error.errors;
+                message = "";
+                Object.keys(errors).forEach(function(k) {
+                        message += k + ": " + errors[k] + "\n";
+                });
+        }
+
+        alert(message);
+}
+
+ +

An error object can include either a message property or an errors object containing validation errors.

+ +

If you load the page now, you should be able to submit a comment that appears even after you refresh.

Conclusion #

+ +

In this tutorial, you saw how to create a simple app in Deployd. In the next part (coming soon), you'll see how to secure this app with Events.

+ +

The source code for this chapter includes a few extra features. If you're feeling adventurous, try adding them yourself:

+ +
    +
  • A refresh button that reloads the comments without refreshing the page
  • +
  • Edit and Delete links next to each comment. Hint: use the put() and del() functions from dpd.js.
  • +
+ +

Download Source

+ + +

More

+ + + +
+
+
+

Other docs in "Getting Started"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/server-include=all.html b/docs/server-include=all.html new file mode 100644 index 0000000..507c2ae --- /dev/null +++ b/docs/server-include=all.html @@ -0,0 +1,491 @@ + + + + + + The Deployd Server - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Building a custom run script in Node.js #

+ +

When running in non-local environments we recommend using a simple node script to start your deployd server. With each environment using its own script, you can easily separate out environmental variables (such as connection information) and actions (such as clearing out a test database).

Example - Production #

+ +
// production.js
+var deployd = require('deployd');
+
+var server = deployd({
+  port: process.env.PORT || 5000,
+  env: 'production',
+  db: {
+    host: 'my.production.mongo.host',
+    port: 27105,
+    name: 'my-db',
+    credentials: {
+      username: 'username',
+      password: 'password'
+    }
+  }
+});
+
+server.listen();
+
+server.on('listening', function() {
+  console.log("Server is listening");
+});
+
+server.on('error', function(err) {
+  console.error(err);
+  process.nextTick(function() { // Give the server a chance to return an error
+    process.exit();
+  });
+});
+

Example - Staging #

+ +
// staging.js
+var deployd = require('deployd');
+
+var server = deployd({
+  port: process.env.PORT || 5000,
+  env: 'staging',
+  db: {
+    host: 'my.production.mongo.host',
+    port: 27105,
+    name: 'my-db',
+    credentials: {
+      username: 'username',
+      password: 'password'
+    }
+  }
+});
+
+// remove all data in the 'todos' collection
+var todos = server.createStore('todos');
+
+todos.remove(function() {
+  // all todos removed
+  server.listen();
+});
+
+server.on('error', function(err) {
+  console.error(err);
+  process.nextTick(function() { // Give the server a chance to return an error
+    process.exit();
+  });
+});
+

Running Your App in Production #

+ +

To run your app as a daemon, use the forever module. You can install it from npm.

+ +
npm install forever -g
+
+ +

Then start the appropriate run script based on your environment.

+ +
forever start production.js
+
+ +

This will daemonize your app and make sure it runs even if it crashes.

+ + + + +

Deploying to your own Server #

+ +

To deploy your app on your server, or on a cloud hosting service such as EC2 or Heroku, the server must support Node.js.

+ +

Deployd also requires a MongoDB database, which can be hosted on the same server or externally.

+ +

If you have root shell access on the deployment server, you can install Deployd on it using the command npm install -g deployd. +Otherwise, you will need to install Deployd as a dependency of your app itself using npm install deployd in the root directory of your app.

+ +

You can use the dpd CLI to run your server; this will start up an instance of MongoDB automatically, using the "data" folder. (Requires MongoDB installed on the server)

Dashboard Access #

+ +

To set up the dashboard on your server, type dpd keygen on your server's command line to create a remote access key. Type dpd showkey to get the key; you should store this somewhere secure.

+ +

You can then go to the /dashboard route on the server and type in that key to gain access.

Server Script #

+ +

Since Deployd is itself a node module, you can write your own scripts to run in production instead of using the command line interface. Read the Building a Custom Run Script Guide.

+ +

Note: Some hosts do not support WebSockets, so dpd.on() may not work correctly on certain deployments.

+ + + + + + + + + +

Using Deployd as a Node.js Module #

+ +

Deployd is a node module and can be used inside other node programs or as the basis of an entire node program.

Installing #

+ +

For an app in your current directory:

+ +
npm install deployd
+
+ +

You can also install globally:

+ +
npm install deployd -g
+

Hello World #

+ +

Here is a simple hello world using Deployd as a node module.

+ +
// hello.js
+var deployd = require('deployd')
+  , options = {port: 3000};
+
+var dpd = deployd(options);
+
+dpd.listen();
+
+ +

Run this like any other node program.

+ +
node hello.js
+

Server Options #

+ +
    +
  • port {Number} - the port to listen on
  • +
  • db {Object} - the database to connect to +
    • db.port {Number} - the port of the database server
    • +
    • db.host {String} - the ip or domain of the database server
    • +
    • db.name {String} - the name of the database
    • +
    • db.credentials {Object} - credentials for db
    • +
    • db.credentials.username {String}
    • +
    • db.credentials.password {String}
  • +
  • env {String} - the environment to run in.
  • +
+ +

Note: If options.env is "development", the dashboard will not require authentication and configuration will not be cached. Make sure to change this to "production" or something similar when deploying.

Caveats #

+ +
    +
  • Deployd mounts its server on process.server. This means you can only run one Deployd server in a process.
  • +
  • Deployd loads resources from the process.cwd. Add this to ensure you are in the right directory: process.chdir(__dirname).
  • +
  • In order to access the /dashboard without a key you must run Deployd with the env option set to development.
  • +
+ + + +

More

+ + + +
+
+
+

Other docs in "Docs"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/server/as-a-node-module.md.html b/docs/server/as-a-node-module.md.html new file mode 100644 index 0000000..93d7f30 --- /dev/null +++ b/docs/server/as-a-node-module.md.html @@ -0,0 +1,372 @@ + + + + + + Using Deployd as a Node.js Module - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Using Deployd as a Node.js Module #

+ +

Deployd is a node module and can be used inside other node programs or as the basis of an entire node program.

Installing #

+ +

For an app in your current directory:

+ +
npm install deployd
+
+ +

You can also install globally:

+ +
npm install deployd -g
+

Hello World #

+ +

Here is a simple hello world using Deployd as a node module.

+ +
// hello.js
+var deployd = require('deployd')
+  , options = {port: 3000};
+
+var dpd = deployd(options);
+
+dpd.listen();
+
+ +

Run this like any other node program.

+ +
node hello.js
+

Server Options #

+ +
    +
  • port {Number} - the port to listen on
  • +
  • db {Object} - the database to connect to +
    • db.port {Number} - the port of the database server
    • +
    • db.host {String} - the ip or domain of the database server
    • +
    • db.name {String} - the name of the database
    • +
    • db.credentials {Object} - credentials for db
    • +
    • db.credentials.username {String}
    • +
    • db.credentials.password {String}
  • +
  • env {String} - the environment to run in.
  • +
+ +

Note: If options.env is "development", the dashboard will not require authentication and configuration will not be cached. Make sure to change this to "production" or something similar when deploying.

Caveats #

+ +
    +
  • Deployd mounts its server on process.server. This means you can only run one Deployd server in a process.
  • +
  • Deployd loads resources from the process.cwd. Add this to ensure you are in the right directory: process.chdir(__dirname).
  • +
  • In order to access the /dashboard without a key you must run Deployd with the env option set to development.
  • +
+ + +

More

+ + + +
+
+
+

Other docs in "The Deployd Server"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/server/run-script.md.html b/docs/server/run-script.md.html new file mode 100644 index 0000000..b162552 --- /dev/null +++ b/docs/server/run-script.md.html @@ -0,0 +1,402 @@ + + + + + + Building a custom run script in Node.js - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Building a custom run script in Node.js #

+ +

When running in non-local environments we recommend using a simple node script to start your deployd server. With each environment using its own script, you can easily separate out environmental variables (such as connection information) and actions (such as clearing out a test database).

Example - Production #

+ +
// production.js
+var deployd = require('deployd');
+
+var server = deployd({
+  port: process.env.PORT || 5000,
+  env: 'production',
+  db: {
+    host: 'my.production.mongo.host',
+    port: 27105,
+    name: 'my-db',
+    credentials: {
+      username: 'username',
+      password: 'password'
+    }
+  }
+});
+
+server.listen();
+
+server.on('listening', function() {
+  console.log("Server is listening");
+});
+
+server.on('error', function(err) {
+  console.error(err);
+  process.nextTick(function() { // Give the server a chance to return an error
+    process.exit();
+  });
+});
+

Example - Staging #

+ +
// staging.js
+var deployd = require('deployd');
+
+var server = deployd({
+  port: process.env.PORT || 5000,
+  env: 'staging',
+  db: {
+    host: 'my.production.mongo.host',
+    port: 27105,
+    name: 'my-db',
+    credentials: {
+      username: 'username',
+      password: 'password'
+    }
+  }
+});
+
+// remove all data in the 'todos' collection
+var todos = server.createStore('todos');
+
+todos.remove(function() {
+  // all todos removed
+  server.listen();
+});
+
+server.on('error', function(err) {
+  console.error(err);
+  process.nextTick(function() { // Give the server a chance to return an error
+    process.exit();
+  });
+});
+

Running Your App in Production #

+ +

To run your app as a daemon, use the forever module. You can install it from npm.

+ +
npm install forever -g
+
+ +

Then start the appropriate run script based on your environment.

+ +
forever start production.js
+
+ +

This will daemonize your app and make sure it runs even if it crashes.

+ + +

More

+ + + +
+
+
+

Other docs in "The Deployd Server"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/server/your-server.md.html b/docs/server/your-server.md.html new file mode 100644 index 0000000..05bcf4c --- /dev/null +++ b/docs/server/your-server.md.html @@ -0,0 +1,341 @@ + + + + + + Deploying to your own Server - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Deploying to your own Server #

+ +

To deploy your app on your server, or on a cloud hosting service such as EC2 or Heroku, the server must support Node.js.

+ +

Deployd also requires a MongoDB database, which can be hosted on the same server or externally.

+ +

If you have root shell access on the deployment server, you can install Deployd on it using the command npm install -g deployd. +Otherwise, you will need to install Deployd as a dependency of your app itself using npm install deployd in the root directory of your app.

+ +

You can use the dpd CLI to run your server; this will start up an instance of MongoDB automatically, using the "data" folder. (Requires MongoDB installed on the server)

Dashboard Access #

+ +

To set up the dashboard on your server, type dpd keygen on your server's command line to create a remote access key. Type dpd showkey to get the key; you should store this somewhere secure.

+ +

You can then go to the /dashboard route on the server and type in that key to gain access.

Server Script #

+ +

Since Deployd is itself a node module, you can write your own scripts to run in production instead of using the command line interface. Read the Building a Custom Run Script Guide.

+ +

Note: Some hosts do not support WebSockets, so dpd.on() may not work correctly on certain deployments.

+ + +

More

+ + + +
+
+
+

Other docs in "The Deployd Server"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/users-include=all.html b/docs/users-include=all.html new file mode 100644 index 0000000..a780f4c --- /dev/null +++ b/docs/users-include=all.html @@ -0,0 +1,607 @@ + + + + + + Users - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Creating User Collections #

User Collection #

+ +

A User Collection extends a Collection, adding the functionality needed to authenticate users with your app. You can create one by choosing "User Collection" when adding a Resource.

Properties #

+ +

User Collections can have the same properties as a Collection, with two additional non-removable properties:

+ +
    +
  • username - The user's identifier; must be unique.
  • +
  • password - An encrypted password. It can never be retrieved from the database, only queried against.
  • +
+ +

In addition to the above constraints, these two properties can only be modified by:

+ +
    +
  • A session authenticated as that user
  • +
  • An internal request, such as a call from an event.
  • +
  • A root request
  • +
+ + + + +

Authenticating Users #

+ +

A User Collection can be accessed in the same ways as a Collection, both with dpd.js and HTTP. It also adds new methods to the API for authentication.

+ +

The examples below use a User Collection called /users with the following schema:

+ +
    +
  • id
  • +
  • username
  • +
  • password
  • +
  • string displayName
  • +

Logging in #

+ +

Log in a user with their username and password. If successful, the browser will save a secure cookie for their session. This request responds with the session details:

+ +
{
+  "id": "s0446b993caaad577a..." //Session id
+  "path": "/users" // The path of the User Collection - useful if you have different types of users.
+  "uid": "ec54ad870eaca95f" //The id of the user
+}
+
+ +

If the username or password is incorrect, Deployd will respond with a generic error:

+ +
{
+  "status": 401,
+  "message: "bad credentials"
+}
+
+ +

For security reasons, users should not be informed which of their credentials (username, password, or both) were incorrect.

dpd.js #

+ +

To authenticate a user, use the .login(credentials, fn) function, including the username and password properties in the request body.

+ +
dpd.users.login({
+  username: "johnsmith",
+  password: "password"
+}, function(result, error) {
+  // Do something
+});
+
+ +

You can also use the .exec('login', credentials, fn) function. This is useful if you have accessed the collection by using dpd() as a function and the login() function is unavailable.

+ +
dpd('users').exec('login', {
+  username: "johnsmith",
+  password: "password"
+}, function(result, error) {
+  // Do something
+});
+

HTTP #

+ +

To authenticate a user, send a POST request to /login with username and password properties in the request body.

+ +
POST /users/login
+{
+  "username": "johnsmith",
+  "password": "password"
+}
+

Logging out #

+ +

Logging out will remove the session cookie on the browser and destroy the current session. It does not return a result.

dpd.js #

+ +

To log out a user, use the .logout(fn) function.

+ +
dpd.users.logout(function(result, error) {
+  // Do something
+});
+
+ +

result will always be null.

+ +

You can also use the .exec('logout', fn) function. This is useful if you have accessed the collection by using dpd() as a function and the logout() function is unavailable.

+ +
dpd('users').exec('logout', function(result, error) {
+  // Do something
+});
+

HTTP #

+ +

To log out a user, send a POST request to /logout. Include the sid cookie to identify your session.

+ +
POST /users/logout
+Cookie: sid=6009c5b070d834a2d336224a93...
+
+ +

The response body will always be empty unless there was an error.

Getting the current user #

+ +

This will return the current user.

+ +
{
+  "id": "2975ff2778493818",
+  "username": "johnsmith",
+  "displayName": "John Smith"
+}
+
+ +

If there is no current user, it will not return a value.

dpd.js #

+ +

To get the current user, use the .me(fn) function.

+ +
dpd.users.me(function(result, error) {
+  // Do something
+});
+
+ +

If there is no current user, result will be null.

+ +

You can also use the .get('me', fn) function. This is useful if you have accessed the collection by using dpd() as a function and the me() function is unavailable.

+ +
dpd('users').get('me', function(result, error) {
+  // Do something
+});
+

HTTP #

+ +

To get the current user, send a GET request to /me. Include the sid cookie to identify your session.

+ +
GET /users/me 
+Cookie: sid=6009c5b070d834a2d336224a93...
+
+ +

If there is no current user, the response body will be blank:

+ +
204 No Content
+
+ + + + +

Working with Sessions #

Background #

+ +

Since HTTP is a stateless protocol, a mechanism is required to tie independent requests and connections to a single remote session. In Deployd, sessions are maintained by signing each request with a session id. Currently the only mechanism for signing requests is HTTP cookies.

+ +

If a request does not contain a sid cookie with an existing session id, a session will be created and set as a cookie on the response.

Sockets #

+ +

WebSocket connections are identified and attached to sessions by the cookies sent during the upgrade request of a websocket.

API #

+ +

As of v0.6 the sessions API is very limited. In upcoming versions the API will include the following:

+ +
    +
  • create sessions from modules
  • +
  • get sockets by session or user id
  • +
  • store arbitrary info on sessions
  • +
  • query sessions
  • +
  • remote session api
  • +
  • query sessions by machine ip
  • +
  • emit to sessions
  • +
+ + + + +

Microblogging app #

+ +

This app demonstrates how to create a microblogging app (similar to Twitter) using User Collections. It also demonstrates how to use dpd.js with AngularJS on the front-end.

+ +

The app supports registering, logging in, making posts, and mentioning other users in posts with their @username.

+ +

Download View Source

Useful files #

+ +

Events:

+ + + +

Front-end:

+ +

Simple Login Form #

+ +

This app demonstrates how to use the "login", "logout", and "me" functions on a User Collection.

+ +

Download View Source

Useful files #

+ +
+ + + + +

Accessing Users in Events with "me" #

+ +

In any Collection Event, the me object refers to the current user. You can use this to secure your app and protect your users. This page lists a few examples of how to use the me object effectively.

Keeping track of an object's creator #

+ +
// On Post /todo-lists
+cancelUnless(me, "You must be logged in to create a todo list", 401);
+
+this.creatorId = me.id;
+

Securing an object #

+ +

You can ensure that only the creator of an object can update it:

+ +
// On Put /todos
+if (!(me && me.id === this.creatorId)) {
+  cancel("This is not your todo", 401);
+}
+

Checking for roles #

+ +

If you store an array of roles on your User Collection, you can use that to verify that the current user can perform an action:

+ +
// On POST /blog-posts
+if (!(me && me.roles.indexOf("author") !== -1)) {
+  cancel("You must be an author to create a blog post", 401);
+}
+

Awarding the user points #

+ +

In a gamification setup, you might want to award the user some points for creating an object:

+ +
// On POST /answers
+if (me) {
+  dpd.users.put(me.id, {
+    points: {$inc: 1}
+  }, function() {});
+}
+
+// On PUT /users
+// External APIs should not be able to edit the point value
+if (!internal) {
+  protect('points');
+}
+
+ + + + + + + + +

More

+ + + +
+
+
+

Other docs in "Docs"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/users/advanced-guides-include=all.html b/docs/users/advanced-guides-include=all.html new file mode 100644 index 0000000..e554b75 --- /dev/null +++ b/docs/users/advanced-guides-include=all.html @@ -0,0 +1,358 @@ + + + + + + Advanced Guides - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Working with Sessions #

Background #

+ +

Since HTTP is a stateless protocol, a mechanism is required to tie independent requests and connections to a single remote session. In Deployd, sessions are maintained by signing each request with a session id. Currently the only mechanism for signing requests is HTTP cookies.

+ +

If a request does not contain a sid cookie with an existing session id, a session will be created and set as a cookie on the response.

Sockets #

+ +

WebSocket connections are identified and attached to sessions by the cookies sent during the upgrade request of a websocket.

API #

+ +

As of v0.6 the sessions API is very limited. In upcoming versions the API will include the following:

+ +
    +
  • create sessions from modules
  • +
  • get sockets by session or user id
  • +
  • store arbitrary info on sessions
  • +
  • query sessions
  • +
  • remote session api
  • +
  • query sessions by machine ip
  • +
  • emit to sessions
  • +
+ + + +

More

+ + + +
+
+
+

Other docs in "Users"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/users/advanced-guides/understanding-sessions.md.html b/docs/users/advanced-guides/understanding-sessions.md.html new file mode 100644 index 0000000..71496c4 --- /dev/null +++ b/docs/users/advanced-guides/understanding-sessions.md.html @@ -0,0 +1,349 @@ + + + + + + Working with Sessions - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Working with Sessions #

Background #

+ +

Since HTTP is a stateless protocol, a mechanism is required to tie independent requests and connections to a single remote session. In Deployd, sessions are maintained by signing each request with a session id. Currently the only mechanism for signing requests is HTTP cookies.

+ +

If a request does not contain a sid cookie with an existing session id, a session will be created and set as a cookie on the response.

Sockets #

+ +

WebSocket connections are identified and attached to sessions by the cookies sent during the upgrade request of a websocket.

API #

+ +

As of v0.6 the sessions API is very limited. In upcoming versions the API will include the following:

+ +
    +
  • create sessions from modules
  • +
  • get sockets by session or user id
  • +
  • store arbitrary info on sessions
  • +
  • query sessions
  • +
  • remote session api
  • +
  • query sessions by machine ip
  • +
  • emit to sessions
  • +
+ + +

More

+ + + +
+
+
+

Other docs in "Advanced Guides"

+
    + +
+
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/users/authenticating-users.md.html b/docs/users/authenticating-users.md.html new file mode 100644 index 0000000..0a1d36f --- /dev/null +++ b/docs/users/authenticating-users.md.html @@ -0,0 +1,472 @@ + + + + + + Authenticating Users - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Authenticating Users #

+ +

A User Collection can be accessed in the same ways as a Collection, both with dpd.js and HTTP. It also adds new methods to the API for authentication.

+ +

The examples below use a User Collection called /users with the following schema:

+ +
    +
  • id
  • +
  • username
  • +
  • password
  • +
  • string displayName
  • +

Logging in #

+ +

Log in a user with their username and password. If successful, the browser will save a secure cookie for their session. This request responds with the session details:

+ +
{
+  "id": "s0446b993caaad577a..." //Session id
+  "path": "/users" // The path of the User Collection - useful if you have different types of users.
+  "uid": "ec54ad870eaca95f" //The id of the user
+}
+
+ +

If the username or password is incorrect, Deployd will respond with a generic error:

+ +
{
+  "status": 401,
+  "message: "bad credentials"
+}
+
+ +

For security reasons, users should not be informed which of their credentials (username, password, or both) were incorrect.

dpd.js #

+ +

To authenticate a user, use the .login(credentials, fn) function, including the username and password properties in the request body.

+ +
dpd.users.login({
+  username: "johnsmith",
+  password: "password"
+}, function(result, error) {
+  // Do something
+});
+
+ +

You can also use the .exec('login', credentials, fn) function. This is useful if you have accessed the collection by using dpd() as a function and the login() function is unavailable.

+ +
dpd('users').exec('login', {
+  username: "johnsmith",
+  password: "password"
+}, function(result, error) {
+  // Do something
+});
+

HTTP #

+ +

To authenticate a user, send a POST request to /login with username and password properties in the request body.

+ +
POST /users/login
+{
+  "username": "johnsmith",
+  "password": "password"
+}
+

Logging out #

+ +

Logging out will remove the session cookie on the browser and destroy the current session. It does not return a result.

dpd.js #

+ +

To log out a user, use the .logout(fn) function.

+ +
dpd.users.logout(function(result, error) {
+  // Do something
+});
+
+ +

result will always be null.

+ +

You can also use the .exec('logout', fn) function. This is useful if you have accessed the collection by using dpd() as a function and the logout() function is unavailable.

+ +
dpd('users').exec('logout', function(result, error) {
+  // Do something
+});
+

HTTP #

+ +

To log out a user, send a POST request to /logout. Include the sid cookie to identify your session.

+ +
POST /users/logout
+Cookie: sid=6009c5b070d834a2d336224a93...
+
+ +

The response body will always be empty unless there was an error.

Getting the current user #

+ +

This will return the current user.

+ +
{
+  "id": "2975ff2778493818",
+  "username": "johnsmith",
+  "displayName": "John Smith"
+}
+
+ +

If there is no current user, it will not return a value.

dpd.js #

+ +

To get the current user, use the .me(fn) function.

+ +
dpd.users.me(function(result, error) {
+  // Do something
+});
+
+ +

If there is no current user, result will be null.

+ +

You can also use the .get('me', fn) function. This is useful if you have accessed the collection by using dpd() as a function and the me() function is unavailable.

+ +
dpd('users').get('me', function(result, error) {
+  // Do something
+});
+

HTTP #

+ +

To get the current user, send a GET request to /me. Include the sid cookie to identify your session.

+ +
GET /users/me 
+Cookie: sid=6009c5b070d834a2d336224a93...
+
+ +

If there is no current user, the response body will be blank:

+ +
204 No Content
+
+ + +

More

+ + + +
+
+
+

Other docs in "Users"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/users/creating-user-collections.md.html b/docs/users/creating-user-collections.md.html new file mode 100644 index 0000000..06ce313 --- /dev/null +++ b/docs/users/creating-user-collections.md.html @@ -0,0 +1,366 @@ + + + + + + Creating User Collections - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Creating User Collections #

User Collection #

+ +

A User Collection extends a Collection, adding the functionality needed to authenticate users with your app. You can create one by choosing "User Collection" when adding a Resource.

Properties #

+ +

User Collections can have the same properties as a Collection, with two additional non-removable properties:

+ +
    +
  • username - The user's identifier; must be unique.
  • +
  • password - An encrypted password. It can never be retrieved from the database, only queried against.
  • +
+ +

In addition to the above constraints, these two properties can only be modified by:

+ +
    +
  • A session authenticated as that user
  • +
  • An internal request, such as a call from an event.
  • +
  • A root request
  • +
+ + +

More

+ + + +
+
+
+

Other docs in "Users"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/users/examples-include=all.html b/docs/users/examples-include=all.html new file mode 100644 index 0000000..4fe32bb --- /dev/null +++ b/docs/users/examples-include=all.html @@ -0,0 +1,377 @@ + + + + + + Examples - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Microblogging app #

+ +

This app demonstrates how to create a microblogging app (similar to Twitter) using User Collections. It also demonstrates how to use dpd.js with AngularJS on the front-end.

+ +

The app supports registering, logging in, making posts, and mentioning other users in posts with their @username.

+ +

Download View Source

Useful files #

+ +

Events:

+ + + +

Front-end:

+ +
+ + + + +

Simple Login Form #

+ +

This app demonstrates how to use the "login", "logout", and "me" functions on a User Collection.

+ +

Download View Source

Useful files #

+ +
+ + + +

More

+ + + +
+
+ +
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/users/examples/microblogging.md.html b/docs/users/examples/microblogging.md.html new file mode 100644 index 0000000..b1da596 --- /dev/null +++ b/docs/users/examples/microblogging.md.html @@ -0,0 +1,353 @@ + + + + + + Microblogging app - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Microblogging app #

+ +

This app demonstrates how to create a microblogging app (similar to Twitter) using User Collections. It also demonstrates how to use dpd.js with AngularJS on the front-end.

+ +

The app supports registering, logging in, making posts, and mentioning other users in posts with their @username.

+ +

Download View Source

Useful files #

+ +

Events:

+ + + +

Front-end:

+ +
+ + +

More

+ + + +
+
+
+

Other docs in "Examples"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/users/examples/simple-login.md.html b/docs/users/examples/simple-login.md.html new file mode 100644 index 0000000..a7a0ad4 --- /dev/null +++ b/docs/users/examples/simple-login.md.html @@ -0,0 +1,343 @@ + + + + + + Simple Login Form - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Simple Login Form #

+ +

This app demonstrates how to use the "login", "logout", and "me" functions on a User Collection.

+ +

Download View Source

Useful files #

+ +
+ + +

More

+ + + +
+
+
+

Other docs in "Examples"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/users/users-in-events.md.html b/docs/users/users-in-events.md.html new file mode 100644 index 0000000..3fcfa02 --- /dev/null +++ b/docs/users/users-in-events.md.html @@ -0,0 +1,389 @@ + + + + + + Accessing Users in Events - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Accessing Users in Events with "me" #

+ +

In any Collection Event, the me object refers to the current user. You can use this to secure your app and protect your users. This page lists a few examples of how to use the me object effectively.

Keeping track of an object's creator #

+ +
// On Post /todo-lists
+cancelUnless(me, "You must be logged in to create a todo list", 401);
+
+this.creatorId = me.id;
+

Securing an object #

+ +

You can ensure that only the creator of an object can update it:

+ +
// On Put /todos
+if (!(me && me.id === this.creatorId)) {
+  cancel("This is not your todo", 401);
+}
+

Checking for roles #

+ +

If you store an array of roles on your User Collection, you can use that to verify that the current user can perform an action:

+ +
// On POST /blog-posts
+if (!(me && me.roles.indexOf("author") !== -1)) {
+  cancel("You must be an author to create a blog post", 401);
+}
+

Awarding the user points #

+ +

In a gamification setup, you might want to award the user some points for creating an object:

+ +
// On POST /answers
+if (me) {
+  dpd.users.put(me.id, {
+    points: {$inc: 1}
+  }, function() {});
+}
+
+// On PUT /users
+// External APIs should not be able to edit the point value
+if (!internal) {
+  protect('points');
+}
+
+ + +

More

+ + + +
+
+
+

Other docs in "Users"

+ +
+
+ +
+
+

Related Examples

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules-include=all.html b/docs/using-modules-include=all.html new file mode 100644 index 0000000..450fd30 --- /dev/null +++ b/docs/using-modules-include=all.html @@ -0,0 +1,841 @@ + + + + + + Using Modules - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + + + + + + +

Installing a Module #

From NPM #

+ +

Deployd modules are 100% compatible with node modules. This means you can install a module with npm from your project's root directory.

+ +
cd my-dpd-project
+mkdir -p node_modules
+npm install my-dpd-module
+
+ +

To find deployd modules available on npm search for dpd.

+ +

If you used the Deployd installer, you will need to download node.js in order to use npm.

From Source #

+ +

You can also install a module from source by putting it in your project's node_modules folder. Even a single file is valid (eg: /node_modules/foo.js).

+ + + + +

Dpd.js for Custom Resources #

+ +

Because Custom Resource Types can specify APIs very different from a Collection, Dpd.js acts as a generic HTTP library for Custom Resources.

Accessing the Resource #

+ +

The API for your Resource is automatically generated as dpd.[resource].

+ +

Examples:

+ +
dpd.emails
+dpd.addfollower
+dpd.uploads
+
+ +

Note: If your Resource name has a dash in it (e.g. /add-follower), the dash is removed when accessing it in this way (e.g. dpd.addfollower).

+ +

You can also access your resource by using dpd(resourceName) as a function.

+ +

Examples:

+ +
dpd('emails')
+dpd('add-follower')
+dpd('uploads')
+

Callbacks #

+ +

Every function in the Dpd.js API takes a callback function (represented by fn in the docs) with the signature function(result, error).

+ +

The callback will be executed asynchronously when the API has received a response from the server.

+ +

The result argument differs depending on the function. If the result failed, it will be null and the error argument will contain the error message.

+ +

The error argument, if there was an error, is an object:

+ +
    +
  • status (number): The HTTP status code of the request. Common codes include: +
    • 400 - Bad Request: The request contained invalid data and could not be completed
    • +
    • 401 - Unauthorized: The current session is not authorized to perform that action
    • +
    • 500 - Internal Server Error: Something went wrong on the server
  • +
  • message (string): A message describing the error. Not always present.
  • +
  • errors (object): A hash of error messages corresponding to the properties of the object that was sent - usually indicates validation errors. Not always present.
  • +
+ +

Examples of errors:

+ +
{
+    "status": 401,
+    "message": "You are not allowed to access that resource!"
+}
+
+ + + +
{
+    "status": 400,
+    "errors": {
+        "title": "Title must be less than 100 characters",
+        "category": "Not a valid category"
+    }
+}
+

get() #

+ +
dpd.[resource].get([func], [path], [query], fn)
+
+ +

Makes a GET HTTP request at the URL /<resource>/<func>/<path>, using the query object as the query string if provided.

+ +
    +
  • func - A special identifier, i.e. /me.
  • +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON.
  • +
  • fn - Callback function(result, error).
  • +

post() #

+ +
dpd.[resource].post([path], [query], body, fn)
+
+ +

Makes a POST HTTP request at the URL /<resource>/<path>, using the query object as the query string if provided and body as the request body.

+ +
    +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON.
  • +
  • body - The body of the request; will be serialized as JSON and sent with Content-Type: application/json header.
  • +
  • fn - Callback function(result, error).
  • +

put() #

+ +
dpd.[resource].put([path], [query], body, fn)
+
+ +

Makes a PUT HTTP request at the URL /<resource>/<path>, using the query object as the query string if provided and body as the request body.

+ +
    +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON and passed as the q parameter.
  • +
  • body - The body of the request; will be serialized as JSON and sent with Content-Type: application/json header.
  • +
  • fn - Callback function(result, error).
  • +

del() #

+ +
dpd.[resource].del([path], [query], fn)
+
+ +

Makes a DELETE HTTP request at the URL /<resource>/<path>, using the query object as the query string if provided.

+ +
    +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON and passed as the q parameter.
  • +
  • fn - Callback function(result, error).
  • +

exec() #

+ +
dpd.[resource].exec(func, [path], [body], fn)
+
+ +

Makes an RPC-style POST HTTP request at the URL /<resource>/<func>/<path>. Useful for functions that don't make sense in REST-style APIs, such as /users/login.

+ +
    +
  • func - The name of the function to call
  • +
  • path - An identifier for a particular object, usually the id
  • +
  • body - The body of the request; will be serialized as JSON and sent with Content-Type: application/json header.
  • +
  • fn - Callback function(result, error).
  • +

Realtime API #

+ +

The Generic Realtime API behaves the same way as the Collection Realtime API.

Event API for Custom Resources #

Background #

+ +

Custom Resources may load event scripts to allow you to inject business logic during requests to the resource. For example, the collection resource exposes an event called validate. Given the following todo resource folder:

+ +
/my-app
+  /resources
+    /todos
+      validate.js
+
+ +

The collection resource would load the contents of validate.js as the validate event.

Default Event Script Domain #

+ +

Event scripts do not share a global scope with other modules in your app. Instead each time an event script is run, a new scope is created for it.

+ +

The following functions and objects are available to all event scripts.

me #

+ +

The current user if one exists on the current Context.

isMe() #

+ +
isMe(id)
+
+ +

Returns true if the current user (me) matches the provided id.

this #

+ +

If the resource does not implement a custom domain, this will be an empty object. Otherwise this usually refers to the current domain's instance (eg. an object in a collection).

cancel() #

+ +
cancel(message, [statusCode])
+
+ +

Stops the current request with the provided error message and HTTP status code. Status code defaults to 400.

cancelIf(), cancelUnless() #

+ +
cancelIf(condition, message, [statusCode])
+cancelUnless(condition, message, [statusCode])
+
+ +

Calls cancel(message, statusCode) if the provided condition is truthy (for cancelIf()) or falsy (for cancelUnless).

internal #

+ +

A boolean property, true if this request has been initiated by another script.

isRoot #

+ +

A boolean property, true if this request is authenticated as root (from the dashboard or a custom script).

query #

+ +

The current HTTP query. (eg ?foo=bar - query would be {foo: 'bar'}).

emit() #

+ +
emit([userCollection, query], message, [data])
+
+ +

Emits a realtime message to the client. You can use userCollection and query parameters to limit the message broadcast to specific users.

console #

+ +

Support for console.log() and other console methods.

+ + + + +

Email Resource #

+ +

This custom resource type allows you to send an email to your users.

+ +

The Email resource is built on the Nodemailer module for Node.js; much of the documentation on this page is taken from their README.

Installation #

+ +

In your app's root directory, type npm install dpd-email into the command line or download from source. This should create a dpd-email directory in your app's node_modules directory.

+ +

See Installing Modules for details.

Configuration #

+ +

Before using the email resource, you must go to its Dashboard page and configure it.

+ +

These settings are required:

+ +
    +
  • host: The hostname of your SMTP provider.
  • +
  • port: The port number of your SMTP provider. Defaults to 25; 587 is also common.
  • +
  • ssl: If checked, use SSL to communicate with your SMTP provider. Unneeded for port 587; as it will automatically upgrade to a secure connection.
  • +
  • username: The SMTP username for your app.
  • +
  • password: The SMTP username for your app.
  • +
+ +

These settings are optional:

+ +
    +
  • defaultFromAddress: A "from" email address to provide by default. If this is not provided, you will need to provide this address in every request.
  • +
  • internalOnly: If checked, only allow internal requests (such as those from events) to send emails. Recommended for security.
  • +
  • productionOnly: If checked, attempting to send an email in the development environment will simply print it to the Deployd console.
  • +

Usage #

+ +

To send an email, call dpd.email.post(options, callback) (replacing email with your resource name). The options argument is an object:

+ +
    +
  • from: The email address of the sender. Required if defaultFromAddress is not configured. All e-mail addresses can be plain (sender@server.com) or formatted (Sender Name <sender@server.com>)
  • +
  • to: Comma separated list of recipients e-mail addresses that will appear on the To: field
  • +
  • cc: Comma separated list of recipients e-mail addresses that will appear on the Cc: field
  • +
  • bcc: Comma separated list of recipients e-mail addresses that will appear on the Bcc: field
  • +
  • subject: The subject of the e-mail.
  • +
  • text: The plaintext version of the message
  • +
  • html: The HTML version of the message
  • +

Example Usage #

+ +
// On POST /users
+
+dpd.email.post({
+  to: this.email,
+  from: "deployd-server@example.com", 
+  subject: "MyApp registration",
+  text: this.username + ",\n\n" +
+        "Thank you for registering for MyApp!"
+}, function() {});
+

Event Resource #

+ +

This custom resource type allows you to write an event that will run when the resource's route receives a GET or POST request.

Installation #

+ +

In your app's root directory, type npm install dpd-event into the command line or download the source. This should create a dpd-event directory in your app's node_modules directory.

+ +

See Installing Modules for details.

Usage #

+ +

The On POST event will be executed when the resource's route (or a subroute) receives a POST request, and likewise with the On GET event.

+ +

It is strongly recommended that you reserve the On GET event for operations that return a value, but don't have any side effects of modifying the database or performing some other operation.

+ +

If your resource is called /add-follower, you can trigger its POST event from dpd.js:

+ +
dpd.addfollower.post('320d6151a9aad8ce', {userId: '6d75e75d9bd9b8a6'}, function(result, error) {
+  // Do something
+})
+
+ +

And over HTTP:

+ +
POST /add-follower/320d6151a9aad8ce
+Content-Type: application/json
+{
+  "userId": "6d75e75d9bd9b8a6"
+}
+

Event API #

+ +

In addition to the generic custom resource event API, the following functions and variables are available while scripting the Event resource:

setResult(result) #

+ +

Sets the response body. The result argument can be a string or an object.

+ +
// On GET /top-score
+dpd.scores.get({$limit: 1, $sort: {score: -1}, function(result) {
+  setResult(result[0]);
+});
+

url #

+ +

The URL of the request, without the resource's base URL. If the resource is called /add-follower and receives a request at /add-follower/320d6151a9aad8ce, the url value will be /320d6151a9aad8ce.

+ +
// On GET /statistics
+// Get the top score
+if (url === '/top-score') {
+  dpd.scores.get({$limit: 1, $sort: {score: -1}, function(result) {
+    setResult(result[0]);
+  });
+}
+

parts #

+ +

An array of the parts of the url, separated by /. If the resource is called /add-follower and receives a request at /add-follower/320d6151a9aad8ce/6d75e75d9bd9b8a6, the parts value will be ['320d6151a9aad8ce', '6d75e75d9bd9b8a6'].

+ +
// On POST /add-score
+// Give the specified user (/add-score/:userId) 5 points
+var userId = parts[0];
+if (!userId) cancel("You must provide a user");
+
+dpd.users.put({id: userId}, {score: {$inc: 5}}, function(result, err) {
+  if (err) cancel(err);
+});
+

query #

+ +

The query string object.

+ +
// On GET /sum
+// Return the sum of the a and b properties (/sum?a=5&b=1)
+
+setResult(query.a + query.b);
+

body #

+ +

The body of the request.

+ +
// On POST /sum
+// Return the sum of the a and b properties {a: 5, b: 1}
+
+setResult(body.a + body.b);
+

Importer #

+ +

This custom resource type allows you to import collections from an existing MongoDB.

Installation #

+ +

Create a project. Then install the dpd-importer module.

+ +
dpd create my-app
+cd my-app
+mkdir node_modules
+npm install dpd-importer
+dpd -d
+
+ +

In your dashboard - click the green new resource button and choose Importer.

+ +

Give the new resource the default name "/importer". Open it by clicking "IMPOTER" in the left menu.

+ +

Enter the information of your old MongoDB server. Clicking on Start Import will start creating deployd collections from data in the provided db by streaming data directly from the old db into your new deployd db. The importer will do its best to create properties based on the types it infers from your data.

S3 Bucket Resource #

+ +

This custom resource type allows you to store and retrieve files from an Amazon S3 bucket.

Installation #

+ +

In your app's root directory, type npm install s3-bucket-resource into the command line or download the source. This should create a dpd-s3 directory in your app's node_modules directory.

+ +

See Installing Modules for details.

Configuration #

+ +

Before you can use the S3 Bucket resource, you must set the three properties on its "Config" page:

+ +
    +
  • bucket: The name of your S3 Bucket
  • +
  • key: The security key of your S3 Bucket
  • +
  • secret: The secret key of your S3 Bucket
  • +

Usage #

Upload #

+ +

There are two ways to upload files. Both ways require HTTP access; you cannot upload files with dpd.js.

Direct upload #
+ +

Send a POST request to the url where you want to upload the file, including the file name. Set the Content-Type header to that of the file you are uploading and pass the file's content in the request body.

+ +

It will return a 200 OK if the upload was successful. If there was an error, it will return the error directly from S3. This is usually in XML; see Amazon's S3 documentation for information.

+ +
POST /my-bucket/README.txt
+Content-Type: text/plain
+Hello, world!
+
+200 OK
+
Multipart upload #
+ +

You can upload files directly from a browser using the multipart/form-data type and the <input type="file" /> tag:

+ +
<form action="/installer-downloads" enctype="multipart/form-data" method="post">
+    <input type="file" name="upload" multiple="multiple" />
+    <button type="submit">Upload</button>
+</form>
+
+ +

To send a multipart request manually, send a POST request to the url where you want to upload the file, not including the file name. The Content-Type header must be multipart/form-data. Set the request body according to the multipart/form-data standard.

+ +

If the upload was successful and there is a Referrer header on the request (e.g. if it was submitted as a form from a browser), the response will redirect to the referrer. Otherwise, it will return 200 OK. If there was an error, it will return the error directly from S3. This is usually in XML; see Amazon's S3 documentation for information.

Retrieving files #

+ +

To download a file, send a GET request to the url where the file exists.

+ +
GET /my-bucket/README.txt
+
+200 OK
+Content-Type: text/plain
+Hello, world!
+

Deleting files #

+ +

To delete a file, send a DELETE request to the url where the file exists.

+ +
DELETE /my-bucket/README.txt
+
+200 OK
+
+ +

This can also be done with dpd.js:

+ +
dpd.mybucket.del('README.txt', function(response, error) {
+    // Do something
+});
+

Events #

+ +

The S3 Bucket Resource has three events:

+ +
    +
  • On Upload: Executed before a file is uploaded to S3.
  • +
  • On Get: Executed before a file is downloaded from S3.
  • +
  • On Delete: Executed before a file is deleted.
  • +

Event API #

url #

+ +

The URL of the request. Does not include the resource's name; if the request URL is /my-bucket/README.txt, the url property will be /README.txt.

fileSize #

+ +

Only available in On Upload. The size of the file, in bytes.

+ +
    // On Upload
+    // Set a limit on file size
+    if (fileSize > 1024*1024*1024) { // 1GB
+        cancel("File is too big; limit is 1GB");
+    }
+

fileName #

+ +

Only available in On Upload. The name of the file that is being uploaded.

+ +
    // On Upload
+    dpd.uploads.post({ filename: fileName, creator: me.id }, function() {})
+
+ + + + +

Using a Custom Resource Type #

+ +

Deployd modules can register new Resource Types, which can be created with a route and configured per instance. Deployd comes with two built-in Resource Types: "Collection" and "User Collection".

+ +

To add more Resource Types, you can install a module that includes one. The examples on this page use the Event resource.

Creating an instance of a Custom Resource Type #

+ +

Once the module is properly installed, you can add the custom resource just like a Collection. Custom Resources will usually have an asterisk icon.

+ +

Creating an Event resource

+ +

Note: After adding any module, you will have to restart the Deployd server to see its effects. If you don't see the custom resource type in the list, you may have to restart the server and refresh the dashboard.

Configuring a Custom Resource Type #

+ +

See the documentation of your Custom Resource Type module for details on configuration options. Most custom resource types implement a "Config" page and an "Events" page.

+ +

The "Config" page can take different forms. For very basic modules, it's often a simple JSON editor where you can enter optional values. Others will list their available configuration values in a form.

+ +

The "Events" page is similar to the Collection "Events" page.

+ +

Depending on the complexity of the custom resource type, it may have different configuration pages.

+ + + +

More

+ + + +
+
+
+

Other docs in "Docs"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules/installing-modules.md.html b/docs/using-modules/installing-modules.md.html new file mode 100644 index 0000000..f5791c8 --- /dev/null +++ b/docs/using-modules/installing-modules.md.html @@ -0,0 +1,400 @@ + + + + + + Installing a Module - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Installing a Module #

From NPM #

+ +

Deployd modules are 100% compatible with node modules. This means you can install a module with npm from your project's root directory.

+ +
cd my-dpd-project
+mkdir -p node_modules
+npm install my-dpd-module
+
+ +

To find deployd modules available on npm search for dpd.

+ +

If you used the Deployd installer, you will need to download node.js in order to use npm.

From Source #

+ +

You can also install a module from source by putting it in your project's node_modules folder. Even a single file is valid (eg: /node_modules/foo.js).

+ + +

More

+ + + +
+
+
+

Other docs in "Using Modules"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules/official-include=all.html b/docs/using-modules/official-include=all.html new file mode 100644 index 0000000..744bddd --- /dev/null +++ b/docs/using-modules/official-include=all.html @@ -0,0 +1,631 @@ + + + + + + Official - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Email Resource #

+ +

This custom resource type allows you to send an email to your users.

+ +

The Email resource is built on the Nodemailer module for Node.js; much of the documentation on this page is taken from their README.

Installation #

+ +

In your app's root directory, type npm install dpd-email into the command line or download from source. This should create a dpd-email directory in your app's node_modules directory.

+ +

See Installing Modules for details.

Configuration #

+ +

Before using the email resource, you must go to its Dashboard page and configure it.

+ +

These settings are required:

+ +
    +
  • host: The hostname of your SMTP provider.
  • +
  • port: The port number of your SMTP provider. Defaults to 25; 587 is also common.
  • +
  • ssl: If checked, use SSL to communicate with your SMTP provider. Unneeded for port 587; as it will automatically upgrade to a secure connection.
  • +
  • username: The SMTP username for your app.
  • +
  • password: The SMTP username for your app.
  • +
+ +

These settings are optional:

+ +
    +
  • defaultFromAddress: A "from" email address to provide by default. If this is not provided, you will need to provide this address in every request.
  • +
  • internalOnly: If checked, only allow internal requests (such as those from events) to send emails. Recommended for security.
  • +
  • productionOnly: If checked, attempting to send an email in the development environment will simply print it to the Deployd console.
  • +

Usage #

+ +

To send an email, call dpd.email.post(options, callback) (replacing email with your resource name). The options argument is an object:

+ +
    +
  • from: The email address of the sender. Required if defaultFromAddress is not configured. All e-mail addresses can be plain (sender@server.com) or formatted (Sender Name <sender@server.com>)
  • +
  • to: Comma separated list of recipients e-mail addresses that will appear on the To: field
  • +
  • cc: Comma separated list of recipients e-mail addresses that will appear on the Cc: field
  • +
  • bcc: Comma separated list of recipients e-mail addresses that will appear on the Bcc: field
  • +
  • subject: The subject of the e-mail.
  • +
  • text: The plaintext version of the message
  • +
  • html: The HTML version of the message
  • +

Example Usage #

+ +
// On POST /users
+
+dpd.email.post({
+  to: this.email,
+  from: "deployd-server@example.com", 
+  subject: "MyApp registration",
+  text: this.username + ",\n\n" +
+        "Thank you for registering for MyApp!"
+}, function() {});
+
+ + + + +

Event Resource #

+ +

This custom resource type allows you to write an event that will run when the resource's route receives a GET or POST request.

Installation #

+ +

In your app's root directory, type npm install dpd-event into the command line or download the source. This should create a dpd-event directory in your app's node_modules directory.

+ +

See Installing Modules for details.

Usage #

+ +

The On POST event will be executed when the resource's route (or a subroute) receives a POST request, and likewise with the On GET event.

+ +

It is strongly recommended that you reserve the On GET event for operations that return a value, but don't have any side effects of modifying the database or performing some other operation.

+ +

If your resource is called /add-follower, you can trigger its POST event from dpd.js:

+ +
dpd.addfollower.post('320d6151a9aad8ce', {userId: '6d75e75d9bd9b8a6'}, function(result, error) {
+  // Do something
+})
+
+ +

And over HTTP:

+ +
POST /add-follower/320d6151a9aad8ce
+Content-Type: application/json
+{
+  "userId": "6d75e75d9bd9b8a6"
+}
+

Event API #

+ +

In addition to the generic custom resource event API, the following functions and variables are available while scripting the Event resource:

setResult(result) #

+ +

Sets the response body. The result argument can be a string or an object.

+ +
// On GET /top-score
+dpd.scores.get({$limit: 1, $sort: {score: -1}, function(result) {
+  setResult(result[0]);
+});
+

url #

+ +

The URL of the request, without the resource's base URL. If the resource is called /add-follower and receives a request at /add-follower/320d6151a9aad8ce, the url value will be /320d6151a9aad8ce.

+ +
// On GET /statistics
+// Get the top score
+if (url === '/top-score') {
+  dpd.scores.get({$limit: 1, $sort: {score: -1}, function(result) {
+    setResult(result[0]);
+  });
+}
+

parts #

+ +

An array of the parts of the url, separated by /. If the resource is called /add-follower and receives a request at /add-follower/320d6151a9aad8ce/6d75e75d9bd9b8a6, the parts value will be ['320d6151a9aad8ce', '6d75e75d9bd9b8a6'].

+ +
// On POST /add-score
+// Give the specified user (/add-score/:userId) 5 points
+var userId = parts[0];
+if (!userId) cancel("You must provide a user");
+
+dpd.users.put({id: userId}, {score: {$inc: 5}}, function(result, err) {
+  if (err) cancel(err);
+});
+

query #

+ +

The query string object.

+ +
// On GET /sum
+// Return the sum of the a and b properties (/sum?a=5&b=1)
+
+setResult(query.a + query.b);
+

body #

+ +

The body of the request.

+ +
// On POST /sum
+// Return the sum of the a and b properties {a: 5, b: 1}
+
+setResult(body.a + body.b);
+
+ + + + +

Importer #

+ +

This custom resource type allows you to import collections from an existing MongoDB.

Installation #

+ +

Create a project. Then install the dpd-importer module.

+ +
dpd create my-app
+cd my-app
+mkdir node_modules
+npm install dpd-importer
+dpd -d
+
+ +

In your dashboard - click the green new resource button and choose Importer.

+ +

Give the new resource the default name "/importer". Open it by clicking "IMPOTER" in the left menu.

+ +

Enter the information of your old MongoDB server. Clicking on Start Import will start creating deployd collections from data in the provided db by streaming data directly from the old db into your new deployd db. The importer will do its best to create properties based on the types it infers from your data.

+ + + + +

S3 Bucket Resource #

+ +

This custom resource type allows you to store and retrieve files from an Amazon S3 bucket.

Installation #

+ +

In your app's root directory, type npm install s3-bucket-resource into the command line or download the source. This should create a dpd-s3 directory in your app's node_modules directory.

+ +

See Installing Modules for details.

Configuration #

+ +

Before you can use the S3 Bucket resource, you must set the three properties on its "Config" page:

+ +
    +
  • bucket: The name of your S3 Bucket
  • +
  • key: The security key of your S3 Bucket
  • +
  • secret: The secret key of your S3 Bucket
  • +

Usage #

Upload #

+ +

There are two ways to upload files. Both ways require HTTP access; you cannot upload files with dpd.js.

Direct upload #
+ +

Send a POST request to the url where you want to upload the file, including the file name. Set the Content-Type header to that of the file you are uploading and pass the file's content in the request body.

+ +

It will return a 200 OK if the upload was successful. If there was an error, it will return the error directly from S3. This is usually in XML; see Amazon's S3 documentation for information.

+ +
POST /my-bucket/README.txt
+Content-Type: text/plain
+Hello, world!
+
+200 OK
+
Multipart upload #
+ +

You can upload files directly from a browser using the multipart/form-data type and the <input type="file" /> tag:

+ +
<form action="/installer-downloads" enctype="multipart/form-data" method="post">
+    <input type="file" name="upload" multiple="multiple" />
+    <button type="submit">Upload</button>
+</form>
+
+ +

To send a multipart request manually, send a POST request to the url where you want to upload the file, not including the file name. The Content-Type header must be multipart/form-data. Set the request body according to the multipart/form-data standard.

+ +

If the upload was successful and there is a Referrer header on the request (e.g. if it was submitted as a form from a browser), the response will redirect to the referrer. Otherwise, it will return 200 OK. If there was an error, it will return the error directly from S3. This is usually in XML; see Amazon's S3 documentation for information.

Retrieving files #

+ +

To download a file, send a GET request to the url where the file exists.

+ +
GET /my-bucket/README.txt
+
+200 OK
+Content-Type: text/plain
+Hello, world!
+

Deleting files #

+ +

To delete a file, send a DELETE request to the url where the file exists.

+ +
DELETE /my-bucket/README.txt
+
+200 OK
+
+ +

This can also be done with dpd.js:

+ +
dpd.mybucket.del('README.txt', function(response, error) {
+    // Do something
+});
+

Events #

+ +

The S3 Bucket Resource has three events:

+ +
    +
  • On Upload: Executed before a file is uploaded to S3.
  • +
  • On Get: Executed before a file is downloaded from S3.
  • +
  • On Delete: Executed before a file is deleted.
  • +

Event API #

url #

+ +

The URL of the request. Does not include the resource's name; if the request URL is /my-bucket/README.txt, the url property will be /README.txt.

fileSize #

+ +

Only available in On Upload. The size of the file, in bytes.

+ +
    // On Upload
+    // Set a limit on file size
+    if (fileSize > 1024*1024*1024) { // 1GB
+        cancel("File is too big; limit is 1GB");
+    }
+

fileName #

+ +

Only available in On Upload. The name of the file that is being uploaded.

+ +
    // On Upload
+    dpd.uploads.post({ filename: fileName, creator: me.id }, function() {})
+
+ + + +

More

+ + + +
+
+
+

Other docs in "Using Modules"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules/official/email.md.html b/docs/using-modules/official/email.md.html new file mode 100644 index 0000000..733b4d5 --- /dev/null +++ b/docs/using-modules/official/email.md.html @@ -0,0 +1,436 @@ + + + + + + Email - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Email Resource #

+ +

This custom resource type allows you to send an email to your users.

+ +

The Email resource is built on the Nodemailer module for Node.js; much of the documentation on this page is taken from their README.

Installation #

+ +

In your app's root directory, type npm install dpd-email into the command line or download from source. This should create a dpd-email directory in your app's node_modules directory.

+ +

See Installing Modules for details.

Configuration #

+ +

Before using the email resource, you must go to its Dashboard page and configure it.

+ +

These settings are required:

+ +
    +
  • host: The hostname of your SMTP provider.
  • +
  • port: The port number of your SMTP provider. Defaults to 25; 587 is also common.
  • +
  • ssl: If checked, use SSL to communicate with your SMTP provider. Unneeded for port 587; as it will automatically upgrade to a secure connection.
  • +
  • username: The SMTP username for your app.
  • +
  • password: The SMTP username for your app.
  • +
+ +

These settings are optional:

+ +
    +
  • defaultFromAddress: A "from" email address to provide by default. If this is not provided, you will need to provide this address in every request.
  • +
  • internalOnly: If checked, only allow internal requests (such as those from events) to send emails. Recommended for security.
  • +
  • productionOnly: If checked, attempting to send an email in the development environment will simply print it to the Deployd console.
  • +

Usage #

+ +

To send an email, call dpd.email.post(options, callback) (replacing email with your resource name). The options argument is an object:

+ +
    +
  • from: The email address of the sender. Required if defaultFromAddress is not configured. All e-mail addresses can be plain (sender@server.com) or formatted (Sender Name <sender@server.com>)
  • +
  • to: Comma separated list of recipients e-mail addresses that will appear on the To: field
  • +
  • cc: Comma separated list of recipients e-mail addresses that will appear on the Cc: field
  • +
  • bcc: Comma separated list of recipients e-mail addresses that will appear on the Bcc: field
  • +
  • subject: The subject of the e-mail.
  • +
  • text: The plaintext version of the message
  • +
  • html: The HTML version of the message
  • +

Example Usage #

+ +
// On POST /users
+
+dpd.email.post({
+  to: this.email,
+  from: "deployd-server@example.com", 
+  subject: "MyApp registration",
+  text: this.username + ",\n\n" +
+        "Thank you for registering for MyApp!"
+}, function() {});
+
+ + +

More

+ + + +
+
+
+

Other docs in "Official"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules/official/event.md.html b/docs/using-modules/official/event.md.html new file mode 100644 index 0000000..c6c1965 --- /dev/null +++ b/docs/using-modules/official/event.md.html @@ -0,0 +1,460 @@ + + + + + + Event Resource - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Event Resource #

+ +

This custom resource type allows you to write an event that will run when the resource's route receives a GET or POST request.

Installation #

+ +

In your app's root directory, type npm install dpd-event into the command line or download the source. This should create a dpd-event directory in your app's node_modules directory.

+ +

See Installing Modules for details.

Usage #

+ +

The On POST event will be executed when the resource's route (or a subroute) receives a POST request, and likewise with the On GET event.

+ +

It is strongly recommended that you reserve the On GET event for operations that return a value, but don't have any side effects of modifying the database or performing some other operation.

+ +

If your resource is called /add-follower, you can trigger its POST event from dpd.js:

+ +
dpd.addfollower.post('320d6151a9aad8ce', {userId: '6d75e75d9bd9b8a6'}, function(result, error) {
+  // Do something
+})
+
+ +

And over HTTP:

+ +
POST /add-follower/320d6151a9aad8ce
+Content-Type: application/json
+{
+  "userId": "6d75e75d9bd9b8a6"
+}
+

Event API #

+ +

In addition to the generic custom resource event API, the following functions and variables are available while scripting the Event resource:

setResult(result) #

+ +

Sets the response body. The result argument can be a string or an object.

+ +
// On GET /top-score
+dpd.scores.get({$limit: 1, $sort: {score: -1}, function(result) {
+  setResult(result[0]);
+});
+

url #

+ +

The URL of the request, without the resource's base URL. If the resource is called /add-follower and receives a request at /add-follower/320d6151a9aad8ce, the url value will be /320d6151a9aad8ce.

+ +
// On GET /statistics
+// Get the top score
+if (url === '/top-score') {
+  dpd.scores.get({$limit: 1, $sort: {score: -1}, function(result) {
+    setResult(result[0]);
+  });
+}
+

parts #

+ +

An array of the parts of the url, separated by /. If the resource is called /add-follower and receives a request at /add-follower/320d6151a9aad8ce/6d75e75d9bd9b8a6, the parts value will be ['320d6151a9aad8ce', '6d75e75d9bd9b8a6'].

+ +
// On POST /add-score
+// Give the specified user (/add-score/:userId) 5 points
+var userId = parts[0];
+if (!userId) cancel("You must provide a user");
+
+dpd.users.put({id: userId}, {score: {$inc: 5}}, function(result, err) {
+  if (err) cancel(err);
+});
+

query #

+ +

The query string object.

+ +
// On GET /sum
+// Return the sum of the a and b properties (/sum?a=5&b=1)
+
+setResult(query.a + query.b);
+

body #

+ +

The body of the request.

+ +
// On POST /sum
+// Return the sum of the a and b properties {a: 5, b: 1}
+
+setResult(body.a + body.b);
+
+ + +

More

+ + + +
+
+
+

Other docs in "Official"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules/official/importer.md.html b/docs/using-modules/official/importer.md.html new file mode 100644 index 0000000..54a78b6 --- /dev/null +++ b/docs/using-modules/official/importer.md.html @@ -0,0 +1,402 @@ + + + + + + Importer - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Importer #

+ +

This custom resource type allows you to import collections from an existing MongoDB.

Installation #

+ +

Create a project. Then install the dpd-importer module.

+ +
dpd create my-app
+cd my-app
+mkdir node_modules
+npm install dpd-importer
+dpd -d
+
+ +

In your dashboard - click the green new resource button and choose Importer.

+ +

Give the new resource the default name "/importer". Open it by clicking "IMPOTER" in the left menu.

+ +

Enter the information of your old MongoDB server. Clicking on Start Import will start creating deployd collections from data in the provided db by streaming data directly from the old db into your new deployd db. The importer will do its best to create properties based on the types it infers from your data.

+ + +

More

+ + + +
+
+
+

Other docs in "Official"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules/official/s3.md.html b/docs/using-modules/official/s3.md.html new file mode 100644 index 0000000..698a353 --- /dev/null +++ b/docs/using-modules/official/s3.md.html @@ -0,0 +1,472 @@ + + + + + + S3 Bucket - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

S3 Bucket Resource #

+ +

This custom resource type allows you to store and retrieve files from an Amazon S3 bucket.

Installation #

+ +

In your app's root directory, type npm install s3-bucket-resource into the command line or download the source. This should create a dpd-s3 directory in your app's node_modules directory.

+ +

See Installing Modules for details.

Configuration #

+ +

Before you can use the S3 Bucket resource, you must set the three properties on its "Config" page:

+ +
    +
  • bucket: The name of your S3 Bucket
  • +
  • key: The security key of your S3 Bucket
  • +
  • secret: The secret key of your S3 Bucket
  • +

Usage #

Upload #

+ +

There are two ways to upload files. Both ways require HTTP access; you cannot upload files with dpd.js.

Direct upload #
+ +

Send a POST request to the url where you want to upload the file, including the file name. Set the Content-Type header to that of the file you are uploading and pass the file's content in the request body.

+ +

It will return a 200 OK if the upload was successful. If there was an error, it will return the error directly from S3. This is usually in XML; see Amazon's S3 documentation for information.

+ +
POST /my-bucket/README.txt
+Content-Type: text/plain
+Hello, world!
+
+200 OK
+
Multipart upload #
+ +

You can upload files directly from a browser using the multipart/form-data type and the <input type="file" /> tag:

+ +
<form action="/installer-downloads" enctype="multipart/form-data" method="post">
+    <input type="file" name="upload" multiple="multiple" />
+    <button type="submit">Upload</button>
+</form>
+
+ +

To send a multipart request manually, send a POST request to the url where you want to upload the file, not including the file name. The Content-Type header must be multipart/form-data. Set the request body according to the multipart/form-data standard.

+ +

If the upload was successful and there is a Referrer header on the request (e.g. if it was submitted as a form from a browser), the response will redirect to the referrer. Otherwise, it will return 200 OK. If there was an error, it will return the error directly from S3. This is usually in XML; see Amazon's S3 documentation for information.

Retrieving files #

+ +

To download a file, send a GET request to the url where the file exists.

+ +
GET /my-bucket/README.txt
+
+200 OK
+Content-Type: text/plain
+Hello, world!
+

Deleting files #

+ +

To delete a file, send a DELETE request to the url where the file exists.

+ +
DELETE /my-bucket/README.txt
+
+200 OK
+
+ +

This can also be done with dpd.js:

+ +
dpd.mybucket.del('README.txt', function(response, error) {
+    // Do something
+});
+

Events #

+ +

The S3 Bucket Resource has three events:

+ +
    +
  • On Upload: Executed before a file is uploaded to S3.
  • +
  • On Get: Executed before a file is downloaded from S3.
  • +
  • On Delete: Executed before a file is deleted.
  • +

Event API #

url #

+ +

The URL of the request. Does not include the resource's name; if the request URL is /my-bucket/README.txt, the url property will be /README.txt.

fileSize #

+ +

Only available in On Upload. The size of the file, in bytes.

+ +
    // On Upload
+    // Set a limit on file size
+    if (fileSize > 1024*1024*1024) { // 1GB
+        cancel("File is too big; limit is 1GB");
+    }
+

fileName #

+ +

Only available in On Upload. The name of the file that is being uploaded.

+ +
    // On Upload
+    dpd.uploads.post({ filename: fileName, creator: me.id }, function() {})
+
+ + +

More

+ + + +
+
+
+

Other docs in "Official"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules/reference-include=all.html b/docs/using-modules/reference-include=all.html new file mode 100644 index 0000000..ec4a25d --- /dev/null +++ b/docs/using-modules/reference-include=all.html @@ -0,0 +1,553 @@ + + + + + + Reference - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + + + +

Dpd.js for Custom Resources #

+ +

Because Custom Resource Types can specify APIs very different from a Collection, Dpd.js acts as a generic HTTP library for Custom Resources.

Accessing the Resource #

+ +

The API for your Resource is automatically generated as dpd.[resource].

+ +

Examples:

+ +
dpd.emails
+dpd.addfollower
+dpd.uploads
+
+ +

Note: If your Resource name has a dash in it (e.g. /add-follower), the dash is removed when accessing it in this way (e.g. dpd.addfollower).

+ +

You can also access your resource by using dpd(resourceName) as a function.

+ +

Examples:

+ +
dpd('emails')
+dpd('add-follower')
+dpd('uploads')
+

Callbacks #

+ +

Every function in the Dpd.js API takes a callback function (represented by fn in the docs) with the signature function(result, error).

+ +

The callback will be executed asynchronously when the API has received a response from the server.

+ +

The result argument differs depending on the function. If the result failed, it will be null and the error argument will contain the error message.

+ +

The error argument, if there was an error, is an object:

+ +
    +
  • status (number): The HTTP status code of the request. Common codes include: +
    • 400 - Bad Request: The request contained invalid data and could not be completed
    • +
    • 401 - Unauthorized: The current session is not authorized to perform that action
    • +
    • 500 - Internal Server Error: Something went wrong on the server
  • +
  • message (string): A message describing the error. Not always present.
  • +
  • errors (object): A hash of error messages corresponding to the properties of the object that was sent - usually indicates validation errors. Not always present.
  • +
+ +

Examples of errors:

+ +
{
+    "status": 401,
+    "message": "You are not allowed to access that resource!"
+}
+
+ + + +
{
+    "status": 400,
+    "errors": {
+        "title": "Title must be less than 100 characters",
+        "category": "Not a valid category"
+    }
+}
+

get() #

+ +
dpd.[resource].get([func], [path], [query], fn)
+
+ +

Makes a GET HTTP request at the URL /<resource>/<func>/<path>, using the query object as the query string if provided.

+ +
    +
  • func - A special identifier, i.e. /me.
  • +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON.
  • +
  • fn - Callback function(result, error).
  • +

post() #

+ +
dpd.[resource].post([path], [query], body, fn)
+
+ +

Makes a POST HTTP request at the URL /<resource>/<path>, using the query object as the query string if provided and body as the request body.

+ +
    +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON.
  • +
  • body - The body of the request; will be serialized as JSON and sent with Content-Type: application/json header.
  • +
  • fn - Callback function(result, error).
  • +

put() #

+ +
dpd.[resource].put([path], [query], body, fn)
+
+ +

Makes a PUT HTTP request at the URL /<resource>/<path>, using the query object as the query string if provided and body as the request body.

+ +
    +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON and passed as the q parameter.
  • +
  • body - The body of the request; will be serialized as JSON and sent with Content-Type: application/json header.
  • +
  • fn - Callback function(result, error).
  • +

del() #

+ +
dpd.[resource].del([path], [query], fn)
+
+ +

Makes a DELETE HTTP request at the URL /<resource>/<path>, using the query object as the query string if provided.

+ +
    +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON and passed as the q parameter.
  • +
  • fn - Callback function(result, error).
  • +

exec() #

+ +
dpd.[resource].exec(func, [path], [body], fn)
+
+ +

Makes an RPC-style POST HTTP request at the URL /<resource>/<func>/<path>. Useful for functions that don't make sense in REST-style APIs, such as /users/login.

+ +
    +
  • func - The name of the function to call
  • +
  • path - An identifier for a particular object, usually the id
  • +
  • body - The body of the request; will be serialized as JSON and sent with Content-Type: application/json header.
  • +
  • fn - Callback function(result, error).
  • +

Realtime API #

+ +

The Generic Realtime API behaves the same way as the Collection Realtime API.

+ + + + +

Event API for Custom Resources #

Background #

+ +

Custom Resources may load event scripts to allow you to inject business logic during requests to the resource. For example, the collection resource exposes an event called validate. Given the following todo resource folder:

+ +
/my-app
+  /resources
+    /todos
+      validate.js
+
+ +

The collection resource would load the contents of validate.js as the validate event.

Default Event Script Domain #

+ +

Event scripts do not share a global scope with other modules in your app. Instead each time an event script is run, a new scope is created for it.

+ +

The following functions and objects are available to all event scripts.

me #

+ +

The current user if one exists on the current Context.

isMe() #

+ +
isMe(id)
+
+ +

Returns true if the current user (me) matches the provided id.

this #

+ +

If the resource does not implement a custom domain, this will be an empty object. Otherwise this usually refers to the current domain's instance (eg. an object in a collection).

cancel() #

+ +
cancel(message, [statusCode])
+
+ +

Stops the current request with the provided error message and HTTP status code. Status code defaults to 400.

cancelIf(), cancelUnless() #

+ +
cancelIf(condition, message, [statusCode])
+cancelUnless(condition, message, [statusCode])
+
+ +

Calls cancel(message, statusCode) if the provided condition is truthy (for cancelIf()) or falsy (for cancelUnless).

internal #

+ +

A boolean property, true if this request has been initiated by another script.

isRoot #

+ +

A boolean property, true if this request is authenticated as root (from the dashboard or a custom script).

query #

+ +

The current HTTP query. (eg ?foo=bar - query would be {foo: 'bar'}).

emit() #

+ +
emit([userCollection, query], message, [data])
+
+ +

Emits a realtime message to the client. You can use userCollection and query parameters to limit the message broadcast to specific users.

console #

+ +

Support for console.log() and other console methods.

+ + + +

More

+ + + +
+
+
+

Other docs in "Using Modules"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules/reference/dpd-js.md.html b/docs/using-modules/reference/dpd-js.md.html new file mode 100644 index 0000000..ad3722b --- /dev/null +++ b/docs/using-modules/reference/dpd-js.md.html @@ -0,0 +1,496 @@ + + + + + + Dpd.js for Custom Resources - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Dpd.js for Custom Resources #

+ +

Because Custom Resource Types can specify APIs very different from a Collection, Dpd.js acts as a generic HTTP library for Custom Resources.

Accessing the Resource #

+ +

The API for your Resource is automatically generated as dpd.[resource].

+ +

Examples:

+ +
dpd.emails
+dpd.addfollower
+dpd.uploads
+
+ +

Note: If your Resource name has a dash in it (e.g. /add-follower), the dash is removed when accessing it in this way (e.g. dpd.addfollower).

+ +

You can also access your resource by using dpd(resourceName) as a function.

+ +

Examples:

+ +
dpd('emails')
+dpd('add-follower')
+dpd('uploads')
+

Callbacks #

+ +

Every function in the Dpd.js API takes a callback function (represented by fn in the docs) with the signature function(result, error).

+ +

The callback will be executed asynchronously when the API has received a response from the server.

+ +

The result argument differs depending on the function. If the result failed, it will be null and the error argument will contain the error message.

+ +

The error argument, if there was an error, is an object:

+ +
    +
  • status (number): The HTTP status code of the request. Common codes include: +
    • 400 - Bad Request: The request contained invalid data and could not be completed
    • +
    • 401 - Unauthorized: The current session is not authorized to perform that action
    • +
    • 500 - Internal Server Error: Something went wrong on the server
  • +
  • message (string): A message describing the error. Not always present.
  • +
  • errors (object): A hash of error messages corresponding to the properties of the object that was sent - usually indicates validation errors. Not always present.
  • +
+ +

Examples of errors:

+ +
{
+    "status": 401,
+    "message": "You are not allowed to access that resource!"
+}
+
+ + + +
{
+    "status": 400,
+    "errors": {
+        "title": "Title must be less than 100 characters",
+        "category": "Not a valid category"
+    }
+}
+

get() #

+ +
dpd.[resource].get([func], [path], [query], fn)
+
+ +

Makes a GET HTTP request at the URL /<resource>/<func>/<path>, using the query object as the query string if provided.

+ +
    +
  • func - A special identifier, i.e. /me.
  • +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON.
  • +
  • fn - Callback function(result, error).
  • +

post() #

+ +
dpd.[resource].post([path], [query], body, fn)
+
+ +

Makes a POST HTTP request at the URL /<resource>/<path>, using the query object as the query string if provided and body as the request body.

+ +
    +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON.
  • +
  • body - The body of the request; will be serialized as JSON and sent with Content-Type: application/json header.
  • +
  • fn - Callback function(result, error).
  • +

put() #

+ +
dpd.[resource].put([path], [query], body, fn)
+
+ +

Makes a PUT HTTP request at the URL /<resource>/<path>, using the query object as the query string if provided and body as the request body.

+ +
    +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON and passed as the q parameter.
  • +
  • body - The body of the request; will be serialized as JSON and sent with Content-Type: application/json header.
  • +
  • fn - Callback function(result, error).
  • +

del() #

+ +
dpd.[resource].del([path], [query], fn)
+
+ +

Makes a DELETE HTTP request at the URL /<resource>/<path>, using the query object as the query string if provided.

+ +
    +
  • path - An identifier for a particular object, usually the id
  • +
  • query - An object defining the querystring. If the object is complex, it will be serialized as JSON and passed as the q parameter.
  • +
  • fn - Callback function(result, error).
  • +

exec() #

+ +
dpd.[resource].exec(func, [path], [body], fn)
+
+ +

Makes an RPC-style POST HTTP request at the URL /<resource>/<func>/<path>. Useful for functions that don't make sense in REST-style APIs, such as /users/login.

+ +
    +
  • func - The name of the function to call
  • +
  • path - An identifier for a particular object, usually the id
  • +
  • body - The body of the request; will be serialized as JSON and sent with Content-Type: application/json header.
  • +
  • fn - Callback function(result, error).
  • +

Realtime API #

+ +

The Generic Realtime API behaves the same way as the Collection Realtime API.

+ + +

More

+ + + +
+
+
+

Other docs in "Reference"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules/reference/event-api.md.html b/docs/using-modules/reference/event-api.md.html new file mode 100644 index 0000000..df4fcaf --- /dev/null +++ b/docs/using-modules/reference/event-api.md.html @@ -0,0 +1,424 @@ + + + + + + Event API for Custom Resources - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Event API for Custom Resources #

Background #

+ +

Custom Resources may load event scripts to allow you to inject business logic during requests to the resource. For example, the collection resource exposes an event called validate. Given the following todo resource folder:

+ +
/my-app
+  /resources
+    /todos
+      validate.js
+
+ +

The collection resource would load the contents of validate.js as the validate event.

Default Event Script Domain #

+ +

Event scripts do not share a global scope with other modules in your app. Instead each time an event script is run, a new scope is created for it.

+ +

The following functions and objects are available to all event scripts.

me #

+ +

The current user if one exists on the current Context.

isMe() #

+ +
isMe(id)
+
+ +

Returns true if the current user (me) matches the provided id.

this #

+ +

If the resource does not implement a custom domain, this will be an empty object. Otherwise this usually refers to the current domain's instance (eg. an object in a collection).

cancel() #

+ +
cancel(message, [statusCode])
+
+ +

Stops the current request with the provided error message and HTTP status code. Status code defaults to 400.

cancelIf(), cancelUnless() #

+ +
cancelIf(condition, message, [statusCode])
+cancelUnless(condition, message, [statusCode])
+
+ +

Calls cancel(message, statusCode) if the provided condition is truthy (for cancelIf()) or falsy (for cancelUnless).

internal #

+ +

A boolean property, true if this request has been initiated by another script.

isRoot #

+ +

A boolean property, true if this request is authenticated as root (from the dashboard or a custom script).

query #

+ +

The current HTTP query. (eg ?foo=bar - query would be {foo: 'bar'}).

emit() #

+ +
emit([userCollection, query], message, [data])
+
+ +

Emits a realtime message to the client. You can use userCollection and query parameters to limit the message broadcast to specific users.

console #

+ +

Support for console.log() and other console methods.

+ + +

More

+ + + +
+
+
+

Other docs in "Reference"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/docs/using-modules/using-resource-types.md.html b/docs/using-modules/using-resource-types.md.html new file mode 100644 index 0000000..9451a6b --- /dev/null +++ b/docs/using-modules/using-resource-types.md.html @@ -0,0 +1,405 @@ + + + + + + Using a Custom Resource Type - Deployd Docs + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +

Using a Custom Resource Type #

+ +

Deployd modules can register new Resource Types, which can be created with a route and configured per instance. Deployd comes with two built-in Resource Types: "Collection" and "User Collection".

+ +

To add more Resource Types, you can install a module that includes one. The examples on this page use the Event resource.

Creating an instance of a Custom Resource Type #

+ +

Once the module is properly installed, you can add the custom resource just like a Collection. Custom Resources will usually have an asterisk icon.

+ +

Creating an Event resource

+ +

Note: After adding any module, you will have to restart the Deployd server to see its effects. If you don't see the custom resource type in the list, you may have to restart the server and refresh the dashboard.

Configuring a Custom Resource Type #

+ +

See the documentation of your Custom Resource Type module for details on configuration options. Most custom resource types implement a "Config" page and an "Events" page.

+ +

The "Config" page can take different forms. For very basic modules, it's often a simple JSON editor where you can enter optional values. Others will list their available configuration values in a form.

+ +

The "Events" page is similar to the Collection "Events" page.

+ +

Depending on the complexity of the custom resource type, it may have different configuration pages.

+ + +

More

+ + + +
+
+
+

Other docs in "Using Modules"

+ +
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/examples/images/chat-room.png b/examples/images/chat-room.png new file mode 100644 index 0000000000000000000000000000000000000000..3055d585cf9a75a7fc15afa8e0b7446bf932ff25 GIT binary patch literal 11127 zcmeHtX;f3$_Gi>mUI|KBiYN#;lv0R*iVR_js0f09%rgioF+i9}fB@0rA%%#j$eaKr zGYC;e8A3p05(qMckU$t@2xK5kNgyGi!+XB&|609zb+2CC-|9nh@7?F#efD&Id+&Qs z!aWP)LkDFJ0sw$RcT8?s0|5K_0f0S(f9w@eZsA`>iw=82tc`B~D)Fb5L>E7S4b2S! zfRD-I+n)PH*FOiEIE4TJhue35d%6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?y^51Z4R^JL3L0u_L&Cy(FX?QU!i|k8 zQtQ)rFB}fHcGQfrVqK$NY=jxu9w17`r?g)bh!0Z^5{NST?T-Voi>(hqj=2$(~&=an?nhph7K@ly;5xLY#TU=6A z)@AJbn0+KKv|A#3Koz2GNZdYF>bhR#QLis^mneT2?83>;Eiab==}ZBE9>`8FhHIDK zQ&ZYVAE=?Zz~fQGwUQQX6wnR3Xzu}|_vxO{txy?Z>Fd|++@;d$&&&4u$BHK{$2x~D z>NhW!7*#y#|9CBY`B#8+e3r0XKC&E-&~;o@@6IYMNt2**|Bx&_e*~qPLe4+PGB1LbfH8@iKRFv?&+N$P=Q=_o0>RAi0fFIe@Mw+ zuA*N&N~Mcq&ztv)KAcDBx>2gv*)GHT=})25`R;~ww;?HC|J(Nh;o0+^!8z%H&Z#V*lk=>E^|6`b1emT27|SllsiC z5Lh8^zTme`9mTYYLTi@ZeO8CRTea?7OWx*PS=CO+S)@a`KqsJn0Y)1xJP zD$jDw`EX`)e&w|fz^MvNy@Okp%i(gvcF0zzkVsO)PM(g9fVafA(w9hw+N9Nvi4u|!d4^A#s-7JKUSP-{8p|k77&FI3C6T}6YTK_SI z1S1KhJ7voL9)&#b#ze(>c#|q9h)8s5u{wK&cLO=OwqH%zmM7A&R!Cansr&j;X-k*F z2mjI`a2PLr%+9OV+lQUJ^y?FG`foslJNLnYpAO|z_|9B+k%$`>A9OFgi4wu{fOY+!1aIXOOq1pYS*N@kY{tx$p)O029fWl-Y X__KPY`$YR<0e6fnZdKm6|Hpp=yzL&j literal 0 HcmV?d00001 diff --git a/examples/images/todo-app.png b/examples/images/todo-app.png new file mode 100644 index 0000000000000000000000000000000000000000..14dc57d528f638b3f81c69bd635df4c8efb60b7f GIT binary patch literal 5729 zcmbVQcT|(hwhxE}q(?+h>4Xj@GzA5L&;v+E=^X??0qGJvA|2@^f}oU0Z=pwubV8F7 zij*9B34|t{z>DXe`__GHy>-{S?~m{MW@ha@v-h`u`!{vt^VCyS1e6ZkStE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kyFy}Qx)aOf`e2cb=V|C_s{zj-B!Cet#75|K^#N{prR7jjjM~(oc_zX>1qedod;-gn9s + + + + + deployd + + + + + + + + + + + + + + + + + + + + + +
+ + +
+

A Simple Todo App #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using dpd.js.

+ +

Download View Source

Useful files #

+ +

A Simple Todo App with AngularJS #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using the AngularJS framework.

+ +

Download View Source

Useful files #

+ +

A Simple Todo App with Backbone.js #

+ +

Todo app

+ +

This app demonstrates how to access a Collection's API using Backbone.js.

+ +

Download View Source

Useful files #

+ +

Chatroom #

+ +

Todo app

+ +

This app demonstrates how to send messages to the client using Sockets when data is updated on the server.

+ +

Download View Source

Useful files #

+ +

Email Resource Type #

+ +

This module demonstrates how to use a Node module such as Nodemailer to make a reusable resource type.

+ +

For information on how to use this module in your app, see the Email Resource documentation.

+ +

Download View Source

Useful files #

+ +

Event Resource Type #

+ +

This module demonstrates how to run user-defined Events in your resource. See the Creating Custom Resource Types page for an analysis of the source.

+ +

For information on how to use this module in your app, see the Event Resource documentation.

+ +

Download View Source

Useful files #

+ +

S3 Bucket Resource Type #

+ +

This module demonstrates how to receive file uploads in a custom resource type.

+ +

For information on how to use this module in your app, see the S3 Bucket Resource documentation.

+ +

Download View Source

Useful files #

+ +

Microblogging app #

+ +

This app demonstrates how to create a microblogging app (similar to Twitter) using User Collections. It also demonstrates how to use dpd.js with AngularJS on the front-end.

+ +

The app supports registering, logging in, making posts, and mentioning other users in posts with their @username.

+ +

Download View Source

Useful files #

+ +

Events:

+ + + +

Front-end:

+ +

Simple Login Form #

+ +

This app demonstrates how to use the "login", "logout", and "me" functions on a User Collection.

+ +

Download View Source

Useful files #

+ +
+
+ + +
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/guides.html b/guides.html new file mode 100644 index 0000000..6668ce3 --- /dev/null +++ b/guides.html @@ -0,0 +1,439 @@ + + + + + + deployd + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/images/basic-dashboard.png b/images/basic-dashboard.png new file mode 100644 index 0000000000000000000000000000000000000000..984267951aa95389d80f01f44fba0e2007b5ff47 GIT binary patch literal 16022 zcmbVz2UJu`)-FjvB?zd5MuG?^2!cS9bCR5MzJSE0$x&z!1W_AAB z24(_27VsMy{7p;XKTH>OSqY4y9_kg~3yzhzk~jv&xA5ENW;cNEHyvN-xnN)rHKYGw zwnK9*fL~I%O6$66Kwr9gm^oWwsG8Y0xUwrtYtp%MvGcHVa&YWBr(s}-+>nzJ*Yq^r zNb>poNGoaS1a#_&LuAzFTETr`xd+Qqda&;I2l5r`$ndn{Db;{#ExwP zd01!aW2{>RTs(xWAa`n`d-M>p7IN=C>EzvyPpP7K3E@I7nU6fS;FV4c&!4k8$h_2+ zX<=4QdKmhy(rJqqc5-%ER}YmsRQ6ec^d#~x-Y9MiprFHji}^>YB*D4`zNFt))l%}V z&(WmEv}KHuI|{<<7l?uHkAbgAjcJDSlPLNH7V=KdoqW&1geh+5R88&Cl+We)$!`5F z%Dx5{?+<_AZ7dYnP54c>zi(C-I7)p22dNy6nG@f9|K>J%=X>e*_q&q>W2Wgauz=4! zSuqOn<%YwoAR+hXY&A(9Q+m46eCE@>M^Oy-Lr@(Z_{BFc9XZS}h-SnHG}&;2?oRDS zSG*|gITaRw=ISN4O}AbGq`T)*@7_@jMwhWdjs9j|N6_o zU}mur0s7TbxVG3hVi-7L4cNdNyyKVIu8k%12L`k`(0s+__o!wdo{mq2l}?e@Z=8Xo zg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K1FHP-~YG{9zp7SQ@vQ}(%os-PG{M>SQ>S=nw;)vdyldWx33 zWx85%r8*E83J1$QIJL8apd%{flKFYZpFgoU+AnkJK&g zITKPY3NC->;hfbMnDr#H`OLQT&*z+{s(M3$C%~paHhMX4e)}`vUCx!gD(P@1@*p|U5zUDzZ~k17xUw4*Q3`^<@W}=C99n^C)9d0x zg^~aZMb8B(WofH=7fl6)b$d5^&?UByvoh8fI8BOmpVOwyyVBBa<;3N@Mz`k)zjX@P zo5JtP?#h0Yxr?1o9AaxBaM0-YzU7Lp$JT{dEVOfyS#4r+dmjIFJ@>oeMKc#QFKPyv z+zE+sTcGVrdAm4`G(9iG7+(Sh#gxNaZwG%5{SppxqNJS1tROG0iyv zZ+_2f6Or5<^swa@N8y@F7jmlYgvxBPcqToDsW$iw4)bcD?OxI%!YM(M7VJ!0vNha7 z@uWt3QTy_DOEcC19Lw3s8Ii@&u*iaIHB3@``<-Qfy3(9x6)n zKY85#yW-=D?~8zT12aTLLuk~)mQ7Dn9+<0o25b#4vDV;ENl9rroLJy=F(YJB_KtG1 zRrRjvpePdIUvh-G!%?ie)%(%}Mqqk;n5?o{(@JFtGgE-SzkhVJbTywQ&q~=DD$`)` z)IOIzVrFzy)StTjG4n5P@QXOsBYC*{iI;OvQ0mE>pq$3WZ*XwNTZx5FeUd*XN-PPD z{L~58+{zxnS{NUa5u~27=JuXG(14;!WO$~Fh%DP9cbQ~`L{4(O=y=f)QV?{p_bJH*SS&nf z!Z>N_Pv7WEA=kB}w18%SGBqe=%w!L-S$N~NW!IAM=J{7lc@Y$-JuV<; zNZi-fj1zJ~cAp#2Pr$tWW1zopr01^@A)c^nh literal 0 HcmV?d00001 diff --git a/img/glyphicons-halflings-white.png b/img/glyphicons-halflings-white.png new file mode 100644 index 0000000000000000000000000000000000000000..3bf6484a29d8da269f9bc874b25493a45fae3bae GIT binary patch literal 8777 zcmZvC1yGz#v+m*$LXcp=A$ZWB0fL7wNbp_U*$~{_gL`my3oP#L!5tQ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R(5iWJi2~l&xy}aU7kW?o-V*6Av2wyZTG!E2KSW2* zGRLQkQU;Oz##ie-Z4fI)WSRxn$(ZcD;TL+;^r=a4(G~H3ZhK$lSXZj?cvyY8%d9JM zzc3#pD^W_QnWy#rx#;c&N@sqHhrnHRmj#i;s%zLm6SE(n&BWpd&f7>XnjV}OlZntI70fq%8~9<7 zMYaw`E-rp49-oC1N_uZTo)Cu%RR2QWdHpzQIcNsoDp`3xfP+`gI?tVQZ4X={qU?(n zV>0ASES^Xuc;9JBji{)RnFL(Lez;8XbB1uWaMp@p?7xhXk6V#!6B@aP4Rz7-K%a>i z?fvf}va_DGUXlI#4--`A3qK7J?-HwnG7O~H2;zR~RLW)_^#La!=}+>KW#anZ{|^D3 B7G?kd literal 0 HcmV?d00001 diff --git a/img/glyphicons-halflings.png b/img/glyphicons-halflings.png new file mode 100644 index 0000000000000000000000000000000000000000..a9969993201f9cee63cf9f49217646347297b643 GIT binary patch literal 12799 zcma*OWmH^Ivn@*S;K3nSf_t!#;0f+&pm7Po8`nk}2q8f5;M%x$SdAkd9FAvlc$ zx660V9e3Ox@4WZ^?7jZ%QFGU-T~%||Ug4iK6bbQY@zBuF2$hxOw9wF=A)nUSxR_5@ zEX>HBryGrjyuOFFv$Y4<+|3H@gQfEqD<)+}a~mryD|1U9*I_FOG&F%+Ww{SJ-V2BR zjt<81Ek$}Yb*95D4RS0HCps|uLyovt;P05hchQb-u2bzLtmog&f2}1VlNhxXV);S9 zM2buBg~!q9PtF)&KGRgf3#z7B(hm5WlNClaCWFs!-P!4-u*u5+=+D|ZE9e`KvhTHT zJBnLwGM%!u&vlE%1ytJ=!xt~y_YkFLQb6bS!E+s8l7PiPGSt9xrmg?LV&&SL?J~cI zS(e9TF1?SGyh+M_p@o1dyWu7o7_6p;N6hO!;4~ z2B`I;y`;$ZdtBpvK5%oQ^p4eR2L)BH>B$FQeC*t)c`L71gXHPUa|vyu`Bnz)H$ZcXGve(}XvR!+*8a>BLV;+ryG1kt0=)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-Fb}tannKCv>y~^`r|(1Q9;+sZlYf3XPSX|^gR01UFtu$B*R;$sPZdIZShRr>|b@J z;#G{EdoY+O;REEjQ}X7_YzWLO+Ey3>a_KDe1CjSe| z6arqcEZ)CX!8r(si`dqbF$uu&pnf^Np{1f*TdJ`r2;@SaZ z#hb4xlaCA@Pwqj#LlUEe5L{I$k(Zj$d3(~)u(F%&xb8={N9hKxlZIO1ABsM{Mt|)2 zJ^t9Id;?%4PfR4&Ph9B9cFK~@tG3wlFW-0fXZS_L4U*EiAA%+`h%q2^6BCC;t0iO4V=s4Qug{M|iDV@s zC7|ef-dxiR7T&Mpre!%hiUhHM%3Qxi$Lzw6&(Tvlx9QA_7LhYq<(o~=Y>3ka-zrQa zhGpfFK@)#)rtfz61w35^sN1=IFw&Oc!Nah+8@qhJ0UEGr;JplaxOGI82OVqZHsqfX ze1}r{jy;G?&}Da}a7>SCDsFDuzuseeCKof|Dz2BPsP8? zY;a)Tkr2P~0^2BeO?wnzF_Ul-ekY=-w26VnU%U3f19Z-pj&2 z4J_a|o4Dci+MO)mPQIM>kdPG1xydiR9@#8m zh27D7GF{p|a{8({Q-Pr-;#jV{2zHR>lGoFtIfIpoMo?exuQyX_A;;l0AP4!)JEM$EwMInZkj+8*IHP4vKRd zKx_l-i*>A*C@{u%ct`y~s6MWAfO{@FPIX&sg8H{GMDc{4M3%$@c8&RAlw0-R<4DO3 trJqdc$mBpWeznn?E0M$F`|3v=`3%T2A17h;rxP7$%JLd=6(2u;`(N3pt&so# literal 0 HcmV?d00001 diff --git a/index.html b/index.html new file mode 100644 index 0000000..ba92d50 --- /dev/null +++ b/index.html @@ -0,0 +1,564 @@ + + + + + + Index - Deployd Docs + + + + + + + + + + + + + + + + + +

+ + + +
+ +
+
+
+

Quick Start #

+ +

Get Deployd up and running and build your first API with the getting started guide.

Example Apps #

+ +

Check out the examples to see how Deployd APIs are built.

Guides #

+ +

Complete guides describing the core concepts needed to build APIs with Deployd, including accessing collections, authenticating users, and using modules.

APIs #

+ +

A complete list of APIs available when developing a Deployd app.

+
+
+
+

Deployd Docs - Table of Contents

+ + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + +
+
+

Feedback

+

Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.

+
+
+

Edit or Download these Docs

+

This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!

+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/javascripts/app.js b/javascripts/app.js new file mode 100644 index 0000000..87d5d10 --- /dev/null +++ b/javascripts/app.js @@ -0,0 +1,57 @@ +(function () { + function queryParam(name) { + name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); + var regexS = "[\\?&]" + name + "=([^&#]*)"; + var regex = new RegExp(regexS); + var results = regex.exec(window.location.search); + if(results == null) + return ""; + else + return decodeURIComponent(results[1].replace(/\+/g, " ")); + } + + // highlight query + var q = queryParam('q'); + if(q) { + var $bdy = $('.section, #search-results'); + var words = q.split(/\s+/); + for(var i = 0; i < words.length; i++) { + if(words[i] && words[i].length > 2) $bdy.highlight(words[i]); + } + } + + $(function () { + // fix for scroll + + function fixScroll() { + var $a = $('a[name="' + window.location.hash.replace('#', '') + '"]'); + if($a.length) { + setTimeout(function () { + $(window).scrollTop($a.eq(0).parent('.section').offset().top - 85); + + $a.eq(0).parent('.section').addClass('linked'); + }, 1); + } + } + if(window.location.hash) { + fixScroll(); + } + + $('a[href]').click(function() { + var href = $(this).attr('href'); + + if (href.indexOf('#') !== -1) { + setTimeout(function() { + $('.section.linked').removeClass('linked'); + fixScroll(); + }, 1); + } + }); + + //prettify + $('.section pre').addClass('prettyprint'); + prettyPrint(); + }); + +})(); + diff --git a/javascripts/libs/angular-sanitize.js b/javascripts/libs/angular-sanitize.js new file mode 100644 index 0000000..d87dc7a --- /dev/null +++ b/javascripts/libs/angular-sanitize.js @@ -0,0 +1,532 @@ +/** + * @license AngularJS v1.0.1 + * (c) 2010-2012 Google, Inc. http://angularjs.org + * License: MIT + */ +(function(window, angular, undefined) { +'use strict'; + +/** + * @ngdoc overview + * @name ngSanitize + * @description + */ + +/* + * HTML Parser By Misko Hevery (misko@hevery.com) + * based on: HTML Parser By John Resig (ejohn.org) + * Original code by Erik Arvidsson, Mozilla Public License + * http://erik.eae.net/simplehtmlparser/simplehtmlparser.js + * + * // Use like so: + * htmlParser(htmlString, { + * start: function(tag, attrs, unary) {}, + * end: function(tag) {}, + * chars: function(text) {}, + * comment: function(text) {} + * }); + * + */ + + +/** + * @ngdoc service + * @name ngSanitize.$sanitize + * @function + * + * @description + * The input is sanitized by parsing the html into tokens. All safe tokens (from a whitelist) are + * then serialized back to properly escaped html string. This means that no unsafe input can make + * it into the returned string, however, since our parser is more strict than a typical browser + * parser, it's possible that some obscure input, which would be recognized as valid HTML by a + * browser, won't make it through the sanitizer. + * + * @param {string} html Html input. + * @returns {string} Sanitized html. + * + * @example + + + +
+ Snippet: + + + + + + + + + + + + + + + + + + + + + +
FilterSourceRendered
html filter +
<div ng-bind-html="snippet">
</div>
+
+
+
no filter
<div ng-bind="snippet">
</div>
unsafe html filter
<div ng-bind-html-unsafe="snippet">
</div>
+
+
+ + it('should sanitize the html snippet ', function() { + expect(using('#html-filter').element('div').html()). + toBe('

an html\nclick here\nsnippet

'); + }); + + it('should escape snippet without any filter', function() { + expect(using('#escaped-html').element('div').html()). + toBe("<p style=\"color:blue\">an html\n" + + "<em onmouseover=\"this.textContent='PWN3D!'\">click here</em>\n" + + "snippet</p>"); + }); + + it('should inline raw snippet if filtered as unsafe', function() { + expect(using('#html-unsafe-filter').element("div").html()). + toBe("

an html\n" + + "click here\n" + + "snippet

"); + }); + + it('should update', function() { + input('snippet').enter('new text'); + expect(using('#html-filter').binding('snippet')).toBe('new text'); + expect(using('#escaped-html').element('div').html()).toBe("new <b>text</b>"); + expect(using('#html-unsafe-filter').binding("snippet")).toBe('new text'); + }); +
+
+ */ +var $sanitize = function(html) { + var buf = []; + htmlParser(html, htmlSanitizeWriter(buf)); + return buf.join(''); +}; + + +// Regular Expressions for parsing tags and attributes +var START_TAG_REGEXP = /^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*>/, + END_TAG_REGEXP = /^<\s*\/\s*([\w:-]+)[^>]*>/, + ATTR_REGEXP = /([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g, + BEGIN_TAG_REGEXP = /^/g, + CDATA_REGEXP = //g, + URI_REGEXP = /^((ftp|https?):\/\/|mailto:|#)/, + NON_ALPHANUMERIC_REGEXP = /([^\#-~| |!])/g; // Match everything outside of normal chars and " (quote character) + + +// Good source of info about elements and attributes +// http://dev.w3.org/html5/spec/Overview.html#semantics +// http://simon.html5.org/html-elements + +// Safe Void Elements - HTML5 +// http://dev.w3.org/html5/spec/Overview.html#void-elements +var voidElements = makeMap("area,br,col,hr,img,wbr"); + +// Elements that you can, intentionally, leave open (and which close themselves) +// http://dev.w3.org/html5/spec/Overview.html#optional-tags +var optionalEndTagBlockElements = makeMap("colgroup,dd,dt,li,p,tbody,td,tfoot,th,thead,tr"), + optionalEndTagInlineElements = makeMap("rp,rt"), + optionalEndTagElements = angular.extend({}, optionalEndTagInlineElements, optionalEndTagBlockElements); + +// Safe Block Elements - HTML5 +var blockElements = angular.extend({}, optionalEndTagBlockElements, makeMap("address,article,aside," + + "blockquote,caption,center,del,dir,div,dl,figure,figcaption,footer,h1,h2,h3,h4,h5,h6," + + "header,hgroup,hr,ins,map,menu,nav,ol,pre,script,section,table,ul")); + +// Inline Elements - HTML5 +var inlineElements = angular.extend({}, optionalEndTagInlineElements, makeMap("a,abbr,acronym,b,bdi,bdo," + + "big,br,cite,code,del,dfn,em,font,i,img,ins,kbd,label,map,mark,q,ruby,rp,rt,s,samp,small," + + "span,strike,strong,sub,sup,time,tt,u,var")); + + +// Special Elements (can contain anything) +var specialElements = makeMap("script,style"); + +var validElements = angular.extend({}, voidElements, blockElements, inlineElements, optionalEndTagElements); + +//Attributes that have href and hence need to be sanitized +var uriAttrs = makeMap("background,cite,href,longdesc,src,usemap"); +var validAttrs = angular.extend({}, uriAttrs, makeMap( + 'abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,'+ + 'color,cols,colspan,compact,coords,dir,face,headers,height,hreflang,hspace,'+ + 'ismap,lang,language,nohref,nowrap,rel,rev,rows,rowspan,rules,'+ + 'scope,scrolling,shape,span,start,summary,target,title,type,'+ + 'valign,value,vspace,width')); + +function makeMap(str) { + var obj = {}, items = str.split(','), i; + for (i = 0; i < items.length; i++) obj[items[i]] = true; + return obj; +} + + +/** + * @example + * htmlParser(htmlString, { + * start: function(tag, attrs, unary) {}, + * end: function(tag) {}, + * chars: function(text) {}, + * comment: function(text) {} + * }); + * + * @param {string} html string + * @param {object} handler + */ +function htmlParser( html, handler ) { + var index, chars, match, stack = [], last = html; + stack.last = function() { return stack[ stack.length - 1 ]; }; + + while ( html ) { + chars = true; + + // Make sure we're not in a script or style element + if ( !stack.last() || !specialElements[ stack.last() ] ) { + + // Comment + if ( html.indexOf(""); + + if ( index >= 0 ) { + if (handler.comment) handler.comment( html.substring( 4, index ) ); + html = html.substring( index + 3 ); + chars = false; + } + + // end tag + } else if ( BEGING_END_TAGE_REGEXP.test(html) ) { + match = html.match( END_TAG_REGEXP ); + + if ( match ) { + html = html.substring( match[0].length ); + match[0].replace( END_TAG_REGEXP, parseEndTag ); + chars = false; + } + + // start tag + } else if ( BEGIN_TAG_REGEXP.test(html) ) { + match = html.match( START_TAG_REGEXP ); + + if ( match ) { + html = html.substring( match[0].length ); + match[0].replace( START_TAG_REGEXP, parseStartTag ); + chars = false; + } + } + + if ( chars ) { + index = html.indexOf("<"); + + var text = index < 0 ? html : html.substring( 0, index ); + html = index < 0 ? "" : html.substring( index ); + + if (handler.chars) handler.chars( decodeEntities(text) ); + } + + } else { + html = html.replace(new RegExp("(.*)<\\s*\\/\\s*" + stack.last() + "[^>]*>", 'i'), function(all, text){ + text = text. + replace(COMMENT_REGEXP, "$1"). + replace(CDATA_REGEXP, "$1"); + + if (handler.chars) handler.chars( decodeEntities(text) ); + + return ""; + }); + + parseEndTag( "", stack.last() ); + } + + if ( html == last ) { + throw "Parse Error: " + html; + } + last = html; + } + + // Clean up any remaining tags + parseEndTag(); + + function parseStartTag( tag, tagName, rest, unary ) { + tagName = angular.lowercase(tagName); + if ( blockElements[ tagName ] ) { + while ( stack.last() && inlineElements[ stack.last() ] ) { + parseEndTag( "", stack.last() ); + } + } + + if ( optionalEndTagElements[ tagName ] && stack.last() == tagName ) { + parseEndTag( "", tagName ); + } + + unary = voidElements[ tagName ] || !!unary; + + if ( !unary ) + stack.push( tagName ); + + var attrs = {}; + + rest.replace(ATTR_REGEXP, function(match, name, doubleQuotedValue, singleQoutedValue, unqoutedValue) { + var value = doubleQuotedValue + || singleQoutedValue + || unqoutedValue + || ''; + + attrs[name] = decodeEntities(value); + }); + if (handler.start) handler.start( tagName, attrs, unary ); + } + + function parseEndTag( tag, tagName ) { + var pos = 0, i; + tagName = angular.lowercase(tagName); + if ( tagName ) + // Find the closest opened tag of the same type + for ( pos = stack.length - 1; pos >= 0; pos-- ) + if ( stack[ pos ] == tagName ) + break; + + if ( pos >= 0 ) { + // Close all the open elements, up the stack + for ( i = stack.length - 1; i >= pos; i-- ) + if (handler.end) handler.end( stack[ i ] ); + + // Remove the open elements from the stack + stack.length = pos; + } + } +} + +/** + * decodes all entities into regular string + * @param value + * @returns {string} A string with decoded entities. + */ +var hiddenPre=document.createElement("pre"); +function decodeEntities(value) { + hiddenPre.innerHTML=value.replace(//g, '>'); +} + +/** + * create an HTML/XML writer which writes to buffer + * @param {Array} buf use buf.jain('') to get out sanitized html string + * @returns {object} in the form of { + * start: function(tag, attrs, unary) {}, + * end: function(tag) {}, + * chars: function(text) {}, + * comment: function(text) {} + * } + */ +function htmlSanitizeWriter(buf){ + var ignore = false; + var out = angular.bind(buf, buf.push); + return { + start: function(tag, attrs, unary){ + tag = angular.lowercase(tag); + if (!ignore && specialElements[tag]) { + ignore = tag; + } + if (!ignore && validElements[tag] == true) { + out('<'); + out(tag); + angular.forEach(attrs, function(value, key){ + var lkey=angular.lowercase(key); + if (validAttrs[lkey]==true && (uriAttrs[lkey]!==true || value.match(URI_REGEXP))) { + out(' '); + out(key); + out('="'); + out(encodeEntities(value)); + out('"'); + } + }); + out(unary ? '/>' : '>'); + } + }, + end: function(tag){ + tag = angular.lowercase(tag); + if (!ignore && validElements[tag] == true) { + out(''); + } + if (tag == ignore) { + ignore = false; + } + }, + chars: function(chars){ + if (!ignore) { + out(encodeEntities(chars)); + } + } + }; +} + + +// define ngSanitize module and register $sanitize service +angular.module('ngSanitize', []).value('$sanitize', $sanitize); + +/** + * @ngdoc directive + * @name ngSanitize.directive:ngBindHtml + * + * @description + * Creates a binding that will sanitize the result of evaluating the `expression` with the + * {@link ngSanitize.$sanitize $sanitize} service and innerHTML the result into the current element. + * + * See {@link ngSanitize.$sanitize $sanitize} docs for examples. + * + * @element ANY + * @param {expression} ngBindHtml {@link guide/expression Expression} to evaluate. + */ +angular.module('ngSanitize').directive('ngBindHtml', ['$sanitize', function($sanitize) { + return function(scope, element, attr) { + element.addClass('ng-binding').data('$binding', attr.ngBindHtml); + scope.$watch(attr.ngBindHtml, function(value) { + value = $sanitize(value); + element.html(value || ''); + }); + }; +}]); +/** + * @ngdoc filter + * @name ngSanitize.filter:linky + * @function + * + * @description + * Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and + * plain email address links. + * + * @param {string} text Input text. + * @returns {string} Html-linkified text. + * + * @example + + + +
+ Snippet: + + + + + + + + + + + + + + + + +
FilterSourceRendered
linky filter +
<div ng-bind-html="snippet | linky">
</div>
+
+
+
no filter
<div ng-bind="snippet">
</div>
+ + + it('should linkify the snippet with urls', function() { + expect(using('#linky-filter').binding('snippet | linky')). + toBe('Pretty text with some links: ' + + 'http://angularjs.org/, ' + + 'us@somewhere.org, ' + + 'another@somewhere.org, ' + + 'and one more: ftp://127.0.0.1/.'); + }); + + it ('should not linkify snippet without the linky filter', function() { + expect(using('#escaped-html').binding('snippet')). + toBe("Pretty text with some links:\n" + + "http://angularjs.org/,\n" + + "mailto:us@somewhere.org,\n" + + "another@somewhere.org,\n" + + "and one more: ftp://127.0.0.1/."); + }); + + it('should update', function() { + input('snippet').enter('new http://link.'); + expect(using('#linky-filter').binding('snippet | linky')). + toBe('new http://link.'); + expect(using('#escaped-html').binding('snippet')).toBe('new http://link.'); + }); + + + */ +angular.module('ngSanitize').filter('linky', function() { + var LINKY_URL_REGEXP = /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s\.\;\,\(\)\{\}\<\>]/, + MAILTO_REGEXP = /^mailto:/; + + return function(text) { + if (!text) return text; + var match; + var raw = text; + var html = []; + // TODO(vojta): use $sanitize instead + var writer = htmlSanitizeWriter(html); + var url; + var i; + while ((match = raw.match(LINKY_URL_REGEXP))) { + // We can not end in these as they are sometimes found at the end of the sentence + url = match[0]; + // if we did not match ftp/http/mailto then assume mailto + if (match[2] == match[3]) url = 'mailto:' + url; + i = match.index; + writer.chars(raw.substr(0, i)); + writer.start('a', {href:url}); + writer.chars(match[0].replace(MAILTO_REGEXP, '')); + writer.end('a'); + raw = raw.substring(i + match[0].length); + } + writer.chars(raw); + return html.join(''); + }; +}); + +})(window, window.angular); \ No newline at end of file diff --git a/javascripts/libs/angular.js b/javascripts/libs/angular.js new file mode 100644 index 0000000..6c214b2 --- /dev/null +++ b/javascripts/libs/angular.js @@ -0,0 +1,14401 @@ +/** + * @license AngularJS v1.0.2 + * (c) 2010-2012 Google, Inc. http://angularjs.org + * License: MIT + */ +(function(window, document, undefined) { +'use strict'; + +//////////////////////////////////// + +/** + * @ngdoc function + * @name angular.lowercase + * @function + * + * @description Converts the specified string to lowercase. + * @param {string} string String to be converted to lowercase. + * @returns {string} Lowercased string. + */ +var lowercase = function(string){return isString(string) ? string.toLowerCase() : string;}; + + +/** + * @ngdoc function + * @name angular.uppercase + * @function + * + * @description Converts the specified string to uppercase. + * @param {string} string String to be converted to uppercase. + * @returns {string} Uppercased string. + */ +var uppercase = function(string){return isString(string) ? string.toUpperCase() : string;}; + + +var manualLowercase = function(s) { + return isString(s) + ? s.replace(/[A-Z]/g, function(ch) {return fromCharCode(ch.charCodeAt(0) | 32);}) + : s; +}; +var manualUppercase = function(s) { + return isString(s) + ? s.replace(/[a-z]/g, function(ch) {return fromCharCode(ch.charCodeAt(0) & ~32);}) + : s; +}; + + +// String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish +// locale, for this reason we need to detect this case and redefine lowercase/uppercase methods +// with correct but slower alternatives. +if ('i' !== 'I'.toLowerCase()) { + lowercase = manualLowercase; + uppercase = manualUppercase; +} + +function fromCharCode(code) {return String.fromCharCode(code);} + + +var Error = window.Error, + /** holds major version number for IE or NaN for real browsers */ + msie = int((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1]), + jqLite, // delay binding since jQuery could be loaded after us. + jQuery, // delay binding + slice = [].slice, + push = [].push, + toString = Object.prototype.toString, + + /** @name angular */ + angular = window.angular || (window.angular = {}), + angularModule, + nodeName_, + uid = ['0', '0', '0']; + +/** + * @ngdoc function + * @name angular.forEach + * @function + * + * @description + * Invokes the `iterator` function once for each item in `obj` collection, which can be either an + * object or an array. The `iterator` function is invoked with `iterator(value, key)`, where `value` + * is the value of an object property or an array element and `key` is the object property key or + * array element index. Specifying a `context` for the function is optional. + * + * Note: this function was previously known as `angular.foreach`. + * +
+     var values = {name: 'misko', gender: 'male'};
+     var log = [];
+     angular.forEach(values, function(value, key){
+       this.push(key + ': ' + value);
+     }, log);
+     expect(log).toEqual(['name: misko', 'gender:male']);
+   
+ * + * @param {Object|Array} obj Object to iterate over. + * @param {Function} iterator Iterator function. + * @param {Object=} context Object to become context (`this`) for the iterator function. + * @returns {Object|Array} Reference to `obj`. + */ +function forEach(obj, iterator, context) { + var key; + if (obj) { + if (isFunction(obj)){ + for (key in obj) { + if (key != 'prototype' && key != 'length' && key != 'name' && obj.hasOwnProperty(key)) { + iterator.call(context, obj[key], key); + } + } + } else if (obj.forEach && obj.forEach !== forEach) { + obj.forEach(iterator, context); + } else if (isObject(obj) && isNumber(obj.length)) { + for (key = 0; key < obj.length; key++) + iterator.call(context, obj[key], key); + } else { + for (key in obj) { + if (obj.hasOwnProperty(key)) { + iterator.call(context, obj[key], key); + } + } + } + } + return obj; +} + +function sortedKeys(obj) { + var keys = []; + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + keys.push(key); + } + } + return keys.sort(); +} + +function forEachSorted(obj, iterator, context) { + var keys = sortedKeys(obj); + for ( var i = 0; i < keys.length; i++) { + iterator.call(context, obj[keys[i]], keys[i]); + } + return keys; +} + + +/** + * when using forEach the params are value, key, but it is often useful to have key, value. + * @param {function(string, *)} iteratorFn + * @returns {function(*, string)} + */ +function reverseParams(iteratorFn) { + return function(value, key) { iteratorFn(key, value) }; +} + +/** + * A consistent way of creating unique IDs in angular. The ID is a sequence of alpha numeric + * characters such as '012ABC'. The reason why we are not using simply a number counter is that + * the number string gets longer over time, and it can also overflow, where as the the nextId + * will grow much slower, it is a string, and it will never overflow. + * + * @returns an unique alpha-numeric string + */ +function nextUid() { + var index = uid.length; + var digit; + + while(index) { + index--; + digit = uid[index].charCodeAt(0); + if (digit == 57 /*'9'*/) { + uid[index] = 'A'; + return uid.join(''); + } + if (digit == 90 /*'Z'*/) { + uid[index] = '0'; + } else { + uid[index] = String.fromCharCode(digit + 1); + return uid.join(''); + } + } + uid.unshift('0'); + return uid.join(''); +} + +/** + * @ngdoc function + * @name angular.extend + * @function + * + * @description + * Extends the destination object `dst` by copying all of the properties from the `src` object(s) + * to `dst`. You can specify multiple `src` objects. + * + * @param {Object} dst Destination object. + * @param {...Object} src Source object(s). + */ +function extend(dst) { + forEach(arguments, function(obj){ + if (obj !== dst) { + forEach(obj, function(value, key){ + dst[key] = value; + }); + } + }); + return dst; +} + +function int(str) { + return parseInt(str, 10); +} + + +function inherit(parent, extra) { + return extend(new (extend(function() {}, {prototype:parent}))(), extra); +} + + +/** + * @ngdoc function + * @name angular.noop + * @function + * + * @description + * A function that performs no operations. This function can be useful when writing code in the + * functional style. +
+     function foo(callback) {
+       var result = calculateResult();
+       (callback || angular.noop)(result);
+     }
+   
+ */ +function noop() {} +noop.$inject = []; + + +/** + * @ngdoc function + * @name angular.identity + * @function + * + * @description + * A function that returns its first argument. This function is useful when writing code in the + * functional style. + * +
+     function transformer(transformationFn, value) {
+       return (transformationFn || identity)(value);
+     };
+   
+ */ +function identity($) {return $;} +identity.$inject = []; + + +function valueFn(value) {return function() {return value;};} + +/** + * @ngdoc function + * @name angular.isUndefined + * @function + * + * @description + * Determines if a reference is undefined. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is undefined. + */ +function isUndefined(value){return typeof value == 'undefined';} + + +/** + * @ngdoc function + * @name angular.isDefined + * @function + * + * @description + * Determines if a reference is defined. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is defined. + */ +function isDefined(value){return typeof value != 'undefined';} + + +/** + * @ngdoc function + * @name angular.isObject + * @function + * + * @description + * Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not + * considered to be objects. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is an `Object` but not `null`. + */ +function isObject(value){return value != null && typeof value == 'object';} + + +/** + * @ngdoc function + * @name angular.isString + * @function + * + * @description + * Determines if a reference is a `String`. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a `String`. + */ +function isString(value){return typeof value == 'string';} + + +/** + * @ngdoc function + * @name angular.isNumber + * @function + * + * @description + * Determines if a reference is a `Number`. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a `Number`. + */ +function isNumber(value){return typeof value == 'number';} + + +/** + * @ngdoc function + * @name angular.isDate + * @function + * + * @description + * Determines if a value is a date. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a `Date`. + */ +function isDate(value){ + return toString.apply(value) == '[object Date]'; +} + + +/** + * @ngdoc function + * @name angular.isArray + * @function + * + * @description + * Determines if a reference is an `Array`. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is an `Array`. + */ +function isArray(value) { + return toString.apply(value) == '[object Array]'; +} + + +/** + * @ngdoc function + * @name angular.isFunction + * @function + * + * @description + * Determines if a reference is a `Function`. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a `Function`. + */ +function isFunction(value){return typeof value == 'function';} + + +/** + * Checks if `obj` is a window object. + * + * @private + * @param {*} obj Object to check + * @returns {boolean} True if `obj` is a window obj. + */ +function isWindow(obj) { + return obj && obj.document && obj.location && obj.alert && obj.setInterval; +} + + +function isScope(obj) { + return obj && obj.$evalAsync && obj.$watch; +} + + +function isFile(obj) { + return toString.apply(obj) === '[object File]'; +} + + +function isBoolean(value) { + return typeof value == 'boolean'; +} + + +function trim(value) { + return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; +} + +/** + * @ngdoc function + * @name angular.isElement + * @function + * + * @description + * Determines if a reference is a DOM element (or wrapped jQuery element). + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element). + */ +function isElement(node) { + return node && + (node.nodeName // we are a direct element + || (node.bind && node.find)); // we have a bind and find method part of jQuery API +} + +/** + * @param str 'key1,key2,...' + * @returns {object} in the form of {key1:true, key2:true, ...} + */ +function makeMap(str){ + var obj = {}, items = str.split(","), i; + for ( i = 0; i < items.length; i++ ) + obj[ items[i] ] = true; + return obj; +} + + +if (msie < 9) { + nodeName_ = function(element) { + element = element.nodeName ? element : element[0]; + return (element.scopeName && element.scopeName != 'HTML') + ? uppercase(element.scopeName + ':' + element.nodeName) : element.nodeName; + }; +} else { + nodeName_ = function(element) { + return element.nodeName ? element.nodeName : element[0].nodeName; + }; +} + + +function map(obj, iterator, context) { + var results = []; + forEach(obj, function(value, index, list) { + results.push(iterator.call(context, value, index, list)); + }); + return results; +} + + +/** + * @description + * Determines the number of elements in an array, the number of properties an object has, or + * the length of a string. + * + * Note: This function is used to augment the Object type in Angular expressions. See + * {@link angular.Object} for more information about Angular arrays. + * + * @param {Object|Array|string} obj Object, array, or string to inspect. + * @param {boolean} [ownPropsOnly=false] Count only "own" properties in an object + * @returns {number} The size of `obj` or `0` if `obj` is neither an object nor an array. + */ +function size(obj, ownPropsOnly) { + var size = 0, key; + + if (isArray(obj) || isString(obj)) { + return obj.length; + } else if (isObject(obj)){ + for (key in obj) + if (!ownPropsOnly || obj.hasOwnProperty(key)) + size++; + } + + return size; +} + + +function includes(array, obj) { + return indexOf(array, obj) != -1; +} + +function indexOf(array, obj) { + if (array.indexOf) return array.indexOf(obj); + + for ( var i = 0; i < array.length; i++) { + if (obj === array[i]) return i; + } + return -1; +} + +function arrayRemove(array, value) { + var index = indexOf(array, value); + if (index >=0) + array.splice(index, 1); + return value; +} + +function isLeafNode (node) { + if (node) { + switch (node.nodeName) { + case "OPTION": + case "PRE": + case "TITLE": + return true; + } + } + return false; +} + +/** + * @ngdoc function + * @name angular.copy + * @function + * + * @description + * Creates a deep copy of `source`, which should be an object or an array. + * + * * If no destination is supplied, a copy of the object or array is created. + * * If a destination is provided, all of its elements (for array) or properties (for objects) + * are deleted and then all elements/properties from the source are copied to it. + * * If `source` is not an object or array, `source` is returned. + * + * Note: this function is used to augment the Object type in Angular expressions. See + * {@link ng.$filter} for more information about Angular arrays. + * + * @param {*} source The source that will be used to make a copy. + * Can be any type, including primitives, `null`, and `undefined`. + * @param {(Object|Array)=} destination Destination into which the source is copied. If + * provided, must be of the same type as `source`. + * @returns {*} The copy or updated `destination`, if `destination` was specified. + */ +function copy(source, destination){ + if (isWindow(source) || isScope(source)) throw Error("Can't copy Window or Scope"); + if (!destination) { + destination = source; + if (source) { + if (isArray(source)) { + destination = copy(source, []); + } else if (isDate(source)) { + destination = new Date(source.getTime()); + } else if (isObject(source)) { + destination = copy(source, {}); + } + } + } else { + if (source === destination) throw Error("Can't copy equivalent objects or arrays"); + if (isArray(source)) { + while(destination.length) { + destination.pop(); + } + for ( var i = 0; i < source.length; i++) { + destination.push(copy(source[i])); + } + } else { + forEach(destination, function(value, key){ + delete destination[key]; + }); + for ( var key in source) { + destination[key] = copy(source[key]); + } + } + } + return destination; +} + +/** + * Create a shallow copy of an object + */ +function shallowCopy(src, dst) { + dst = dst || {}; + + for(var key in src) { + if (src.hasOwnProperty(key) && key.substr(0, 2) !== '$$') { + dst[key] = src[key]; + } + } + + return dst; +} + + +/** + * @ngdoc function + * @name angular.equals + * @function + * + * @description + * Determines if two objects or two values are equivalent. Supports value types, arrays and + * objects. + * + * Two objects or values are considered equivalent if at least one of the following is true: + * + * * Both objects or values pass `===` comparison. + * * Both objects or values are of the same type and all of their properties pass `===` comparison. + * * Both values are NaN. (In JavasScript, NaN == NaN => false. But we consider two NaN as equal) + * + * During a property comparision, properties of `function` type and properties with names + * that begin with `$` are ignored. + * + * Scope and DOMWindow objects are being compared only be identify (`===`). + * + * @param {*} o1 Object or value to compare. + * @param {*} o2 Object or value to compare. + * @returns {boolean} True if arguments are equal. + */ +function equals(o1, o2) { + if (o1 === o2) return true; + if (o1 === null || o2 === null) return false; + if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN + var t1 = typeof o1, t2 = typeof o2, length, key, keySet; + if (t1 == t2) { + if (t1 == 'object') { + if (isArray(o1)) { + if ((length = o1.length) == o2.length) { + for(key=0; key 2 ? sliceArgs(arguments, 2) : []; + if (isFunction(fn) && !(fn instanceof RegExp)) { + return curryArgs.length + ? function() { + return arguments.length + ? fn.apply(self, curryArgs.concat(slice.call(arguments, 0))) + : fn.apply(self, curryArgs); + } + : function() { + return arguments.length + ? fn.apply(self, arguments) + : fn.call(self); + }; + } else { + // in IE, native methods are not functions so they cannot be bound (note: they don't need to be) + return fn; + } +} + + +function toJsonReplacer(key, value) { + var val = value; + + if (/^\$+/.test(key)) { + val = undefined; + } else if (isWindow(value)) { + val = '$WINDOW'; + } else if (value && document === value) { + val = '$DOCUMENT'; + } else if (isScope(value)) { + val = '$SCOPE'; + } + + return val; +} + + +/** + * @ngdoc function + * @name angular.toJson + * @function + * + * @description + * Serializes input into a JSON-formatted string. + * + * @param {Object|Array|Date|string|number} obj Input to be serialized into JSON. + * @param {boolean=} pretty If set to true, the JSON output will contain newlines and whitespace. + * @returns {string} Jsonified string representing `obj`. + */ +function toJson(obj, pretty) { + return JSON.stringify(obj, toJsonReplacer, pretty ? ' ' : null); +} + + +/** + * @ngdoc function + * @name angular.fromJson + * @function + * + * @description + * Deserializes a JSON string. + * + * @param {string} json JSON string to deserialize. + * @returns {Object|Array|Date|string|number} Deserialized thingy. + */ +function fromJson(json) { + return isString(json) + ? JSON.parse(json) + : json; +} + + +function toBoolean(value) { + if (value && value.length !== 0) { + var v = lowercase("" + value); + value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]'); + } else { + value = false; + } + return value; +} + +/** + * @returns {string} Returns the string representation of the element. + */ +function startingTag(element) { + element = jqLite(element).clone(); + try { + // turns out IE does not let you set .html() on elements which + // are not allowed to have children. So we just ignore it. + element.html(''); + } catch(e) {} + return jqLite('
').append(element).html(). + match(/^(<[^>]+>)/)[1]. + replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); }); +} + + +///////////////////////////////////////////////// + +/** + * Parses an escaped url query string into key-value pairs. + * @returns Object.<(string|boolean)> + */ +function parseKeyValue(/**string*/keyValue) { + var obj = {}, key_value, key; + forEach((keyValue || "").split('&'), function(keyValue){ + if (keyValue) { + key_value = keyValue.split('='); + key = decodeURIComponent(key_value[0]); + obj[key] = isDefined(key_value[1]) ? decodeURIComponent(key_value[1]) : true; + } + }); + return obj; +} + +function toKeyValue(obj) { + var parts = []; + forEach(obj, function(value, key) { + parts.push(encodeUriQuery(key, true) + (value === true ? '' : '=' + encodeUriQuery(value, true))); + }); + return parts.length ? parts.join('&') : ''; +} + + +/** + * We need our custom mehtod because encodeURIComponent is too agressive and doesn't follow + * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path + * segments: + * segment = *pchar + * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * pct-encoded = "%" HEXDIG HEXDIG + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" + */ +function encodeUriSegment(val) { + return encodeUriQuery(val, true). + replace(/%26/gi, '&'). + replace(/%3D/gi, '='). + replace(/%2B/gi, '+'); +} + + +/** + * This method is intended for encoding *key* or *value* parts of query component. We need a custom + * method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be + * encoded per http://tools.ietf.org/html/rfc3986: + * query = *( pchar / "/" / "?" ) + * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * pct-encoded = "%" HEXDIG HEXDIG + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" + */ +function encodeUriQuery(val, pctEncodeSpaces) { + return encodeURIComponent(val). + replace(/%40/gi, '@'). + replace(/%3A/gi, ':'). + replace(/%24/g, '$'). + replace(/%2C/gi, ','). + replace((pctEncodeSpaces ? null : /%20/g), '+'); +} + + +/** + * @ngdoc directive + * @name ng.directive:ngApp + * + * @element ANY + * @param {angular.Module} ngApp on optional application + * {@link angular.module module} name to load. + * + * @description + * + * Use this directive to auto-bootstrap on application. Only + * one directive can be used per HTML document. The directive + * designates the root of the application and is typically placed + * ot the root of the page. + * + * In the example below if the `ngApp` directive would not be placed + * on the `html` element then the document would not be compiled + * and the `{{ 1+2 }}` would not be resolved to `3`. + * + * `ngApp` is the easiest way to bootstrap an application. + * + + + I can add: 1 + 2 = {{ 1+2 }} + + + * + */ +function angularInit(element, bootstrap) { + var elements = [element], + appElement, + module, + names = ['ng:app', 'ng-app', 'x-ng-app', 'data-ng-app'], + NG_APP_CLASS_REGEXP = /\sng[:\-]app(:\s*([\w\d_]+);?)?\s/; + + function append(element) { + element && elements.push(element); + } + + forEach(names, function(name) { + names[name] = true; + append(document.getElementById(name)); + name = name.replace(':', '\\:'); + if (element.querySelectorAll) { + forEach(element.querySelectorAll('.' + name), append); + forEach(element.querySelectorAll('.' + name + '\\:'), append); + forEach(element.querySelectorAll('[' + name + ']'), append); + } + }); + + forEach(elements, function(element) { + if (!appElement) { + var className = ' ' + element.className + ' '; + var match = NG_APP_CLASS_REGEXP.exec(className); + if (match) { + appElement = element; + module = (match[2] || '').replace(/\s+/g, ','); + } else { + forEach(element.attributes, function(attr) { + if (!appElement && names[attr.name]) { + appElement = element; + module = attr.value; + } + }); + } + } + }); + if (appElement) { + bootstrap(appElement, module ? [module] : []); + } +} + +/** + * @ngdoc function + * @name angular.bootstrap + * @description + * Use this function to manually start up angular application. + * + * See: {@link guide/bootstrap Bootstrap} + * + * @param {Element} element DOM element which is the root of angular application. + * @param {Array=} modules an array of module declarations. See: {@link angular.module modules} + * @returns {AUTO.$injector} Returns the newly created injector for this app. + */ +function bootstrap(element, modules) { + element = jqLite(element); + modules = modules || []; + modules.unshift(['$provide', function($provide) { + $provide.value('$rootElement', element); + }]); + modules.unshift('ng'); + var injector = createInjector(modules); + injector.invoke( + ['$rootScope', '$rootElement', '$compile', '$injector', function(scope, element, compile, injector){ + scope.$apply(function() { + element.data('$injector', injector); + compile(element)(scope); + }); + }] + ); + return injector; +} + +var SNAKE_CASE_REGEXP = /[A-Z]/g; +function snake_case(name, separator){ + separator = separator || '_'; + return name.replace(SNAKE_CASE_REGEXP, function(letter, pos) { + return (pos ? separator : '') + letter.toLowerCase(); + }); +} + +function bindJQuery() { + // bind to jQuery if present; + jQuery = window.jQuery; + // reset to jQuery or default to us. + if (jQuery) { + jqLite = jQuery; + extend(jQuery.fn, { + scope: JQLitePrototype.scope, + controller: JQLitePrototype.controller, + injector: JQLitePrototype.injector, + inheritedData: JQLitePrototype.inheritedData + }); + JQLitePatchJQueryRemove('remove', true); + JQLitePatchJQueryRemove('empty'); + JQLitePatchJQueryRemove('html'); + } else { + jqLite = JQLite; + } + angular.element = jqLite; +} + +/** + * throw error of the argument is falsy. + */ +function assertArg(arg, name, reason) { + if (!arg) { + throw new Error("Argument '" + (name || '?') + "' is " + (reason || "required")); + } + return arg; +} + +function assertArgFn(arg, name, acceptArrayAnnotation) { + if (acceptArrayAnnotation && isArray(arg)) { + arg = arg[arg.length - 1]; + } + + assertArg(isFunction(arg), name, 'not a function, got ' + + (arg && typeof arg == 'object' ? arg.constructor.name || 'Object' : typeof arg)); + return arg; +} + +/** + * @ngdoc interface + * @name angular.Module + * @description + * + * Interface for configuring angular {@link angular.module modules}. + */ + +function setupModuleLoader(window) { + + function ensure(obj, name, factory) { + return obj[name] || (obj[name] = factory()); + } + + return ensure(ensure(window, 'angular', Object), 'module', function() { + /** @type {Object.} */ + var modules = {}; + + /** + * @ngdoc function + * @name angular.module + * @description + * + * The `angular.module` is a global place for creating and registering Angular modules. All + * modules (angular core or 3rd party) that should be available to an application must be + * registered using this mechanism. + * + * + * # Module + * + * A module is a collocation of services, directives, filters, and configure information. Module + * is used to configure the {@link AUTO.$injector $injector}. + * + *
+     * // Create a new module
+     * var myModule = angular.module('myModule', []);
+     *
+     * // register a new service
+     * myModule.value('appName', 'MyCoolApp');
+     *
+     * // configure existing services inside initialization blocks.
+     * myModule.config(function($locationProvider) {
+     *   // Configure existing providers
+     *   $locationProvider.hashPrefix('!');
+     * });
+     * 
+ * + * Then you can create an injector and load your modules like this: + * + *
+     * var injector = angular.injector(['ng', 'MyModule'])
+     * 
+ * + * However it's more likely that you'll just use + * {@link ng.directive:ngApp ngApp} or + * {@link angular.bootstrap} to simplify this process for you. + * + * @param {!string} name The name of the module to create or retrieve. + * @param {Array.=} requires If specified then new module is being created. If unspecified then the + * the module is being retrieved for further configuration. + * @param {Function} configFn Option configuration function for the module. Same as + * {@link angular.Module#config Module#config()}. + * @returns {module} new module with the {@link angular.Module} api. + */ + return function module(name, requires, configFn) { + if (requires && modules.hasOwnProperty(name)) { + modules[name] = null; + } + return ensure(modules, name, function() { + if (!requires) { + throw Error('No module: ' + name); + } + + /** @type {!Array.>} */ + var invokeQueue = []; + + /** @type {!Array.} */ + var runBlocks = []; + + var config = invokeLater('$injector', 'invoke'); + + /** @type {angular.Module} */ + var moduleInstance = { + // Private state + _invokeQueue: invokeQueue, + _runBlocks: runBlocks, + + /** + * @ngdoc property + * @name angular.Module#requires + * @propertyOf angular.Module + * @returns {Array.} List of module names which must be loaded before this module. + * @description + * Holds the list of modules which the injector will load before the current module is loaded. + */ + requires: requires, + + /** + * @ngdoc property + * @name angular.Module#name + * @propertyOf angular.Module + * @returns {string} Name of the module. + * @description + */ + name: name, + + + /** + * @ngdoc method + * @name angular.Module#provider + * @methodOf angular.Module + * @param {string} name service name + * @param {Function} providerType Construction function for creating new instance of the service. + * @description + * See {@link AUTO.$provide#provider $provide.provider()}. + */ + provider: invokeLater('$provide', 'provider'), + + /** + * @ngdoc method + * @name angular.Module#factory + * @methodOf angular.Module + * @param {string} name service name + * @param {Function} providerFunction Function for creating new instance of the service. + * @description + * See {@link AUTO.$provide#factory $provide.factory()}. + */ + factory: invokeLater('$provide', 'factory'), + + /** + * @ngdoc method + * @name angular.Module#service + * @methodOf angular.Module + * @param {string} name service name + * @param {Function} constructor A constructor function that will be instantiated. + * @description + * See {@link AUTO.$provide#service $provide.service()}. + */ + service: invokeLater('$provide', 'service'), + + /** + * @ngdoc method + * @name angular.Module#value + * @methodOf angular.Module + * @param {string} name service name + * @param {*} object Service instance object. + * @description + * See {@link AUTO.$provide#value $provide.value()}. + */ + value: invokeLater('$provide', 'value'), + + /** + * @ngdoc method + * @name angular.Module#constant + * @methodOf angular.Module + * @param {string} name constant name + * @param {*} object Constant value. + * @description + * Because the constant are fixed, they get applied before other provide methods. + * See {@link AUTO.$provide#constant $provide.constant()}. + */ + constant: invokeLater('$provide', 'constant', 'unshift'), + + /** + * @ngdoc method + * @name angular.Module#filter + * @methodOf angular.Module + * @param {string} name Filter name. + * @param {Function} filterFactory Factory function for creating new instance of filter. + * @description + * See {@link ng.$filterProvider#register $filterProvider.register()}. + */ + filter: invokeLater('$filterProvider', 'register'), + + /** + * @ngdoc method + * @name angular.Module#controller + * @methodOf angular.Module + * @param {string} name Controller name. + * @param {Function} constructor Controller constructor function. + * @description + * See {@link ng.$controllerProvider#register $controllerProvider.register()}. + */ + controller: invokeLater('$controllerProvider', 'register'), + + /** + * @ngdoc method + * @name angular.Module#directive + * @methodOf angular.Module + * @param {string} name directive name + * @param {Function} directiveFactory Factory function for creating new instance of + * directives. + * @description + * See {@link ng.$compileProvider#directive $compileProvider.directive()}. + */ + directive: invokeLater('$compileProvider', 'directive'), + + /** + * @ngdoc method + * @name angular.Module#config + * @methodOf angular.Module + * @param {Function} configFn Execute this function on module load. Useful for service + * configuration. + * @description + * Use this method to register work which needs to be performed on module loading. + */ + config: config, + + /** + * @ngdoc method + * @name angular.Module#run + * @methodOf angular.Module + * @param {Function} initializationFn Execute this function after injector creation. + * Useful for application initialization. + * @description + * Use this method to register work which needs to be performed when the injector with + * with the current module is finished loading. + */ + run: function(block) { + runBlocks.push(block); + return this; + } + }; + + if (configFn) { + config(configFn); + } + + return moduleInstance; + + /** + * @param {string} provider + * @param {string} method + * @param {String=} insertMethod + * @returns {angular.Module} + */ + function invokeLater(provider, method, insertMethod) { + return function() { + invokeQueue[insertMethod || 'push']([provider, method, arguments]); + return moduleInstance; + } + } + }); + }; + }); + +} + +/** + * @ngdoc property + * @name angular.version + * @description + * An object that contains information about the current AngularJS version. This object has the + * following properties: + * + * - `full` – `{string}` – Full version string, such as "0.9.18". + * - `major` – `{number}` – Major version number, such as "0". + * - `minor` – `{number}` – Minor version number, such as "9". + * - `dot` – `{number}` – Dot version number, such as "18". + * - `codeName` – `{string}` – Code name of the release, such as "jiggling-armfat". + */ +var version = { + full: '1.0.2', // all of these placeholder strings will be replaced by rake's + major: 1, // compile task + minor: 0, + dot: 2, + codeName: 'debilitating-awesomeness' +}; + + +function publishExternalAPI(angular){ + extend(angular, { + 'bootstrap': bootstrap, + 'copy': copy, + 'extend': extend, + 'equals': equals, + 'element': jqLite, + 'forEach': forEach, + 'injector': createInjector, + 'noop':noop, + 'bind':bind, + 'toJson': toJson, + 'fromJson': fromJson, + 'identity':identity, + 'isUndefined': isUndefined, + 'isDefined': isDefined, + 'isString': isString, + 'isFunction': isFunction, + 'isObject': isObject, + 'isNumber': isNumber, + 'isElement': isElement, + 'isArray': isArray, + 'version': version, + 'isDate': isDate, + 'lowercase': lowercase, + 'uppercase': uppercase, + 'callbacks': {counter: 0} + }); + + angularModule = setupModuleLoader(window); + try { + angularModule('ngLocale'); + } catch (e) { + angularModule('ngLocale', []).provider('$locale', $LocaleProvider); + } + + angularModule('ng', ['ngLocale'], ['$provide', + function ngModule($provide) { + $provide.provider('$compile', $CompileProvider). + directive({ + a: htmlAnchorDirective, + input: inputDirective, + textarea: inputDirective, + form: formDirective, + script: scriptDirective, + select: selectDirective, + style: styleDirective, + option: optionDirective, + ngBind: ngBindDirective, + ngBindHtmlUnsafe: ngBindHtmlUnsafeDirective, + ngBindTemplate: ngBindTemplateDirective, + ngClass: ngClassDirective, + ngClassEven: ngClassEvenDirective, + ngClassOdd: ngClassOddDirective, + ngCsp: ngCspDirective, + ngCloak: ngCloakDirective, + ngController: ngControllerDirective, + ngForm: ngFormDirective, + ngHide: ngHideDirective, + ngInclude: ngIncludeDirective, + ngInit: ngInitDirective, + ngNonBindable: ngNonBindableDirective, + ngPluralize: ngPluralizeDirective, + ngRepeat: ngRepeatDirective, + ngShow: ngShowDirective, + ngSubmit: ngSubmitDirective, + ngStyle: ngStyleDirective, + ngSwitch: ngSwitchDirective, + ngSwitchWhen: ngSwitchWhenDirective, + ngSwitchDefault: ngSwitchDefaultDirective, + ngOptions: ngOptionsDirective, + ngView: ngViewDirective, + ngTransclude: ngTranscludeDirective, + ngModel: ngModelDirective, + ngList: ngListDirective, + ngChange: ngChangeDirective, + required: requiredDirective, + ngRequired: requiredDirective, + ngValue: ngValueDirective + }). + directive(ngAttributeAliasDirectives). + directive(ngEventDirectives); + $provide.provider({ + $anchorScroll: $AnchorScrollProvider, + $browser: $BrowserProvider, + $cacheFactory: $CacheFactoryProvider, + $controller: $ControllerProvider, + $document: $DocumentProvider, + $exceptionHandler: $ExceptionHandlerProvider, + $filter: $FilterProvider, + $interpolate: $InterpolateProvider, + $http: $HttpProvider, + $httpBackend: $HttpBackendProvider, + $location: $LocationProvider, + $log: $LogProvider, + $parse: $ParseProvider, + $route: $RouteProvider, + $routeParams: $RouteParamsProvider, + $rootScope: $RootScopeProvider, + $q: $QProvider, + $sniffer: $SnifferProvider, + $templateCache: $TemplateCacheProvider, + $timeout: $TimeoutProvider, + $window: $WindowProvider + }); + } + ]); +} + +////////////////////////////////// +//JQLite +////////////////////////////////// + +/** + * @ngdoc function + * @name angular.element + * @function + * + * @description + * Wraps a raw DOM element or HTML string as a [jQuery](http://jquery.com) element. + * `angular.element` can be either an alias for [jQuery](http://api.jquery.com/jQuery/) function, if + * jQuery is available, or a function that wraps the element or string in Angular's jQuery lite + * implementation (commonly referred to as jqLite). + * + * Real jQuery always takes precedence over jqLite, provided it was loaded before `DOMContentLoaded` + * event fired. + * + * jqLite is a tiny, API-compatible subset of jQuery that allows + * Angular to manipulate the DOM. jqLite implements only the most commonly needed functionality + * within a very small footprint, so only a subset of the jQuery API - methods, arguments and + * invocation styles - are supported. + * + * Note: All element references in Angular are always wrapped with jQuery or jqLite; they are never + * raw DOM references. + * + * ## Angular's jQuery lite provides the following methods: + * + * - [addClass()](http://api.jquery.com/addClass/) + * - [after()](http://api.jquery.com/after/) + * - [append()](http://api.jquery.com/append/) + * - [attr()](http://api.jquery.com/attr/) + * - [bind()](http://api.jquery.com/bind/) + * - [children()](http://api.jquery.com/children/) + * - [clone()](http://api.jquery.com/clone/) + * - [contents()](http://api.jquery.com/contents/) + * - [css()](http://api.jquery.com/css/) + * - [data()](http://api.jquery.com/data/) + * - [eq()](http://api.jquery.com/eq/) + * - [find()](http://api.jquery.com/find/) - Limited to lookups by tag name. + * - [hasClass()](http://api.jquery.com/hasClass/) + * - [html()](http://api.jquery.com/html/) + * - [next()](http://api.jquery.com/next/) + * - [parent()](http://api.jquery.com/parent/) + * - [prepend()](http://api.jquery.com/prepend/) + * - [prop()](http://api.jquery.com/prop/) + * - [ready()](http://api.jquery.com/ready/) + * - [remove()](http://api.jquery.com/remove/) + * - [removeAttr()](http://api.jquery.com/removeAttr/) + * - [removeClass()](http://api.jquery.com/removeClass/) + * - [removeData()](http://api.jquery.com/removeData/) + * - [replaceWith()](http://api.jquery.com/replaceWith/) + * - [text()](http://api.jquery.com/text/) + * - [toggleClass()](http://api.jquery.com/toggleClass/) + * - [unbind()](http://api.jquery.com/unbind/) + * - [val()](http://api.jquery.com/val/) + * - [wrap()](http://api.jquery.com/wrap/) + * + * ## In addtion to the above, Angular privides an additional method to both jQuery and jQuery lite: + * + * - `controller(name)` - retrieves the controller of the current element or its parent. By default + * retrieves controller associated with the `ngController` directive. If `name` is provided as + * camelCase directive name, then the controller for this directive will be retrieved (e.g. + * `'ngModel'`). + * - `injector()` - retrieves the injector of the current element or its parent. + * - `scope()` - retrieves the {@link api/ng.$rootScope.Scope scope} of the current + * element or its parent. + * - `inheritedData()` - same as `data()`, but walks up the DOM until a value is found or the top + * parent element is reached. + * + * @param {string|DOMElement} element HTML string or DOMElement to be wrapped into jQuery. + * @returns {Object} jQuery object. + */ + +var jqCache = JQLite.cache = {}, + jqName = JQLite.expando = 'ng-' + new Date().getTime(), + jqId = 1, + addEventListenerFn = (window.document.addEventListener + ? function(element, type, fn) {element.addEventListener(type, fn, false);} + : function(element, type, fn) {element.attachEvent('on' + type, fn);}), + removeEventListenerFn = (window.document.removeEventListener + ? function(element, type, fn) {element.removeEventListener(type, fn, false); } + : function(element, type, fn) {element.detachEvent('on' + type, fn); }); + +function jqNextId() { return ++jqId; } + + +var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g; +var MOZ_HACK_REGEXP = /^moz([A-Z])/; + +/** + * Converts snake_case to camelCase. + * Also there is special case for Moz prefix starting with upper case letter. + * @param name Name to normalize + */ +function camelCase(name) { + return name. + replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) { + return offset ? letter.toUpperCase() : letter; + }). + replace(MOZ_HACK_REGEXP, 'Moz$1'); +} + +///////////////////////////////////////////// +// jQuery mutation patch +// +// In conjunction with bindJQuery intercepts all jQuery's DOM destruction apis and fires a +// $destroy event on all DOM nodes being removed. +// +///////////////////////////////////////////// + +function JQLitePatchJQueryRemove(name, dispatchThis) { + var originalJqFn = jQuery.fn[name]; + originalJqFn = originalJqFn.$original || originalJqFn; + removePatch.$original = originalJqFn; + jQuery.fn[name] = removePatch; + + function removePatch() { + var list = [this], + fireEvent = dispatchThis, + set, setIndex, setLength, + element, childIndex, childLength, children, + fns, events; + + while(list.length) { + set = list.shift(); + for(setIndex = 0, setLength = set.length; setIndex < setLength; setIndex++) { + element = jqLite(set[setIndex]); + if (fireEvent) { + events = element.data('events'); + if ( (fns = events && events.$destroy) ) { + forEach(fns, function(fn){ + fn.handler(); + }); + } + } else { + fireEvent = !fireEvent; + } + for(childIndex = 0, childLength = (children = element.children()).length; + childIndex < childLength; + childIndex++) { + list.push(jQuery(children[childIndex])); + } + } + } + return originalJqFn.apply(this, arguments); + } +} + +///////////////////////////////////////////// +function JQLite(element) { + if (element instanceof JQLite) { + return element; + } + if (!(this instanceof JQLite)) { + if (isString(element) && element.charAt(0) != '<') { + throw Error('selectors not implemented'); + } + return new JQLite(element); + } + + if (isString(element)) { + var div = document.createElement('div'); + // Read about the NoScope elements here: + // http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx + div.innerHTML = '
 
' + element; // IE insanity to make NoScope elements work! + div.removeChild(div.firstChild); // remove the superfluous div + JQLiteAddNodes(this, div.childNodes); + this.remove(); // detach the elements from the temporary DOM div. + } else { + JQLiteAddNodes(this, element); + } +} + +function JQLiteClone(element) { + return element.cloneNode(true); +} + +function JQLiteDealoc(element){ + JQLiteRemoveData(element); + for ( var i = 0, children = element.childNodes || []; i < children.length; i++) { + JQLiteDealoc(children[i]); + } +} + +function JQLiteUnbind(element, type, fn) { + var events = JQLiteExpandoStore(element, 'events'), + handle = JQLiteExpandoStore(element, 'handle'); + + if (!handle) return; //no listeners registered + + if (isUndefined(type)) { + forEach(events, function(eventHandler, type) { + removeEventListenerFn(element, type, eventHandler); + delete events[type]; + }); + } else { + if (isUndefined(fn)) { + removeEventListenerFn(element, type, events[type]); + delete events[type]; + } else { + arrayRemove(events[type], fn); + } + } +} + +function JQLiteRemoveData(element) { + var expandoId = element[jqName], + expandoStore = jqCache[expandoId]; + + if (expandoStore) { + if (expandoStore.handle) { + expandoStore.events.$destroy && expandoStore.handle({}, '$destroy'); + JQLiteUnbind(element); + } + delete jqCache[expandoId]; + element[jqName] = undefined; // ie does not allow deletion of attributes on elements. + } +} + +function JQLiteExpandoStore(element, key, value) { + var expandoId = element[jqName], + expandoStore = jqCache[expandoId || -1]; + + if (isDefined(value)) { + if (!expandoStore) { + element[jqName] = expandoId = jqNextId(); + expandoStore = jqCache[expandoId] = {}; + } + expandoStore[key] = value; + } else { + return expandoStore && expandoStore[key]; + } +} + +function JQLiteData(element, key, value) { + var data = JQLiteExpandoStore(element, 'data'), + isSetter = isDefined(value), + keyDefined = !isSetter && isDefined(key), + isSimpleGetter = keyDefined && !isObject(key); + + if (!data && !isSimpleGetter) { + JQLiteExpandoStore(element, 'data', data = {}); + } + + if (isSetter) { + data[key] = value; + } else { + if (keyDefined) { + if (isSimpleGetter) { + // don't create data in this case. + return data && data[key]; + } else { + extend(data, key); + } + } else { + return data; + } + } +} + +function JQLiteHasClass(element, selector) { + return ((" " + element.className + " ").replace(/[\n\t]/g, " "). + indexOf( " " + selector + " " ) > -1); +} + +function JQLiteRemoveClass(element, selector) { + if (selector) { + forEach(selector.split(' '), function(cssClass) { + element.className = trim( + (" " + element.className + " ") + .replace(/[\n\t]/g, " ") + .replace(" " + trim(cssClass) + " ", " ") + ); + }); + } +} + +function JQLiteAddClass(element, selector) { + if (selector) { + forEach(selector.split(' '), function(cssClass) { + if (!JQLiteHasClass(element, cssClass)) { + element.className = trim(element.className + ' ' + trim(cssClass)); + } + }); + } +} + +function JQLiteAddNodes(root, elements) { + if (elements) { + elements = (!elements.nodeName && isDefined(elements.length) && !isWindow(elements)) + ? elements + : [ elements ]; + for(var i=0; i < elements.length; i++) { + root.push(elements[i]); + } + } +} + +function JQLiteController(element, name) { + return JQLiteInheritedData(element, '$' + (name || 'ngController' ) + 'Controller'); +} + +function JQLiteInheritedData(element, name, value) { + element = jqLite(element); + + // if element is the document object work with the html element instead + // this makes $(document).scope() possible + if(element[0].nodeType == 9) { + element = element.find('html'); + } + + while (element.length) { + if (value = element.data(name)) return value; + element = element.parent(); + } +} + +////////////////////////////////////////// +// Functions which are declared directly. +////////////////////////////////////////// +var JQLitePrototype = JQLite.prototype = { + ready: function(fn) { + var fired = false; + + function trigger() { + if (fired) return; + fired = true; + fn(); + } + + this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9 + // we can not use jqLite since we are not done loading and jQuery could be loaded later. + JQLite(window).bind('load', trigger); // fallback to window.onload for others + }, + toString: function() { + var value = []; + forEach(this, function(e){ value.push('' + e);}); + return '[' + value.join(', ') + ']'; + }, + + eq: function(index) { + return (index >= 0) ? jqLite(this[index]) : jqLite(this[this.length + index]); + }, + + length: 0, + push: push, + sort: [].sort, + splice: [].splice +}; + +////////////////////////////////////////// +// Functions iterating getter/setters. +// these functions return self on setter and +// value on get. +////////////////////////////////////////// +var BOOLEAN_ATTR = {}; +forEach('multiple,selected,checked,disabled,readOnly,required'.split(','), function(value) { + BOOLEAN_ATTR[lowercase(value)] = value; +}); +var BOOLEAN_ELEMENTS = {}; +forEach('input,select,option,textarea,button,form'.split(','), function(value) { + BOOLEAN_ELEMENTS[uppercase(value)] = true; +}); + +function getBooleanAttrName(element, name) { + // check dom last since we will most likely fail on name + var booleanAttr = BOOLEAN_ATTR[name.toLowerCase()]; + + // booleanAttr is here twice to minimize DOM access + return booleanAttr && BOOLEAN_ELEMENTS[element.nodeName] && booleanAttr; +} + +forEach({ + data: JQLiteData, + inheritedData: JQLiteInheritedData, + + scope: function(element) { + return JQLiteInheritedData(element, '$scope'); + }, + + controller: JQLiteController , + + injector: function(element) { + return JQLiteInheritedData(element, '$injector'); + }, + + removeAttr: function(element,name) { + element.removeAttribute(name); + }, + + hasClass: JQLiteHasClass, + + css: function(element, name, value) { + name = camelCase(name); + + if (isDefined(value)) { + element.style[name] = value; + } else { + var val; + + if (msie <= 8) { + // this is some IE specific weirdness that jQuery 1.6.4 does not sure why + val = element.currentStyle && element.currentStyle[name]; + if (val === '') val = 'auto'; + } + + val = val || element.style[name]; + + if (msie <= 8) { + // jquery weirdness :-/ + val = (val === '') ? undefined : val; + } + + return val; + } + }, + + attr: function(element, name, value){ + var lowercasedName = lowercase(name); + if (BOOLEAN_ATTR[lowercasedName]) { + if (isDefined(value)) { + if (!!value) { + element[name] = true; + element.setAttribute(name, lowercasedName); + } else { + element[name] = false; + element.removeAttribute(lowercasedName); + } + } else { + return (element[name] || + (element.attributes.getNamedItem(name)|| noop).specified) + ? lowercasedName + : undefined; + } + } else if (isDefined(value)) { + element.setAttribute(name, value); + } else if (element.getAttribute) { + // the extra argument "2" is to get the right thing for a.href in IE, see jQuery code + // some elements (e.g. Document) don't have get attribute, so return undefined + var ret = element.getAttribute(name, 2); + // normalize non-existing attributes to undefined (as jQuery) + return ret === null ? undefined : ret; + } + }, + + prop: function(element, name, value) { + if (isDefined(value)) { + element[name] = value; + } else { + return element[name]; + } + }, + + text: extend((msie < 9) + ? function(element, value) { + if (element.nodeType == 1 /** Element */) { + if (isUndefined(value)) + return element.innerText; + element.innerText = value; + } else { + if (isUndefined(value)) + return element.nodeValue; + element.nodeValue = value; + } + } + : function(element, value) { + if (isUndefined(value)) { + return element.textContent; + } + element.textContent = value; + }, {$dv:''}), + + val: function(element, value) { + if (isUndefined(value)) { + return element.value; + } + element.value = value; + }, + + html: function(element, value) { + if (isUndefined(value)) { + return element.innerHTML; + } + for (var i = 0, childNodes = element.childNodes; i < childNodes.length; i++) { + JQLiteDealoc(childNodes[i]); + } + element.innerHTML = value; + } +}, function(fn, name){ + /** + * Properties: writes return selection, reads return first value + */ + JQLite.prototype[name] = function(arg1, arg2) { + var i, key; + + // JQLiteHasClass has only two arguments, but is a getter-only fn, so we need to special-case it + // in a way that survives minification. + if (((fn.length == 2 && (fn !== JQLiteHasClass && fn !== JQLiteController)) ? arg1 : arg2) === undefined) { + if (isObject(arg1)) { + + // we are a write, but the object properties are the key/values + for(i=0; i < this.length; i++) { + if (fn === JQLiteData) { + // data() takes the whole object in jQuery + fn(this[i], arg1); + } else { + for (key in arg1) { + fn(this[i], key, arg1[key]); + } + } + } + // return self for chaining + return this; + } else { + // we are a read, so read the first child. + if (this.length) + return fn(this[0], arg1, arg2); + } + } else { + // we are a write, so apply to all children + for(i=0; i < this.length; i++) { + fn(this[i], arg1, arg2); + } + // return self for chaining + return this; + } + return fn.$dv; + }; +}); + +function createEventHandler(element, events) { + var eventHandler = function (event, type) { + if (!event.preventDefault) { + event.preventDefault = function() { + event.returnValue = false; //ie + }; + } + + if (!event.stopPropagation) { + event.stopPropagation = function() { + event.cancelBubble = true; //ie + }; + } + + if (!event.target) { + event.target = event.srcElement || document; + } + + if (isUndefined(event.defaultPrevented)) { + var prevent = event.preventDefault; + event.preventDefault = function() { + event.defaultPrevented = true; + prevent.call(event); + }; + event.defaultPrevented = false; + } + + event.isDefaultPrevented = function() { + return event.defaultPrevented; + }; + + forEach(events[type || event.type], function(fn) { + fn.call(element, event); + }); + + // Remove monkey-patched methods (IE), + // as they would cause memory leaks in IE8. + if (msie <= 8) { + // IE7/8 does not allow to delete property on native object + event.preventDefault = null; + event.stopPropagation = null; + event.isDefaultPrevented = null; + } else { + // It shouldn't affect normal browsers (native methods are defined on prototype). + delete event.preventDefault; + delete event.stopPropagation; + delete event.isDefaultPrevented; + } + }; + eventHandler.elem = element; + return eventHandler; +} + +////////////////////////////////////////// +// Functions iterating traversal. +// These functions chain results into a single +// selector. +////////////////////////////////////////// +forEach({ + removeData: JQLiteRemoveData, + + dealoc: JQLiteDealoc, + + bind: function bindFn(element, type, fn){ + var events = JQLiteExpandoStore(element, 'events'), + handle = JQLiteExpandoStore(element, 'handle'); + + if (!events) JQLiteExpandoStore(element, 'events', events = {}); + if (!handle) JQLiteExpandoStore(element, 'handle', handle = createEventHandler(element, events)); + + forEach(type.split(' '), function(type){ + var eventFns = events[type]; + + if (!eventFns) { + if (type == 'mouseenter' || type == 'mouseleave') { + var counter = 0; + + events.mouseenter = []; + events.mouseleave = []; + + bindFn(element, 'mouseover', function(event) { + counter++; + if (counter == 1) { + handle(event, 'mouseenter'); + } + }); + bindFn(element, 'mouseout', function(event) { + counter --; + if (counter == 0) { + handle(event, 'mouseleave'); + } + }); + } else { + addEventListenerFn(element, type, handle); + events[type] = []; + } + eventFns = events[type] + } + eventFns.push(fn); + }); + }, + + unbind: JQLiteUnbind, + + replaceWith: function(element, replaceNode) { + var index, parent = element.parentNode; + JQLiteDealoc(element); + forEach(new JQLite(replaceNode), function(node){ + if (index) { + parent.insertBefore(node, index.nextSibling); + } else { + parent.replaceChild(node, element); + } + index = node; + }); + }, + + children: function(element) { + var children = []; + forEach(element.childNodes, function(element){ + if (element.nodeName != '#text') + children.push(element); + }); + return children; + }, + + contents: function(element) { + return element.childNodes; + }, + + append: function(element, node) { + forEach(new JQLite(node), function(child){ + if (element.nodeType === 1) + element.appendChild(child); + }); + }, + + prepend: function(element, node) { + if (element.nodeType === 1) { + var index = element.firstChild; + forEach(new JQLite(node), function(child){ + if (index) { + element.insertBefore(child, index); + } else { + element.appendChild(child); + index = child; + } + }); + } + }, + + wrap: function(element, wrapNode) { + wrapNode = jqLite(wrapNode)[0]; + var parent = element.parentNode; + if (parent) { + parent.replaceChild(wrapNode, element); + } + wrapNode.appendChild(element); + }, + + remove: function(element) { + JQLiteDealoc(element); + var parent = element.parentNode; + if (parent) parent.removeChild(element); + }, + + after: function(element, newElement) { + var index = element, parent = element.parentNode; + forEach(new JQLite(newElement), function(node){ + parent.insertBefore(node, index.nextSibling); + index = node; + }); + }, + + addClass: JQLiteAddClass, + removeClass: JQLiteRemoveClass, + + toggleClass: function(element, selector, condition) { + if (isUndefined(condition)) { + condition = !JQLiteHasClass(element, selector); + } + (condition ? JQLiteAddClass : JQLiteRemoveClass)(element, selector); + }, + + parent: function(element) { + var parent = element.parentNode; + return parent && parent.nodeType !== 11 ? parent : null; + }, + + next: function(element) { + return element.nextSibling; + }, + + find: function(element, selector) { + return element.getElementsByTagName(selector); + }, + + clone: JQLiteClone +}, function(fn, name){ + /** + * chaining functions + */ + JQLite.prototype[name] = function(arg1, arg2) { + var value; + for(var i=0; i < this.length; i++) { + if (value == undefined) { + value = fn(this[i], arg1, arg2); + if (value !== undefined) { + // any function which returns a value needs to be wrapped + value = jqLite(value); + } + } else { + JQLiteAddNodes(value, fn(this[i], arg1, arg2)); + } + } + return value == undefined ? this : value; + }; +}); + +/** + * Computes a hash of an 'obj'. + * Hash of a: + * string is string + * number is number as string + * object is either result of calling $$hashKey function on the object or uniquely generated id, + * that is also assigned to the $$hashKey property of the object. + * + * @param obj + * @returns {string} hash string such that the same input will have the same hash string. + * The resulting string key is in 'type:hashKey' format. + */ +function hashKey(obj) { + var objType = typeof obj, + key; + + if (objType == 'object' && obj !== null) { + if (typeof (key = obj.$$hashKey) == 'function') { + // must invoke on object to keep the right this + key = obj.$$hashKey(); + } else if (key === undefined) { + key = obj.$$hashKey = nextUid(); + } + } else { + key = obj; + } + + return objType + ':' + key; +} + +/** + * HashMap which can use objects as keys + */ +function HashMap(array){ + forEach(array, this.put, this); +} +HashMap.prototype = { + /** + * Store key value pair + * @param key key to store can be any type + * @param value value to store can be any type + */ + put: function(key, value) { + this[hashKey(key)] = value; + }, + + /** + * @param key + * @returns the value for the key + */ + get: function(key) { + return this[hashKey(key)]; + }, + + /** + * Remove the key/value pair + * @param key + */ + remove: function(key) { + var value = this[key = hashKey(key)]; + delete this[key]; + return value; + } +}; + +/** + * A map where multiple values can be added to the same key such that they form a queue. + * @returns {HashQueueMap} + */ +function HashQueueMap() {} +HashQueueMap.prototype = { + /** + * Same as array push, but using an array as the value for the hash + */ + push: function(key, value) { + var array = this[key = hashKey(key)]; + if (!array) { + this[key] = [value]; + } else { + array.push(value); + } + }, + + /** + * Same as array shift, but using an array as the value for the hash + */ + shift: function(key) { + var array = this[key = hashKey(key)]; + if (array) { + if (array.length == 1) { + delete this[key]; + return array[0]; + } else { + return array.shift(); + } + } + } +}; + +/** + * @ngdoc function + * @name angular.injector + * @function + * + * @description + * Creates an injector function that can be used for retrieving services as well as for + * dependency injection (see {@link guide/di dependency injection}). + * + + * @param {Array.} modules A list of module functions or their aliases. See + * {@link angular.module}. The `ng` module must be explicitly added. + * @returns {function()} Injector function. See {@link AUTO.$injector $injector}. + * + * @example + * Typical usage + *
+ *   // create an injector
+ *   var $injector = angular.injector(['ng']);
+ *
+ *   // use the injector to kick of your application
+ *   // use the type inference to auto inject arguments, or use implicit injection
+ *   $injector.invoke(function($rootScope, $compile, $document){
+ *     $compile($document)($rootScope);
+ *     $rootScope.$digest();
+ *   });
+ * 
+ */ + + +/** + * @ngdoc overview + * @name AUTO + * @description + * + * Implicit module which gets automatically added to each {@link AUTO.$injector $injector}. + */ + +var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; +var FN_ARG_SPLIT = /,/; +var FN_ARG = /^\s*(_?)(.+?)\1\s*$/; +var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; +function annotate(fn) { + var $inject, + fnText, + argDecl, + last; + + if (typeof fn == 'function') { + if (!($inject = fn.$inject)) { + $inject = []; + fnText = fn.toString().replace(STRIP_COMMENTS, ''); + argDecl = fnText.match(FN_ARGS); + forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg){ + arg.replace(FN_ARG, function(all, underscore, name){ + $inject.push(name); + }); + }); + fn.$inject = $inject; + } + } else if (isArray(fn)) { + last = fn.length - 1; + assertArgFn(fn[last], 'fn') + $inject = fn.slice(0, last); + } else { + assertArgFn(fn, 'fn', true); + } + return $inject; +} + +/////////////////////////////////////// + +/** + * @ngdoc object + * @name AUTO.$injector + * @function + * + * @description + * + * `$injector` is used to retrieve object instances as defined by + * {@link AUTO.$provide provider}, instantiate types, invoke methods, + * and load modules. + * + * The following always holds true: + * + *
+ *   var $injector = angular.injector();
+ *   expect($injector.get('$injector')).toBe($injector);
+ *   expect($injector.invoke(function($injector){
+ *     return $injector;
+ *   }).toBe($injector);
+ * 
+ * + * # Injection Function Annotation + * + * JavaScript does not have annotations, and annotations are needed for dependency injection. The + * following ways are all valid way of annotating function with injection arguments and are equivalent. + * + *
+ *   // inferred (only works if code not minified/obfuscated)
+ *   $inject.invoke(function(serviceA){});
+ *
+ *   // annotated
+ *   function explicit(serviceA) {};
+ *   explicit.$inject = ['serviceA'];
+ *   $inject.invoke(explicit);
+ *
+ *   // inline
+ *   $inject.invoke(['serviceA', function(serviceA){}]);
+ * 
+ * + * ## Inference + * + * In JavaScript calling `toString()` on a function returns the function definition. The definition can then be + * parsed and the function arguments can be extracted. *NOTE:* This does not work with minification, and obfuscation + * tools since these tools change the argument names. + * + * ## `$inject` Annotation + * By adding a `$inject` property onto a function the injection parameters can be specified. + * + * ## Inline + * As an array of injection names, where the last item in the array is the function to call. + */ + +/** + * @ngdoc method + * @name AUTO.$injector#get + * @methodOf AUTO.$injector + * + * @description + * Return an instance of the service. + * + * @param {string} name The name of the instance to retrieve. + * @return {*} The instance. + */ + +/** + * @ngdoc method + * @name AUTO.$injector#invoke + * @methodOf AUTO.$injector + * + * @description + * Invoke the method and supply the method arguments from the `$injector`. + * + * @param {!function} fn The function to invoke. The function arguments come form the function annotation. + * @param {Object=} self The `this` for the invoked method. + * @param {Object=} locals Optional object. If preset then any argument names are read from this object first, before + * the `$injector` is consulted. + * @returns {*} the value returned by the invoked `fn` function. + */ + +/** + * @ngdoc method + * @name AUTO.$injector#instantiate + * @methodOf AUTO.$injector + * @description + * Create a new instance of JS type. The method takes a constructor function invokes the new operator and supplies + * all of the arguments to the constructor function as specified by the constructor annotation. + * + * @param {function} Type Annotated constructor function. + * @param {Object=} locals Optional object. If preset then any argument names are read from this object first, before + * the `$injector` is consulted. + * @returns {Object} new instance of `Type`. + */ + +/** + * @ngdoc method + * @name AUTO.$injector#annotate + * @methodOf AUTO.$injector + * + * @description + * Returns an array of service names which the function is requesting for injection. This API is used by the injector + * to determine which services need to be injected into the function when the function is invoked. There are three + * ways in which the function can be annotated with the needed dependencies. + * + * # Argument names + * + * The simplest form is to extract the dependencies from the arguments of the function. This is done by converting + * the function into a string using `toString()` method and extracting the argument names. + *
+ *   // Given
+ *   function MyController($scope, $route) {
+ *     // ...
+ *   }
+ *
+ *   // Then
+ *   expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
+ * 
+ * + * This method does not work with code minfication / obfuscation. For this reason the following annotation strategies + * are supported. + * + * # The `$injector` property + * + * If a function has an `$inject` property and its value is an array of strings, then the strings represent names of + * services to be injected into the function. + *
+ *   // Given
+ *   var MyController = function(obfuscatedScope, obfuscatedRoute) {
+ *     // ...
+ *   }
+ *   // Define function dependencies
+ *   MyController.$inject = ['$scope', '$route'];
+ *
+ *   // Then
+ *   expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
+ * 
+ * + * # The array notation + * + * It is often desirable to inline Injected functions and that's when setting the `$inject` property is very + * inconvenient. In these situations using the array notation to specify the dependencies in a way that survives + * minification is a better choice: + * + *
+ *   // We wish to write this (not minification / obfuscation safe)
+ *   injector.invoke(function($compile, $rootScope) {
+ *     // ...
+ *   });
+ *
+ *   // We are forced to write break inlining
+ *   var tmpFn = function(obfuscatedCompile, obfuscatedRootScope) {
+ *     // ...
+ *   };
+ *   tmpFn.$inject = ['$compile', '$rootScope'];
+ *   injector.invoke(tempFn);
+ *
+ *   // To better support inline function the inline annotation is supported
+ *   injector.invoke(['$compile', '$rootScope', function(obfCompile, obfRootScope) {
+ *     // ...
+ *   }]);
+ *
+ *   // Therefore
+ *   expect(injector.annotate(
+ *      ['$compile', '$rootScope', function(obfus_$compile, obfus_$rootScope) {}])
+ *    ).toEqual(['$compile', '$rootScope']);
+ * 
+ * + * @param {function|Array.} fn Function for which dependent service names need to be retrieved as described + * above. + * + * @returns {Array.} The names of the services which the function requires. + */ + + + + +/** + * @ngdoc object + * @name AUTO.$provide + * + * @description + * + * Use `$provide` to register new providers with the `$injector`. The providers are the factories for the instance. + * The providers share the same name as the instance they create with the `Provider` suffixed to them. + * + * A provider is an object with a `$get()` method. The injector calls the `$get` method to create a new instance of + * a service. The Provider can have additional methods which would allow for configuration of the provider. + * + *
+ *   function GreetProvider() {
+ *     var salutation = 'Hello';
+ *
+ *     this.salutation = function(text) {
+ *       salutation = text;
+ *     };
+ *
+ *     this.$get = function() {
+ *       return function (name) {
+ *         return salutation + ' ' + name + '!';
+ *       };
+ *     };
+ *   }
+ *
+ *   describe('Greeter', function(){
+ *
+ *     beforeEach(module(function($provide) {
+ *       $provide.provider('greet', GreetProvider);
+ *     });
+ *
+ *     it('should greet', inject(function(greet) {
+ *       expect(greet('angular')).toEqual('Hello angular!');
+ *     }));
+ *
+ *     it('should allow configuration of salutation', function() {
+ *       module(function(greetProvider) {
+ *         greetProvider.salutation('Ahoj');
+ *       });
+ *       inject(function(greet) {
+ *         expect(greet('angular')).toEqual('Ahoj angular!');
+ *       });
+ *     )};
+ *
+ *   });
+ * 
+ */ + +/** + * @ngdoc method + * @name AUTO.$provide#provider + * @methodOf AUTO.$provide + * @description + * + * Register a provider for a service. The providers can be retrieved and can have additional configuration methods. + * + * @param {string} name The name of the instance. NOTE: the provider will be available under `name + 'Provider'` key. + * @param {(Object|function())} provider If the provider is: + * + * - `Object`: then it should have a `$get` method. The `$get` method will be invoked using + * {@link AUTO.$injector#invoke $injector.invoke()} when an instance needs to be created. + * - `Constructor`: a new instance of the provider will be created using + * {@link AUTO.$injector#instantiate $injector.instantiate()}, then treated as `object`. + * + * @returns {Object} registered provider instance + */ + +/** + * @ngdoc method + * @name AUTO.$provide#factory + * @methodOf AUTO.$provide + * @description + * + * A short hand for configuring services if only `$get` method is required. + * + * @param {string} name The name of the instance. + * @param {function()} $getFn The $getFn for the instance creation. Internally this is a short hand for + * `$provide.provider(name, {$get: $getFn})`. + * @returns {Object} registered provider instance + */ + + +/** + * @ngdoc method + * @name AUTO.$provide#service + * @methodOf AUTO.$provide + * @description + * + * A short hand for registering service of given class. + * + * @param {string} name The name of the instance. + * @param {Function} constructor A class (constructor function) that will be instantiated. + * @returns {Object} registered provider instance + */ + + +/** + * @ngdoc method + * @name AUTO.$provide#value + * @methodOf AUTO.$provide + * @description + * + * A short hand for configuring services if the `$get` method is a constant. + * + * @param {string} name The name of the instance. + * @param {*} value The value. + * @returns {Object} registered provider instance + */ + + +/** + * @ngdoc method + * @name AUTO.$provide#constant + * @methodOf AUTO.$provide + * @description + * + * A constant value, but unlike {@link AUTO.$provide#value value} it can be injected + * into configuration function (other modules) and it is not interceptable by + * {@link AUTO.$provide#decorator decorator}. + * + * @param {string} name The name of the constant. + * @param {*} value The constant value. + * @returns {Object} registered instance + */ + + +/** + * @ngdoc method + * @name AUTO.$provide#decorator + * @methodOf AUTO.$provide + * @description + * + * Decoration of service, allows the decorator to intercept the service instance creation. The + * returned instance may be the original instance, or a new instance which delegates to the + * original instance. + * + * @param {string} name The name of the service to decorate. + * @param {function()} decorator This function will be invoked when the service needs to be + * instanciated. The function is called using the {@link AUTO.$injector#invoke + * injector.invoke} method and is therefore fully injectable. Local injection arguments: + * + * * `$delegate` - The original service instance, which can be monkey patched, configured, + * decorated or delegated to. + */ + + +function createInjector(modulesToLoad) { + var INSTANTIATING = {}, + providerSuffix = 'Provider', + path = [], + loadedModules = new HashMap(), + providerCache = { + $provide: { + provider: supportObject(provider), + factory: supportObject(factory), + service: supportObject(service), + value: supportObject(value), + constant: supportObject(constant), + decorator: decorator + } + }, + providerInjector = createInternalInjector(providerCache, function() { + throw Error("Unknown provider: " + path.join(' <- ')); + }), + instanceCache = {}, + instanceInjector = (instanceCache.$injector = + createInternalInjector(instanceCache, function(servicename) { + var provider = providerInjector.get(servicename + providerSuffix); + return instanceInjector.invoke(provider.$get, provider); + })); + + + forEach(loadModules(modulesToLoad), function(fn) { instanceInjector.invoke(fn || noop); }); + + return instanceInjector; + + //////////////////////////////////// + // $provider + //////////////////////////////////// + + function supportObject(delegate) { + return function(key, value) { + if (isObject(key)) { + forEach(key, reverseParams(delegate)); + } else { + return delegate(key, value); + } + } + } + + function provider(name, provider_) { + if (isFunction(provider_)) { + provider_ = providerInjector.instantiate(provider_); + } + if (!provider_.$get) { + throw Error('Provider ' + name + ' must define $get factory method.'); + } + return providerCache[name + providerSuffix] = provider_; + } + + function factory(name, factoryFn) { return provider(name, { $get: factoryFn }); } + + function service(name, constructor) { + return factory(name, ['$injector', function($injector) { + return $injector.instantiate(constructor); + }]); + } + + function value(name, value) { return factory(name, valueFn(value)); } + + function constant(name, value) { + providerCache[name] = value; + instanceCache[name] = value; + } + + function decorator(serviceName, decorFn) { + var origProvider = providerInjector.get(serviceName + providerSuffix), + orig$get = origProvider.$get; + + origProvider.$get = function() { + var origInstance = instanceInjector.invoke(orig$get, origProvider); + return instanceInjector.invoke(decorFn, null, {$delegate: origInstance}); + }; + } + + //////////////////////////////////// + // Module Loading + //////////////////////////////////// + function loadModules(modulesToLoad){ + var runBlocks = []; + forEach(modulesToLoad, function(module) { + if (loadedModules.get(module)) return; + loadedModules.put(module, true); + if (isString(module)) { + var moduleFn = angularModule(module); + runBlocks = runBlocks.concat(loadModules(moduleFn.requires)).concat(moduleFn._runBlocks); + + try { + for(var invokeQueue = moduleFn._invokeQueue, i = 0, ii = invokeQueue.length; i < ii; i++) { + var invokeArgs = invokeQueue[i], + provider = invokeArgs[0] == '$injector' + ? providerInjector + : providerInjector.get(invokeArgs[0]); + + provider[invokeArgs[1]].apply(provider, invokeArgs[2]); + } + } catch (e) { + if (e.message) e.message += ' from ' + module; + throw e; + } + } else if (isFunction(module)) { + try { + runBlocks.push(providerInjector.invoke(module)); + } catch (e) { + if (e.message) e.message += ' from ' + module; + throw e; + } + } else if (isArray(module)) { + try { + runBlocks.push(providerInjector.invoke(module)); + } catch (e) { + if (e.message) e.message += ' from ' + String(module[module.length - 1]); + throw e; + } + } else { + assertArgFn(module, 'module'); + } + }); + return runBlocks; + } + + //////////////////////////////////// + // internal Injector + //////////////////////////////////// + + function createInternalInjector(cache, factory) { + + function getService(serviceName) { + if (typeof serviceName !== 'string') { + throw Error('Service name expected'); + } + if (cache.hasOwnProperty(serviceName)) { + if (cache[serviceName] === INSTANTIATING) { + throw Error('Circular dependency: ' + path.join(' <- ')); + } + return cache[serviceName]; + } else { + try { + path.unshift(serviceName); + cache[serviceName] = INSTANTIATING; + return cache[serviceName] = factory(serviceName); + } finally { + path.shift(); + } + } + } + + function invoke(fn, self, locals){ + var args = [], + $inject = annotate(fn), + length, i, + key; + + for(i = 0, length = $inject.length; i < length; i++) { + key = $inject[i]; + args.push( + locals && locals.hasOwnProperty(key) + ? locals[key] + : getService(key, path) + ); + } + if (!fn.$inject) { + // this means that we must be an array. + fn = fn[length]; + } + + + // Performance optimization: http://jsperf.com/apply-vs-call-vs-invoke + switch (self ? -1 : args.length) { + case 0: return fn(); + case 1: return fn(args[0]); + case 2: return fn(args[0], args[1]); + case 3: return fn(args[0], args[1], args[2]); + case 4: return fn(args[0], args[1], args[2], args[3]); + case 5: return fn(args[0], args[1], args[2], args[3], args[4]); + case 6: return fn(args[0], args[1], args[2], args[3], args[4], args[5]); + case 7: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + case 8: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); + case 9: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); + case 10: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); + default: return fn.apply(self, args); + } + } + + function instantiate(Type, locals) { + var Constructor = function() {}, + instance, returnedValue; + + Constructor.prototype = (isArray(Type) ? Type[Type.length - 1] : Type).prototype; + instance = new Constructor(); + returnedValue = invoke(Type, instance, locals); + + return isObject(returnedValue) ? returnedValue : instance; + } + + return { + invoke: invoke, + instantiate: instantiate, + get: getService, + annotate: annotate + }; + } +} +/** + * @ngdoc function + * @name ng.$anchorScroll + * @requires $window + * @requires $location + * @requires $rootScope + * + * @description + * When called, it checks current value of `$location.hash()` and scroll to related element, + * according to rules specified in + * {@link http://dev.w3.org/html5/spec/Overview.html#the-indicated-part-of-the-document Html5 spec}. + * + * It also watches the `$location.hash()` and scroll whenever it changes to match any anchor. + * This can be disabled by calling `$anchorScrollProvider.disableAutoScrolling()`. + */ +function $AnchorScrollProvider() { + + var autoScrollingEnabled = true; + + this.disableAutoScrolling = function() { + autoScrollingEnabled = false; + }; + + this.$get = ['$window', '$location', '$rootScope', function($window, $location, $rootScope) { + var document = $window.document; + + // helper function to get first anchor from a NodeList + // can't use filter.filter, as it accepts only instances of Array + // and IE can't convert NodeList to an array using [].slice + // TODO(vojta): use filter if we change it to accept lists as well + function getFirstAnchor(list) { + var result = null; + forEach(list, function(element) { + if (!result && lowercase(element.nodeName) === 'a') result = element; + }); + return result; + } + + function scroll() { + var hash = $location.hash(), elm; + + // empty hash, scroll to the top of the page + if (!hash) $window.scrollTo(0, 0); + + // element with given id + else if ((elm = document.getElementById(hash))) elm.scrollIntoView(); + + // first anchor with given name :-D + else if ((elm = getFirstAnchor(document.getElementsByName(hash)))) elm.scrollIntoView(); + + // no element and hash == 'top', scroll to the top of the page + else if (hash === 'top') $window.scrollTo(0, 0); + } + + // does not scroll when user clicks on anchor link that is currently on + // (no url change, no $locaiton.hash() change), browser native does scroll + if (autoScrollingEnabled) { + $rootScope.$watch(function() {return $location.hash();}, function() { + $rootScope.$evalAsync(scroll); + }); + } + + return scroll; + }]; +} + +/** + * ! This is a private undocumented service ! + * + * @name ng.$browser + * @requires $log + * @description + * This object has two goals: + * + * - hide all the global state in the browser caused by the window object + * - abstract away all the browser specific features and inconsistencies + * + * For tests we provide {@link ngMock.$browser mock implementation} of the `$browser` + * service, which can be used for convenient testing of the application without the interaction with + * the real browser apis. + */ +/** + * @param {object} window The global window object. + * @param {object} document jQuery wrapped document. + * @param {function()} XHR XMLHttpRequest constructor. + * @param {object} $log console.log or an object with the same interface. + * @param {object} $sniffer $sniffer service + */ +function Browser(window, document, $log, $sniffer) { + var self = this, + rawDocument = document[0], + location = window.location, + history = window.history, + setTimeout = window.setTimeout, + clearTimeout = window.clearTimeout, + pendingDeferIds = {}; + + self.isMock = false; + + var outstandingRequestCount = 0; + var outstandingRequestCallbacks = []; + + // TODO(vojta): remove this temporary api + self.$$completeOutstandingRequest = completeOutstandingRequest; + self.$$incOutstandingRequestCount = function() { outstandingRequestCount++; }; + + /** + * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks` + * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed. + */ + function completeOutstandingRequest(fn) { + try { + fn.apply(null, sliceArgs(arguments, 1)); + } finally { + outstandingRequestCount--; + if (outstandingRequestCount === 0) { + while(outstandingRequestCallbacks.length) { + try { + outstandingRequestCallbacks.pop()(); + } catch (e) { + $log.error(e); + } + } + } + } + } + + /** + * @private + * Note: this method is used only by scenario runner + * TODO(vojta): prefix this method with $$ ? + * @param {function()} callback Function that will be called when no outstanding request + */ + self.notifyWhenNoOutstandingRequests = function(callback) { + // force browser to execute all pollFns - this is needed so that cookies and other pollers fire + // at some deterministic time in respect to the test runner's actions. Leaving things up to the + // regular poller would result in flaky tests. + forEach(pollFns, function(pollFn){ pollFn(); }); + + if (outstandingRequestCount === 0) { + callback(); + } else { + outstandingRequestCallbacks.push(callback); + } + }; + + ////////////////////////////////////////////////////////////// + // Poll Watcher API + ////////////////////////////////////////////////////////////// + var pollFns = [], + pollTimeout; + + /** + * @name ng.$browser#addPollFn + * @methodOf ng.$browser + * + * @param {function()} fn Poll function to add + * + * @description + * Adds a function to the list of functions that poller periodically executes, + * and starts polling if not started yet. + * + * @returns {function()} the added function + */ + self.addPollFn = function(fn) { + if (isUndefined(pollTimeout)) startPoller(100, setTimeout); + pollFns.push(fn); + return fn; + }; + + /** + * @param {number} interval How often should browser call poll functions (ms) + * @param {function()} setTimeout Reference to a real or fake `setTimeout` function. + * + * @description + * Configures the poller to run in the specified intervals, using the specified + * setTimeout fn and kicks it off. + */ + function startPoller(interval, setTimeout) { + (function check() { + forEach(pollFns, function(pollFn){ pollFn(); }); + pollTimeout = setTimeout(check, interval); + })(); + } + + ////////////////////////////////////////////////////////////// + // URL API + ////////////////////////////////////////////////////////////// + + var lastBrowserUrl = location.href, + baseElement = document.find('base'); + + /** + * @name ng.$browser#url + * @methodOf ng.$browser + * + * @description + * GETTER: + * Without any argument, this method just returns current value of location.href. + * + * SETTER: + * With at least one argument, this method sets url to new value. + * If html5 history api supported, pushState/replaceState is used, otherwise + * location.href/location.replace is used. + * Returns its own instance to allow chaining + * + * NOTE: this api is intended for use only by the $location service. Please use the + * {@link ng.$location $location service} to change url. + * + * @param {string} url New url (when used as setter) + * @param {boolean=} replace Should new url replace current history record ? + */ + self.url = function(url, replace) { + // setter + if (url) { + if (lastBrowserUrl == url) return; + lastBrowserUrl = url; + if ($sniffer.history) { + if (replace) history.replaceState(null, '', url); + else { + history.pushState(null, '', url); + // Crazy Opera Bug: http://my.opera.com/community/forums/topic.dml?id=1185462 + baseElement.attr('href', baseElement.attr('href')); + } + } else { + if (replace) location.replace(url); + else location.href = url; + } + return self; + // getter + } else { + // the replacement is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=407172 + return location.href.replace(/%27/g,"'"); + } + }; + + var urlChangeListeners = [], + urlChangeInit = false; + + function fireUrlChange() { + if (lastBrowserUrl == self.url()) return; + + lastBrowserUrl = self.url(); + forEach(urlChangeListeners, function(listener) { + listener(self.url()); + }); + } + + /** + * @name ng.$browser#onUrlChange + * @methodOf ng.$browser + * @TODO(vojta): refactor to use node's syntax for events + * + * @description + * Register callback function that will be called, when url changes. + * + * It's only called when the url is changed by outside of angular: + * - user types different url into address bar + * - user clicks on history (forward/back) button + * - user clicks on a link + * + * It's not called when url is changed by $browser.url() method + * + * The listener gets called with new url as parameter. + * + * NOTE: this api is intended for use only by the $location service. Please use the + * {@link ng.$location $location service} to monitor url changes in angular apps. + * + * @param {function(string)} listener Listener function to be called when url changes. + * @return {function(string)} Returns the registered listener fn - handy if the fn is anonymous. + */ + self.onUrlChange = function(callback) { + if (!urlChangeInit) { + // We listen on both (hashchange/popstate) when available, as some browsers (e.g. Opera) + // don't fire popstate when user change the address bar and don't fire hashchange when url + // changed by push/replaceState + + // html5 history api - popstate event + if ($sniffer.history) jqLite(window).bind('popstate', fireUrlChange); + // hashchange event + if ($sniffer.hashchange) jqLite(window).bind('hashchange', fireUrlChange); + // polling + else self.addPollFn(fireUrlChange); + + urlChangeInit = true; + } + + urlChangeListeners.push(callback); + return callback; + }; + + ////////////////////////////////////////////////////////////// + // Misc API + ////////////////////////////////////////////////////////////// + + /** + * Returns current + * (always relative - without domain) + * + * @returns {string=} + */ + self.baseHref = function() { + var href = baseElement.attr('href'); + return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : href; + }; + + ////////////////////////////////////////////////////////////// + // Cookies API + ////////////////////////////////////////////////////////////// + var lastCookies = {}; + var lastCookieString = ''; + var cookiePath = self.baseHref(); + + /** + * @name ng.$browser#cookies + * @methodOf ng.$browser + * + * @param {string=} name Cookie name + * @param {string=} value Cokkie value + * + * @description + * The cookies method provides a 'private' low level access to browser cookies. + * It is not meant to be used directly, use the $cookie service instead. + * + * The return values vary depending on the arguments that the method was called with as follows: + *
    + *
  • cookies() -> hash of all cookies, this is NOT a copy of the internal state, so do not modify it
  • + *
  • cookies(name, value) -> set name to value, if value is undefined delete the cookie
  • + *
  • cookies(name) -> the same as (name, undefined) == DELETES (no one calls it right now that way)
  • + *
+ * + * @returns {Object} Hash of all cookies (if called without any parameter) + */ + self.cookies = function(name, value) { + var cookieLength, cookieArray, cookie, i, index; + + if (name) { + if (value === undefined) { + rawDocument.cookie = escape(name) + "=;path=" + cookiePath + ";expires=Thu, 01 Jan 1970 00:00:00 GMT"; + } else { + if (isString(value)) { + cookieLength = (rawDocument.cookie = escape(name) + '=' + escape(value) + ';path=' + cookiePath).length + 1; + if (cookieLength > 4096) { + $log.warn("Cookie '"+ name +"' possibly not set or overflowed because it was too large ("+ + cookieLength + " > 4096 bytes)!"); + } + if (lastCookies.length > 20) { + $log.warn("Cookie '"+ name +"' possibly not set or overflowed because too many cookies " + + "were already set (" + lastCookies.length + " > 20 )"); + } + } + } + } else { + if (rawDocument.cookie !== lastCookieString) { + lastCookieString = rawDocument.cookie; + cookieArray = lastCookieString.split("; "); + lastCookies = {}; + + for (i = 0; i < cookieArray.length; i++) { + cookie = cookieArray[i]; + index = cookie.indexOf('='); + if (index > 0) { //ignore nameless cookies + lastCookies[unescape(cookie.substring(0, index))] = unescape(cookie.substring(index + 1)); + } + } + } + return lastCookies; + } + }; + + + /** + * @name ng.$browser#defer + * @methodOf ng.$browser + * @param {function()} fn A function, who's execution should be defered. + * @param {number=} [delay=0] of milliseconds to defer the function execution. + * @returns {*} DeferId that can be used to cancel the task via `$browser.defer.cancel()`. + * + * @description + * Executes a fn asynchroniously via `setTimeout(fn, delay)`. + * + * Unlike when calling `setTimeout` directly, in test this function is mocked and instead of using + * `setTimeout` in tests, the fns are queued in an array, which can be programmatically flushed + * via `$browser.defer.flush()`. + * + */ + self.defer = function(fn, delay) { + var timeoutId; + outstandingRequestCount++; + timeoutId = setTimeout(function() { + delete pendingDeferIds[timeoutId]; + completeOutstandingRequest(fn); + }, delay || 0); + pendingDeferIds[timeoutId] = true; + return timeoutId; + }; + + + /** + * @name ng.$browser#defer.cancel + * @methodOf ng.$browser.defer + * + * @description + * Cancels a defered task identified with `deferId`. + * + * @param {*} deferId Token returned by the `$browser.defer` function. + * @returns {boolean} Returns `true` if the task hasn't executed yet and was successfuly canceled. + */ + self.defer.cancel = function(deferId) { + if (pendingDeferIds[deferId]) { + delete pendingDeferIds[deferId]; + clearTimeout(deferId); + completeOutstandingRequest(noop); + return true; + } + return false; + }; + +} + +function $BrowserProvider(){ + this.$get = ['$window', '$log', '$sniffer', '$document', + function( $window, $log, $sniffer, $document){ + return new Browser($window, $document, $log, $sniffer); + }]; +} +/** + * @ngdoc object + * @name ng.$cacheFactory + * + * @description + * Factory that constructs cache objects. + * + * + * @param {string} cacheId Name or id of the newly created cache. + * @param {object=} options Options object that specifies the cache behavior. Properties: + * + * - `{number=}` `capacity` — turns the cache into LRU cache. + * + * @returns {object} Newly created cache object with the following set of methods: + * + * - `{object}` `info()` — Returns id, size, and options of cache. + * - `{void}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache. + * - `{{*}} `get({string} key) — Returns cached value for `key` or undefined for cache miss. + * - `{void}` `remove({string} key) — Removes a key-value pair from the cache. + * - `{void}` `removeAll() — Removes all cached values. + * - `{void}` `destroy() — Removes references to this cache from $cacheFactory. + * + */ +function $CacheFactoryProvider() { + + this.$get = function() { + var caches = {}; + + function cacheFactory(cacheId, options) { + if (cacheId in caches) { + throw Error('cacheId ' + cacheId + ' taken'); + } + + var size = 0, + stats = extend({}, options, {id: cacheId}), + data = {}, + capacity = (options && options.capacity) || Number.MAX_VALUE, + lruHash = {}, + freshEnd = null, + staleEnd = null; + + return caches[cacheId] = { + + put: function(key, value) { + var lruEntry = lruHash[key] || (lruHash[key] = {key: key}); + + refresh(lruEntry); + + if (isUndefined(value)) return; + if (!(key in data)) size++; + data[key] = value; + + if (size > capacity) { + this.remove(staleEnd.key); + } + }, + + + get: function(key) { + var lruEntry = lruHash[key]; + + if (!lruEntry) return; + + refresh(lruEntry); + + return data[key]; + }, + + + remove: function(key) { + var lruEntry = lruHash[key]; + + if (lruEntry == freshEnd) freshEnd = lruEntry.p; + if (lruEntry == staleEnd) staleEnd = lruEntry.n; + link(lruEntry.n,lruEntry.p); + + delete lruHash[key]; + delete data[key]; + size--; + }, + + + removeAll: function() { + data = {}; + size = 0; + lruHash = {}; + freshEnd = staleEnd = null; + }, + + + destroy: function() { + data = null; + stats = null; + lruHash = null; + delete caches[cacheId]; + }, + + + info: function() { + return extend({}, stats, {size: size}); + } + }; + + + /** + * makes the `entry` the freshEnd of the LRU linked list + */ + function refresh(entry) { + if (entry != freshEnd) { + if (!staleEnd) { + staleEnd = entry; + } else if (staleEnd == entry) { + staleEnd = entry.n; + } + + link(entry.n, entry.p); + link(entry, freshEnd); + freshEnd = entry; + freshEnd.n = null; + } + } + + + /** + * bidirectionally links two entries of the LRU linked list + */ + function link(nextEntry, prevEntry) { + if (nextEntry != prevEntry) { + if (nextEntry) nextEntry.p = prevEntry; //p stands for previous, 'prev' didn't minify + if (prevEntry) prevEntry.n = nextEntry; //n stands for next, 'next' didn't minify + } + } + } + + + cacheFactory.info = function() { + var info = {}; + forEach(caches, function(cache, cacheId) { + info[cacheId] = cache.info(); + }); + return info; + }; + + + cacheFactory.get = function(cacheId) { + return caches[cacheId]; + }; + + + return cacheFactory; + }; +} + +/** + * @ngdoc object + * @name ng.$templateCache + * + * @description + * Cache used for storing html templates. + * + * See {@link ng.$cacheFactory $cacheFactory}. + * + */ +function $TemplateCacheProvider() { + this.$get = ['$cacheFactory', function($cacheFactory) { + return $cacheFactory('templates'); + }]; +} + +/* ! VARIABLE/FUNCTION NAMING CONVENTIONS THAT APPLY TO THIS FILE! + * + * DOM-related variables: + * + * - "node" - DOM Node + * - "element" - DOM Element or Node + * - "$node" or "$element" - jqLite-wrapped node or element + * + * + * Compiler related stuff: + * + * - "linkFn" - linking fn of a single directive + * - "nodeLinkFn" - function that aggregates all linking fns for a particular node + * - "childLinkFn" - function that aggregates all linking fns for child nodes of a particular node + * - "compositeLinkFn" - function that aggregates all linking fns for a compilation root (nodeList) + */ + + +var NON_ASSIGNABLE_MODEL_EXPRESSION = 'Non-assignable model expression: '; + + +/** + * @ngdoc function + * @name ng.$compile + * @function + * + * @description + * Compiles a piece of HTML string or DOM into a template and produces a template function, which + * can then be used to link {@link ng.$rootScope.Scope scope} and the template together. + * + * The compilation is a process of walking the DOM tree and trying to match DOM elements to + * {@link ng.$compileProvider#directive directives}. For each match it + * executes corresponding template function and collects the + * instance functions into a single template function which is then returned. + * + * The template function can then be used once to produce the view or as it is the case with + * {@link ng.directive:ngRepeat repeater} many-times, in which + * case each call results in a view that is a DOM clone of the original template. + * + + + +
+
+
+
+
+
+ + it('should auto compile', function() { + expect(element('div[compile]').text()).toBe('Hello Angular'); + input('html').enter('{{name}}!'); + expect(element('div[compile]').text()).toBe('Angular!'); + }); + +
+ + * + * + * @param {string|DOMElement} element Element or HTML string to compile into a template function. + * @param {function(angular.Scope[, cloneAttachFn]} transclude function available to directives. + * @param {number} maxPriority only apply directives lower then given priority (Only effects the + * root element(s), not their children) + * @returns {function(scope[, cloneAttachFn])} a link function which is used to bind template + * (a DOM element/tree) to a scope. Where: + * + * * `scope` - A {@link ng.$rootScope.Scope Scope} to bind to. + * * `cloneAttachFn` - If `cloneAttachFn` is provided, then the link function will clone the + * `template` and call the `cloneAttachFn` function allowing the caller to attach the + * cloned elements to the DOM document at the appropriate place. The `cloneAttachFn` is + * called as:
`cloneAttachFn(clonedElement, scope)` where: + * + * * `clonedElement` - is a clone of the original `element` passed into the compiler. + * * `scope` - is the current scope with which the linking function is working with. + * + * Calling the linking function returns the element of the template. It is either the original element + * passed in, or the clone of the element if the `cloneAttachFn` is provided. + * + * After linking the view is not updated until after a call to $digest which typically is done by + * Angular automatically. + * + * If you need access to the bound view, there are two ways to do it: + * + * - If you are not asking the linking function to clone the template, create the DOM element(s) + * before you send them to the compiler and keep this reference around. + *
+ *     var element = $compile('

{{total}}

')(scope); + *
+ * + * - if on the other hand, you need the element to be cloned, the view reference from the original + * example would not point to the clone, but rather to the original template that was cloned. In + * this case, you can access the clone via the cloneAttachFn: + *
+ *     var templateHTML = angular.element('

{{total}}

'), + * scope = ....; + * + * var clonedElement = $compile(templateHTML)(scope, function(clonedElement, scope) { + * //attach the clone to DOM document at the right place + * }); + * + * //now we have reference to the cloned DOM via `clone` + *
+ * + * + * For information on how the compiler works, see the + * {@link guide/compiler Angular HTML Compiler} section of the Developer Guide. + */ + + +/** + * @ngdoc service + * @name ng.$compileProvider + * @function + * + * @description + */ +$CompileProvider.$inject = ['$provide']; +function $CompileProvider($provide) { + var hasDirectives = {}, + Suffix = 'Directive', + COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/, + CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/, + MULTI_ROOT_TEMPLATE_ERROR = 'Template must have exactly one root element. was: '; + + + /** + * @ngdoc function + * @name ng.$compileProvider#directive + * @methodOf ng.$compileProvider + * @function + * + * @description + * Register a new directives with the compiler. + * + * @param {string} name Name of the directive in camel-case. (ie ngBind which will match as + * ng-bind). + * @param {function} directiveFactory An injectable directive factroy function. See {@link guide/directive} for more + * info. + * @returns {ng.$compileProvider} Self for chaining. + */ + this.directive = function registerDirective(name, directiveFactory) { + if (isString(name)) { + assertArg(directiveFactory, 'directive'); + if (!hasDirectives.hasOwnProperty(name)) { + hasDirectives[name] = []; + $provide.factory(name + Suffix, ['$injector', '$exceptionHandler', + function($injector, $exceptionHandler) { + var directives = []; + forEach(hasDirectives[name], function(directiveFactory) { + try { + var directive = $injector.invoke(directiveFactory); + if (isFunction(directive)) { + directive = { compile: valueFn(directive) }; + } else if (!directive.compile && directive.link) { + directive.compile = valueFn(directive.link); + } + directive.priority = directive.priority || 0; + directive.name = directive.name || name; + directive.require = directive.require || (directive.controller && directive.name); + directive.restrict = directive.restrict || 'A'; + directives.push(directive); + } catch (e) { + $exceptionHandler(e); + } + }); + return directives; + }]); + } + hasDirectives[name].push(directiveFactory); + } else { + forEach(name, reverseParams(registerDirective)); + } + return this; + }; + + + this.$get = [ + '$injector', '$interpolate', '$exceptionHandler', '$http', '$templateCache', '$parse', + '$controller', '$rootScope', + function($injector, $interpolate, $exceptionHandler, $http, $templateCache, $parse, + $controller, $rootScope) { + + var Attributes = function(element, attr) { + this.$$element = element; + this.$attr = attr || {}; + }; + + Attributes.prototype = { + $normalize: directiveNormalize, + + + /** + * Set a normalized attribute on the element in a way such that all directives + * can share the attribute. This function properly handles boolean attributes. + * @param {string} key Normalized key. (ie ngAttribute) + * @param {string|boolean} value The value to set. If `null` attribute will be deleted. + * @param {boolean=} writeAttr If false, does not write the value to DOM element attribute. + * Defaults to true. + * @param {string=} attrName Optional none normalized name. Defaults to key. + */ + $set: function(key, value, writeAttr, attrName) { + var booleanKey = getBooleanAttrName(this.$$element[0], key), + $$observers = this.$$observers; + + if (booleanKey) { + this.$$element.prop(key, value); + attrName = booleanKey; + } + + this[key] = value; + + // translate normalized key to actual key + if (attrName) { + this.$attr[key] = attrName; + } else { + attrName = this.$attr[key]; + if (!attrName) { + this.$attr[key] = attrName = snake_case(key, '-'); + } + } + + if (writeAttr !== false) { + if (value === null || value === undefined) { + this.$$element.removeAttr(attrName); + } else { + this.$$element.attr(attrName, value); + } + } + + // fire observers + $$observers && forEach($$observers[key], function(fn) { + try { + fn(value); + } catch (e) { + $exceptionHandler(e); + } + }); + }, + + + /** + * Observe an interpolated attribute. + * The observer will never be called, if given attribute is not interpolated. + * + * @param {string} key Normalized key. (ie ngAttribute) . + * @param {function(*)} fn Function that will be called whenever the attribute value changes. + * @returns {function(*)} the `fn` Function passed in. + */ + $observe: function(key, fn) { + var attrs = this, + $$observers = (attrs.$$observers || (attrs.$$observers = {})), + listeners = ($$observers[key] || ($$observers[key] = [])); + + listeners.push(fn); + $rootScope.$evalAsync(function() { + if (!listeners.$$inter) { + // no one registered attribute interpolation function, so lets call it manually + fn(attrs[key]); + } + }); + return fn; + } + }; + + var startSymbol = $interpolate.startSymbol(), + endSymbol = $interpolate.endSymbol(), + denormalizeTemplate = (startSymbol == '{{' || endSymbol == '}}') + ? identity + : function denormalizeTemplate(template) { + return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol); + }; + + + return compile; + + //================================ + + function compile($compileNode, transcludeFn, maxPriority) { + if (!($compileNode instanceof jqLite)) { + // jquery always rewraps, where as we need to preserve the original selector so that we can modify it. + $compileNode = jqLite($compileNode); + } + // We can not compile top level text elements since text nodes can be merged and we will + // not be able to attach scope data to them, so we will wrap them in + forEach($compileNode, function(node, index){ + if (node.nodeType == 3 /* text node */) { + $compileNode[index] = jqLite(node).wrap('').parent()[0]; + } + }); + var compositeLinkFn = compileNodes($compileNode, transcludeFn, $compileNode, maxPriority); + return function(scope, cloneConnectFn){ + assertArg(scope, 'scope'); + // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart + // and sometimes changes the structure of the DOM. + var $linkNode = cloneConnectFn + ? JQLitePrototype.clone.call($compileNode) // IMPORTANT!!! + : $compileNode; + $linkNode.data('$scope', scope); + safeAddClass($linkNode, 'ng-scope'); + if (cloneConnectFn) cloneConnectFn($linkNode, scope); + if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode); + return $linkNode; + }; + } + + function wrongMode(localName, mode) { + throw Error("Unsupported '" + mode + "' for '" + localName + "'."); + } + + function safeAddClass($element, className) { + try { + $element.addClass(className); + } catch(e) { + // ignore, since it means that we are trying to set class on + // SVG element, where class name is read-only. + } + } + + /** + * Compile function matches each node in nodeList against the directives. Once all directives + * for a particular node are collected their compile functions are executed. The compile + * functions return values - the linking functions - are combined into a composite linking + * function, which is the a linking function for the node. + * + * @param {NodeList} nodeList an array of nodes to compile + * @param {function(angular.Scope[, cloneAttachFn]} transcludeFn A linking function, where the + * scope argument is auto-generated to the new child of the transcluded parent scope. + * @param {DOMElement=} $rootElement If the nodeList is the root of the compilation tree then the + * rootElement must be set the jqLite collection of the compile root. This is + * needed so that the jqLite collection items can be replaced with widgets. + * @param {number=} max directive priority + * @returns {?function} A composite linking function of all of the matched directives or null. + */ + function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority) { + var linkFns = [], + nodeLinkFn, childLinkFn, directives, attrs, linkFnFound; + + for(var i = 0; i < nodeList.length; i++) { + attrs = new Attributes(); + + // we must always refer to nodeList[i] since the nodes can be replaced underneath us. + directives = collectDirectives(nodeList[i], [], attrs, maxPriority); + + nodeLinkFn = (directives.length) + ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement) + : null; + + childLinkFn = (nodeLinkFn && nodeLinkFn.terminal) + ? null + : compileNodes(nodeList[i].childNodes, + nodeLinkFn ? nodeLinkFn.transclude : transcludeFn); + + linkFns.push(nodeLinkFn); + linkFns.push(childLinkFn); + linkFnFound = (linkFnFound || nodeLinkFn || childLinkFn); + } + + // return a linking function if we have found anything, null otherwise + return linkFnFound ? compositeLinkFn : null; + + function compositeLinkFn(scope, nodeList, $rootElement, boundTranscludeFn) { + var nodeLinkFn, childLinkFn, node, childScope, childTranscludeFn; + + for(var i = 0, n = 0, ii = linkFns.length; i < ii; n++) { + node = nodeList[n]; + nodeLinkFn = linkFns[i++]; + childLinkFn = linkFns[i++]; + + if (nodeLinkFn) { + if (nodeLinkFn.scope) { + childScope = scope.$new(isObject(nodeLinkFn.scope)); + jqLite(node).data('$scope', childScope); + } else { + childScope = scope; + } + childTranscludeFn = nodeLinkFn.transclude; + if (childTranscludeFn || (!boundTranscludeFn && transcludeFn)) { + nodeLinkFn(childLinkFn, childScope, node, $rootElement, + (function(transcludeFn) { + return function(cloneFn) { + var transcludeScope = scope.$new(); + + return transcludeFn(transcludeScope, cloneFn). + bind('$destroy', bind(transcludeScope, transcludeScope.$destroy)); + }; + })(childTranscludeFn || transcludeFn) + ); + } else { + nodeLinkFn(childLinkFn, childScope, node, undefined, boundTranscludeFn); + } + } else if (childLinkFn) { + childLinkFn(scope, node.childNodes, undefined, boundTranscludeFn); + } + } + } + } + + + /** + * Looks for directives on the given node ands them to the directive collection which is sorted. + * + * @param node node to search + * @param directives an array to which the directives are added to. This array is sorted before + * the function returns. + * @param attrs the shared attrs object which is used to populate the normalized attributes. + * @param {number=} max directive priority + */ + function collectDirectives(node, directives, attrs, maxPriority) { + var nodeType = node.nodeType, + attrsMap = attrs.$attr, + match, + className; + + switch(nodeType) { + case 1: /* Element */ + // use the node name: + addDirective(directives, + directiveNormalize(nodeName_(node).toLowerCase()), 'E', maxPriority); + + // iterate over the attributes + for (var attr, name, nName, value, nAttrs = node.attributes, + j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) { + attr = nAttrs[j]; + if (attr.specified) { + name = attr.name; + nName = directiveNormalize(name.toLowerCase()); + attrsMap[nName] = name; + attrs[nName] = value = trim((msie && name == 'href') + ? decodeURIComponent(node.getAttribute(name, 2)) + : attr.value); + if (getBooleanAttrName(node, nName)) { + attrs[nName] = true; // presence means true + } + addAttrInterpolateDirective(node, directives, value, nName); + addDirective(directives, nName, 'A', maxPriority); + } + } + + // use class as directive + className = node.className; + if (isString(className)) { + while (match = CLASS_DIRECTIVE_REGEXP.exec(className)) { + nName = directiveNormalize(match[2]); + if (addDirective(directives, nName, 'C', maxPriority)) { + attrs[nName] = trim(match[3]); + } + className = className.substr(match.index + match[0].length); + } + } + break; + case 3: /* Text Node */ + addTextInterpolateDirective(directives, node.nodeValue); + break; + case 8: /* Comment */ + try { + match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue); + if (match) { + nName = directiveNormalize(match[1]); + if (addDirective(directives, nName, 'M', maxPriority)) { + attrs[nName] = trim(match[2]); + } + } + } catch (e) { + // turns out that under some circumstances IE9 throws errors when one attempts to read comment's node value. + // Just ignore it and continue. (Can't seem to reproduce in test case.) + } + break; + } + + directives.sort(byPriority); + return directives; + } + + + /** + * Once the directives have been collected their compile functions is executed. This method + * is responsible for inlining directive templates as well as terminating the application + * of the directives if the terminal directive has been reached.. + * + * @param {Array} directives Array of collected directives to execute their compile function. + * this needs to be pre-sorted by priority order. + * @param {Node} compileNode The raw DOM node to apply the compile functions to + * @param {Object} templateAttrs The shared attribute function + * @param {function(angular.Scope[, cloneAttachFn]} transcludeFn A linking function, where the + * scope argument is auto-generated to the new child of the transcluded parent scope. + * @param {DOMElement} $rootElement If we are working on the root of the compile tree then this + * argument has the root jqLite array so that we can replace widgets on it. + * @returns linkFn + */ + function applyDirectivesToNode(directives, compileNode, templateAttrs, transcludeFn, $rootElement) { + var terminalPriority = -Number.MAX_VALUE, + preLinkFns = [], + postLinkFns = [], + newScopeDirective = null, + newIsolatedScopeDirective = null, + templateDirective = null, + $compileNode = templateAttrs.$$element = jqLite(compileNode), + directive, + directiveName, + $template, + transcludeDirective, + childTranscludeFn = transcludeFn, + controllerDirectives, + linkFn, + directiveValue; + + // executes all directives on the current element + for(var i = 0, ii = directives.length; i < ii; i++) { + directive = directives[i]; + $template = undefined; + + if (terminalPriority > directive.priority) { + break; // prevent further processing of directives + } + + if (directiveValue = directive.scope) { + assertNoDuplicate('isolated scope', newIsolatedScopeDirective, directive, $compileNode); + if (isObject(directiveValue)) { + safeAddClass($compileNode, 'ng-isolate-scope'); + newIsolatedScopeDirective = directive; + } + safeAddClass($compileNode, 'ng-scope'); + newScopeDirective = newScopeDirective || directive; + } + + directiveName = directive.name; + + if (directiveValue = directive.controller) { + controllerDirectives = controllerDirectives || {}; + assertNoDuplicate("'" + directiveName + "' controller", + controllerDirectives[directiveName], directive, $compileNode); + controllerDirectives[directiveName] = directive; + } + + if (directiveValue = directive.transclude) { + assertNoDuplicate('transclusion', transcludeDirective, directive, $compileNode); + transcludeDirective = directive; + terminalPriority = directive.priority; + if (directiveValue == 'element') { + $template = jqLite(compileNode); + $compileNode = templateAttrs.$$element = + jqLite(''); + compileNode = $compileNode[0]; + replaceWith($rootElement, jqLite($template[0]), compileNode); + childTranscludeFn = compile($template, transcludeFn, terminalPriority); + } else { + $template = jqLite(JQLiteClone(compileNode)).contents(); + $compileNode.html(''); // clear contents + childTranscludeFn = compile($template, transcludeFn); + } + } + + if ((directiveValue = directive.template)) { + assertNoDuplicate('template', templateDirective, directive, $compileNode); + templateDirective = directive; + directiveValue = denormalizeTemplate(directiveValue); + + if (directive.replace) { + $template = jqLite('
' + + trim(directiveValue) + + '
').contents(); + compileNode = $template[0]; + + if ($template.length != 1 || compileNode.nodeType !== 1) { + throw new Error(MULTI_ROOT_TEMPLATE_ERROR + directiveValue); + } + + replaceWith($rootElement, $compileNode, compileNode); + + var newTemplateAttrs = {$attr: {}}; + + // combine directives from the original node and from the template: + // - take the array of directives for this element + // - split it into two parts, those that were already applied and those that weren't + // - collect directives from the template, add them to the second group and sort them + // - append the second group with new directives to the first group + directives = directives.concat( + collectDirectives( + compileNode, + directives.splice(i + 1, directives.length - (i + 1)), + newTemplateAttrs + ) + ); + mergeTemplateAttributes(templateAttrs, newTemplateAttrs); + + ii = directives.length; + } else { + $compileNode.html(directiveValue); + } + } + + if (directive.templateUrl) { + assertNoDuplicate('template', templateDirective, directive, $compileNode); + templateDirective = directive; + nodeLinkFn = compileTemplateUrl(directives.splice(i, directives.length - i), + nodeLinkFn, $compileNode, templateAttrs, $rootElement, directive.replace, + childTranscludeFn); + ii = directives.length; + } else if (directive.compile) { + try { + linkFn = directive.compile($compileNode, templateAttrs, childTranscludeFn); + if (isFunction(linkFn)) { + addLinkFns(null, linkFn); + } else if (linkFn) { + addLinkFns(linkFn.pre, linkFn.post); + } + } catch (e) { + $exceptionHandler(e, startingTag($compileNode)); + } + } + + if (directive.terminal) { + nodeLinkFn.terminal = true; + terminalPriority = Math.max(terminalPriority, directive.priority); + } + + } + + nodeLinkFn.scope = newScopeDirective && newScopeDirective.scope; + nodeLinkFn.transclude = transcludeDirective && childTranscludeFn; + + // might be normal or delayed nodeLinkFn depending on if templateUrl is present + return nodeLinkFn; + + //////////////////// + + function addLinkFns(pre, post) { + if (pre) { + pre.require = directive.require; + preLinkFns.push(pre); + } + if (post) { + post.require = directive.require; + postLinkFns.push(post); + } + } + + + function getControllers(require, $element) { + var value, retrievalMethod = 'data', optional = false; + if (isString(require)) { + while((value = require.charAt(0)) == '^' || value == '?') { + require = require.substr(1); + if (value == '^') { + retrievalMethod = 'inheritedData'; + } + optional = optional || value == '?'; + } + value = $element[retrievalMethod]('$' + require + 'Controller'); + if (!value && !optional) { + throw Error("No controller: " + require); + } + return value; + } else if (isArray(require)) { + value = []; + forEach(require, function(require) { + value.push(getControllers(require, $element)); + }); + } + return value; + } + + + function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn) { + var attrs, $element, i, ii, linkFn, controller; + + if (compileNode === linkNode) { + attrs = templateAttrs; + } else { + attrs = shallowCopy(templateAttrs, new Attributes(jqLite(linkNode), templateAttrs.$attr)); + } + $element = attrs.$$element; + + if (newScopeDirective && isObject(newScopeDirective.scope)) { + var LOCAL_REGEXP = /^\s*([@=&])\s*(\w*)\s*$/; + + var parentScope = scope.$parent || scope; + + forEach(newScopeDirective.scope, function(definiton, scopeName) { + var match = definiton.match(LOCAL_REGEXP) || [], + attrName = match[2]|| scopeName, + mode = match[1], // @, =, or & + lastValue, + parentGet, parentSet; + + switch (mode) { + + case '@': { + attrs.$observe(attrName, function(value) { + scope[scopeName] = value; + }); + attrs.$$observers[attrName].$$scope = parentScope; + break; + } + + case '=': { + parentGet = $parse(attrs[attrName]); + parentSet = parentGet.assign || function() { + // reset the change, or we will throw this exception on every $digest + lastValue = scope[scopeName] = parentGet(parentScope); + throw Error(NON_ASSIGNABLE_MODEL_EXPRESSION + attrs[attrName] + + ' (directive: ' + newScopeDirective.name + ')'); + }; + lastValue = scope[scopeName] = parentGet(parentScope); + scope.$watch(function() { + var parentValue = parentGet(parentScope); + + if (parentValue !== scope[scopeName]) { + // we are out of sync and need to copy + if (parentValue !== lastValue) { + // parent changed and it has precedence + lastValue = scope[scopeName] = parentValue; + } else { + // if the parent can be assigned then do so + parentSet(parentScope, lastValue = scope[scopeName]); + } + } + return parentValue; + }); + break; + } + + case '&': { + parentGet = $parse(attrs[attrName]); + scope[scopeName] = function(locals) { + return parentGet(parentScope, locals); + } + break; + } + + default: { + throw Error('Invalid isolate scope definition for directive ' + + newScopeDirective.name + ': ' + definiton); + } + } + }); + } + + if (controllerDirectives) { + forEach(controllerDirectives, function(directive) { + var locals = { + $scope: scope, + $element: $element, + $attrs: attrs, + $transclude: boundTranscludeFn + }; + + controller = directive.controller; + if (controller == '@') { + controller = attrs[directive.name]; + } + + $element.data( + '$' + directive.name + 'Controller', + $controller(controller, locals)); + }); + } + + // PRELINKING + for(i = 0, ii = preLinkFns.length; i < ii; i++) { + try { + linkFn = preLinkFns[i]; + linkFn(scope, $element, attrs, + linkFn.require && getControllers(linkFn.require, $element)); + } catch (e) { + $exceptionHandler(e, startingTag($element)); + } + } + + // RECURSION + childLinkFn && childLinkFn(scope, linkNode.childNodes, undefined, boundTranscludeFn); + + // POSTLINKING + for(i = 0, ii = postLinkFns.length; i < ii; i++) { + try { + linkFn = postLinkFns[i]; + linkFn(scope, $element, attrs, + linkFn.require && getControllers(linkFn.require, $element)); + } catch (e) { + $exceptionHandler(e, startingTag($element)); + } + } + } + } + + + /** + * looks up the directive and decorates it with exception handling and proper parameters. We + * call this the boundDirective. + * + * @param {string} name name of the directive to look up. + * @param {string} location The directive must be found in specific format. + * String containing any of theses characters: + * + * * `E`: element name + * * `A': attribute + * * `C`: class + * * `M`: comment + * @returns true if directive was added. + */ + function addDirective(tDirectives, name, location, maxPriority) { + var match = false; + if (hasDirectives.hasOwnProperty(name)) { + for(var directive, directives = $injector.get(name + Suffix), + i = 0, ii = directives.length; i directive.priority) && + directive.restrict.indexOf(location) != -1) { + tDirectives.push(directive); + match = true; + } + } catch(e) { $exceptionHandler(e); } + } + } + return match; + } + + + /** + * When the element is replaced with HTML template then the new attributes + * on the template need to be merged with the existing attributes in the DOM. + * The desired effect is to have both of the attributes present. + * + * @param {object} dst destination attributes (original DOM) + * @param {object} src source attributes (from the directive template) + */ + function mergeTemplateAttributes(dst, src) { + var srcAttr = src.$attr, + dstAttr = dst.$attr, + $element = dst.$$element; + + // reapply the old attributes to the new element + forEach(dst, function(value, key) { + if (key.charAt(0) != '$') { + if (src[key]) { + value += (key === 'style' ? ';' : ' ') + src[key]; + } + dst.$set(key, value, true, srcAttr[key]); + } + }); + + // copy the new attributes on the old attrs object + forEach(src, function(value, key) { + if (key == 'class') { + safeAddClass($element, value); + dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value; + } else if (key == 'style') { + $element.attr('style', $element.attr('style') + ';' + value); + } else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) { + dst[key] = value; + dstAttr[key] = srcAttr[key]; + } + }); + } + + + function compileTemplateUrl(directives, beforeTemplateNodeLinkFn, $compileNode, tAttrs, + $rootElement, replace, childTranscludeFn) { + var linkQueue = [], + afterTemplateNodeLinkFn, + afterTemplateChildLinkFn, + beforeTemplateCompileNode = $compileNode[0], + origAsyncDirective = directives.shift(), + // The fact that we have to copy and patch the directive seems wrong! + derivedSyncDirective = extend({}, origAsyncDirective, { + controller: null, templateUrl: null, transclude: null + }); + + $compileNode.html(''); + + $http.get(origAsyncDirective.templateUrl, {cache: $templateCache}). + success(function(content) { + var compileNode, tempTemplateAttrs, $template; + + content = denormalizeTemplate(content); + + if (replace) { + $template = jqLite('
' + trim(content) + '
').contents(); + compileNode = $template[0]; + + if ($template.length != 1 || compileNode.nodeType !== 1) { + throw new Error(MULTI_ROOT_TEMPLATE_ERROR + content); + } + + tempTemplateAttrs = {$attr: {}}; + replaceWith($rootElement, $compileNode, compileNode); + collectDirectives(compileNode, directives, tempTemplateAttrs); + mergeTemplateAttributes(tAttrs, tempTemplateAttrs); + } else { + compileNode = beforeTemplateCompileNode; + $compileNode.html(content); + } + + directives.unshift(derivedSyncDirective); + afterTemplateNodeLinkFn = applyDirectivesToNode(directives, $compileNode, tAttrs, childTranscludeFn); + afterTemplateChildLinkFn = compileNodes($compileNode.contents(), childTranscludeFn); + + + while(linkQueue.length) { + var controller = linkQueue.pop(), + linkRootElement = linkQueue.pop(), + beforeTemplateLinkNode = linkQueue.pop(), + scope = linkQueue.pop(), + linkNode = compileNode; + + if (beforeTemplateLinkNode !== beforeTemplateCompileNode) { + // it was cloned therefore we have to clone as well. + linkNode = JQLiteClone(compileNode); + replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode); + } + + afterTemplateNodeLinkFn(function() { + beforeTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement, controller); + }, scope, linkNode, $rootElement, controller); + } + linkQueue = null; + }). + error(function(response, code, headers, config) { + throw Error('Failed to load template: ' + config.url); + }); + + return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, controller) { + if (linkQueue) { + linkQueue.push(scope); + linkQueue.push(node); + linkQueue.push(rootElement); + linkQueue.push(controller); + } else { + afterTemplateNodeLinkFn(function() { + beforeTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, controller); + }, scope, node, rootElement, controller); + } + }; + } + + + /** + * Sorting function for bound directives. + */ + function byPriority(a, b) { + return b.priority - a.priority; + } + + + function assertNoDuplicate(what, previousDirective, directive, element) { + if (previousDirective) { + throw Error('Multiple directives [' + previousDirective.name + ', ' + + directive.name + '] asking for ' + what + ' on: ' + startingTag(element)); + } + } + + + function addTextInterpolateDirective(directives, text) { + var interpolateFn = $interpolate(text, true); + if (interpolateFn) { + directives.push({ + priority: 0, + compile: valueFn(function(scope, node) { + var parent = node.parent(), + bindings = parent.data('$binding') || []; + bindings.push(interpolateFn); + safeAddClass(parent.data('$binding', bindings), 'ng-binding'); + scope.$watch(interpolateFn, function(value) { + node[0].nodeValue = value; + }); + }) + }); + } + } + + + function addAttrInterpolateDirective(node, directives, value, name) { + var interpolateFn = $interpolate(value, true); + + + // no interpolation found -> ignore + if (!interpolateFn) return; + + directives.push({ + priority: 100, + compile: valueFn(function(scope, element, attr) { + var $$observers = (attr.$$observers || (attr.$$observers = {})); + + if (name === 'class') { + // we need to interpolate classes again, in the case the element was replaced + // and therefore the two class attrs got merged - we want to interpolate the result + interpolateFn = $interpolate(attr[name], true); + } + + attr[name] = undefined; + ($$observers[name] || ($$observers[name] = [])).$$inter = true; + (attr.$$observers && attr.$$observers[name].$$scope || scope). + $watch(interpolateFn, function(value) { + attr.$set(name, value); + }); + }) + }); + } + + + /** + * This is a special jqLite.replaceWith, which can replace items which + * have no parents, provided that the containing jqLite collection is provided. + * + * @param {JqLite=} $rootElement The root of the compile tree. Used so that we can replace nodes + * in the root of the tree. + * @param {JqLite} $element The jqLite element which we are going to replace. We keep the shell, + * but replace its DOM node reference. + * @param {Node} newNode The new DOM node. + */ + function replaceWith($rootElement, $element, newNode) { + var oldNode = $element[0], + parent = oldNode.parentNode, + i, ii; + + if ($rootElement) { + for(i = 0, ii = $rootElement.length; i < ii; i++) { + if ($rootElement[i] == oldNode) { + $rootElement[i] = newNode; + break; + } + } + } + + if (parent) { + parent.replaceChild(newNode, oldNode); + } + + newNode[jqLite.expando] = oldNode[jqLite.expando]; + $element[0] = newNode; + } + }]; +} + +var PREFIX_REGEXP = /^(x[\:\-_]|data[\:\-_])/i; +/** + * Converts all accepted directives format into proper directive name. + * All of these will become 'myDirective': + * my:DiRective + * my-directive + * x-my-directive + * data-my:directive + * + * Also there is special case for Moz prefix starting with upper case letter. + * @param name Name to normalize + */ +function directiveNormalize(name) { + return camelCase(name.replace(PREFIX_REGEXP, '')); +} + +/** + * @ngdoc object + * @name ng.$compile.directive.Attributes + * @description + * + * A shared object between directive compile / linking functions which contains normalized DOM element + * attributes. The the values reflect current binding state `{{ }}`. The normalization is needed + * since all of these are treated as equivalent in Angular: + * + * + */ + +/** + * @ngdoc property + * @name ng.$compile.directive.Attributes#$attr + * @propertyOf ng.$compile.directive.Attributes + * @returns {object} A map of DOM element attribute names to the normalized name. This is + * needed to do reverse lookup from normalized name back to actual name. + */ + + +/** + * @ngdoc function + * @name ng.$compile.directive.Attributes#$set + * @methodOf ng.$compile.directive.Attributes + * @function + * + * @description + * Set DOM element attribute value. + * + * + * @param {string} name Normalized element attribute name of the property to modify. The name is + * revers translated using the {@link ng.$compile.directive.Attributes#$attr $attr} + * property to the original name. + * @param {string} value Value to set the attribute to. + */ + + + +/** + * Closure compiler type information + */ + +function nodesetLinkingFn( + /* angular.Scope */ scope, + /* NodeList */ nodeList, + /* Element */ rootElement, + /* function(Function) */ boundTranscludeFn +){} + +function directiveLinkingFn( + /* nodesetLinkingFn */ nodesetLinkingFn, + /* angular.Scope */ scope, + /* Node */ node, + /* Element */ rootElement, + /* function(Function) */ boundTranscludeFn +){} + +/** + * @ngdoc object + * @name ng.$controllerProvider + * @description + * The {@link ng.$controller $controller service} is used by Angular to create new + * controllers. + * + * This provider allows controller registration via the + * {@link ng.$controllerProvider#register register} method. + */ +function $ControllerProvider() { + var controllers = {}; + + + /** + * @ngdoc function + * @name ng.$controllerProvider#register + * @methodOf ng.$controllerProvider + * @param {string} name Controller name + * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI + * annotations in the array notation). + */ + this.register = function(name, constructor) { + if (isObject(name)) { + extend(controllers, name) + } else { + controllers[name] = constructor; + } + }; + + + this.$get = ['$injector', '$window', function($injector, $window) { + + /** + * @ngdoc function + * @name ng.$controller + * @requires $injector + * + * @param {Function|string} constructor If called with a function then it's considered to be the + * controller constructor function. Otherwise it's considered to be a string which is used + * to retrieve the controller constructor using the following steps: + * + * * check if a controller with given name is registered via `$controllerProvider` + * * check if evaluating the string on the current scope returns a constructor + * * check `window[constructor]` on the global `window` object + * + * @param {Object} locals Injection locals for Controller. + * @return {Object} Instance of given controller. + * + * @description + * `$controller` service is responsible for instantiating controllers. + * + * It's just simple call to {@link AUTO.$injector $injector}, but extracted into + * a service, so that one can override this service with {@link https://gist.github.com/1649788 + * BC version}. + */ + return function(constructor, locals) { + if(isString(constructor)) { + var name = constructor; + constructor = controllers.hasOwnProperty(name) + ? controllers[name] + : getter(locals.$scope, name, true) || getter($window, name, true); + + assertArgFn(constructor, name, true); + } + + return $injector.instantiate(constructor, locals); + }; + }]; +} + +/** + * @ngdoc object + * @name ng.$document + * @requires $window + * + * @description + * A {@link angular.element jQuery (lite)}-wrapped reference to the browser's `window.document` + * element. + */ +function $DocumentProvider(){ + this.$get = ['$window', function(window){ + return jqLite(window.document); + }]; +} + +/** + * @ngdoc function + * @name ng.$exceptionHandler + * @requires $log + * + * @description + * Any uncaught exception in angular expressions is delegated to this service. + * The default implementation simply delegates to `$log.error` which logs it into + * the browser console. + * + * In unit tests, if `angular-mocks.js` is loaded, this service is overridden by + * {@link ngMock.$exceptionHandler mock $exceptionHandler} + * + * @param {Error} exception Exception associated with the error. + * @param {string=} cause optional information about the context in which + * the error was thrown. + */ +function $ExceptionHandlerProvider() { + this.$get = ['$log', function($log){ + return function(exception, cause) { + $log.error.apply($log, arguments); + }; + }]; +} + +/** + * @ngdoc object + * @name ng.$interpolateProvider + * @function + * + * @description + * + * Used for configuring the interpolation markup. Defaults to `{{` and `}}`. + */ +function $InterpolateProvider() { + var startSymbol = '{{'; + var endSymbol = '}}'; + + /** + * @ngdoc method + * @name ng.$interpolateProvider#startSymbol + * @methodOf ng.$interpolateProvider + * @description + * Symbol to denote start of expression in the interpolated string. Defaults to `{{`. + * + * @param {string=} value new value to set the starting symbol to. + * @returns {string|self} Returns the symbol when used as getter and self if used as setter. + */ + this.startSymbol = function(value){ + if (value) { + startSymbol = value; + return this; + } else { + return startSymbol; + } + }; + + /** + * @ngdoc method + * @name ng.$interpolateProvider#endSymbol + * @methodOf ng.$interpolateProvider + * @description + * Symbol to denote the end of expression in the interpolated string. Defaults to `}}`. + * + * @param {string=} value new value to set the ending symbol to. + * @returns {string|self} Returns the symbol when used as getter and self if used as setter. + */ + this.endSymbol = function(value){ + if (value) { + endSymbol = value; + return this; + } else { + return endSymbol; + } + }; + + + this.$get = ['$parse', function($parse) { + var startSymbolLength = startSymbol.length, + endSymbolLength = endSymbol.length; + + /** + * @ngdoc function + * @name ng.$interpolate + * @function + * + * @requires $parse + * + * @description + * + * Compiles a string with markup into an interpolation function. This service is used by the + * HTML {@link ng.$compile $compile} service for data binding. See + * {@link ng.$interpolateProvider $interpolateProvider} for configuring the + * interpolation markup. + * + * +
+         var $interpolate = ...; // injected
+         var exp = $interpolate('Hello {{name}}!');
+         expect(exp({name:'Angular'}).toEqual('Hello Angular!');
+       
+ * + * + * @param {string} text The text with markup to interpolate. + * @param {boolean=} mustHaveExpression if set to true then the interpolation string must have + * embedded expression in order to return an interpolation function. Strings with no + * embedded expression will return null for the interpolation function. + * @returns {function(context)} an interpolation function which is used to compute the interpolated + * string. The function has these parameters: + * + * * `context`: an object against which any expressions embedded in the strings are evaluated + * against. + * + */ + function $interpolate(text, mustHaveExpression) { + var startIndex, + endIndex, + index = 0, + parts = [], + length = text.length, + hasInterpolation = false, + fn, + exp, + concat = []; + + while(index < length) { + if ( ((startIndex = text.indexOf(startSymbol, index)) != -1) && + ((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) != -1) ) { + (index != startIndex) && parts.push(text.substring(index, startIndex)); + parts.push(fn = $parse(exp = text.substring(startIndex + startSymbolLength, endIndex))); + fn.exp = exp; + index = endIndex + endSymbolLength; + hasInterpolation = true; + } else { + // we did not find anything, so we have to add the remainder to the parts array + (index != length) && parts.push(text.substring(index)); + index = length; + } + } + + if (!(length = parts.length)) { + // we added, nothing, must have been an empty string. + parts.push(''); + length = 1; + } + + if (!mustHaveExpression || hasInterpolation) { + concat.length = length; + fn = function(context) { + for(var i = 0, ii = length, part; i html5 url + } else { + return composeProtocolHostPort(match.protocol, match.host, match.port) + + pathPrefixFromBase(basePath) + match.hash.substr(hashPrefix.length); + } +} + + +function convertToHashbangUrl(url, basePath, hashPrefix) { + var match = matchUrl(url); + + // already hashbang url + if (decodeURIComponent(match.path) == basePath) { + return url; + // convert html5 url -> hashbang url + } else { + var search = match.search && '?' + match.search || '', + hash = match.hash && '#' + match.hash || '', + pathPrefix = pathPrefixFromBase(basePath), + path = match.path.substr(pathPrefix.length); + + if (match.path.indexOf(pathPrefix) !== 0) { + throw Error('Invalid url "' + url + '", missing path prefix "' + pathPrefix + '" !'); + } + + return composeProtocolHostPort(match.protocol, match.host, match.port) + basePath + + '#' + hashPrefix + path + search + hash; + } +} + + +/** + * LocationUrl represents an url + * This object is exposed as $location service when HTML5 mode is enabled and supported + * + * @constructor + * @param {string} url HTML5 url + * @param {string} pathPrefix + */ +function LocationUrl(url, pathPrefix, appBaseUrl) { + pathPrefix = pathPrefix || ''; + + /** + * Parse given html5 (regular) url string into properties + * @param {string} newAbsoluteUrl HTML5 url + * @private + */ + this.$$parse = function(newAbsoluteUrl) { + var match = matchUrl(newAbsoluteUrl, this); + + if (match.path.indexOf(pathPrefix) !== 0) { + throw Error('Invalid url "' + newAbsoluteUrl + '", missing path prefix "' + pathPrefix + '" !'); + } + + this.$$path = decodeURIComponent(match.path.substr(pathPrefix.length)); + this.$$search = parseKeyValue(match.search); + this.$$hash = match.hash && decodeURIComponent(match.hash) || ''; + + this.$$compose(); + }; + + /** + * Compose url and update `absUrl` property + * @private + */ + this.$$compose = function() { + var search = toKeyValue(this.$$search), + hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; + + this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; + this.$$absUrl = composeProtocolHostPort(this.$$protocol, this.$$host, this.$$port) + + pathPrefix + this.$$url; + }; + + + this.$$rewriteAppUrl = function(absoluteLinkUrl) { + if(absoluteLinkUrl.indexOf(appBaseUrl) == 0) { + return absoluteLinkUrl; + } + } + + + this.$$parse(url); +} + + +/** + * LocationHashbangUrl represents url + * This object is exposed as $location service when html5 history api is disabled or not supported + * + * @constructor + * @param {string} url Legacy url + * @param {string} hashPrefix Prefix for hash part (containing path and search) + */ +function LocationHashbangUrl(url, hashPrefix, appBaseUrl) { + var basePath; + + /** + * Parse given hashbang url into properties + * @param {string} url Hashbang url + * @private + */ + this.$$parse = function(url) { + var match = matchUrl(url, this); + + + if (match.hash && match.hash.indexOf(hashPrefix) !== 0) { + throw Error('Invalid url "' + url + '", missing hash prefix "' + hashPrefix + '" !'); + } + + basePath = match.path + (match.search ? '?' + match.search : ''); + match = HASH_MATCH.exec((match.hash || '').substr(hashPrefix.length)); + if (match[1]) { + this.$$path = (match[1].charAt(0) == '/' ? '' : '/') + decodeURIComponent(match[1]); + } else { + this.$$path = ''; + } + + this.$$search = parseKeyValue(match[3]); + this.$$hash = match[5] && decodeURIComponent(match[5]) || ''; + + this.$$compose(); + }; + + /** + * Compose hashbang url and update `absUrl` property + * @private + */ + this.$$compose = function() { + var search = toKeyValue(this.$$search), + hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; + + this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; + this.$$absUrl = composeProtocolHostPort(this.$$protocol, this.$$host, this.$$port) + + basePath + (this.$$url ? '#' + hashPrefix + this.$$url : ''); + }; + + this.$$rewriteAppUrl = function(absoluteLinkUrl) { + if(absoluteLinkUrl.indexOf(appBaseUrl) == 0) { + return absoluteLinkUrl; + } + } + + + this.$$parse(url); +} + + +LocationUrl.prototype = { + + /** + * Has any change been replacing ? + * @private + */ + $$replace: false, + + /** + * @ngdoc method + * @name ng.$location#absUrl + * @methodOf ng.$location + * + * @description + * This method is getter only. + * + * Return full url representation with all segments encoded according to rules specified in + * {@link http://www.ietf.org/rfc/rfc3986.txt RFC 3986}. + * + * @return {string} full url + */ + absUrl: locationGetter('$$absUrl'), + + /** + * @ngdoc method + * @name ng.$location#url + * @methodOf ng.$location + * + * @description + * This method is getter / setter. + * + * Return url (e.g. `/path?a=b#hash`) when called without any parameter. + * + * Change path, search and hash, when called with parameter and return `$location`. + * + * @param {string=} url New url without base prefix (e.g. `/path?a=b#hash`) + * @return {string} url + */ + url: function(url, replace) { + if (isUndefined(url)) + return this.$$url; + + var match = PATH_MATCH.exec(url); + if (match[1]) this.path(decodeURIComponent(match[1])); + if (match[2] || match[1]) this.search(match[3] || ''); + this.hash(match[5] || '', replace); + + return this; + }, + + /** + * @ngdoc method + * @name ng.$location#protocol + * @methodOf ng.$location + * + * @description + * This method is getter only. + * + * Return protocol of current url. + * + * @return {string} protocol of current url + */ + protocol: locationGetter('$$protocol'), + + /** + * @ngdoc method + * @name ng.$location#host + * @methodOf ng.$location + * + * @description + * This method is getter only. + * + * Return host of current url. + * + * @return {string} host of current url. + */ + host: locationGetter('$$host'), + + /** + * @ngdoc method + * @name ng.$location#port + * @methodOf ng.$location + * + * @description + * This method is getter only. + * + * Return port of current url. + * + * @return {Number} port + */ + port: locationGetter('$$port'), + + /** + * @ngdoc method + * @name ng.$location#path + * @methodOf ng.$location + * + * @description + * This method is getter / setter. + * + * Return path of current url when called without any parameter. + * + * Change path when called with parameter and return `$location`. + * + * Note: Path should always begin with forward slash (/), this method will add the forward slash + * if it is missing. + * + * @param {string=} path New path + * @return {string} path + */ + path: locationGetterSetter('$$path', function(path) { + return path.charAt(0) == '/' ? path : '/' + path; + }), + + /** + * @ngdoc method + * @name ng.$location#search + * @methodOf ng.$location + * + * @description + * This method is getter / setter. + * + * Return search part (as object) of current url when called without any parameter. + * + * Change search part when called with parameter and return `$location`. + * + * @param {string|object=} search New search params - string or hash object + * @param {string=} paramValue If `search` is a string, then `paramValue` will override only a + * single search parameter. If the value is `null`, the parameter will be deleted. + * + * @return {string} search + */ + search: function(search, paramValue) { + if (isUndefined(search)) + return this.$$search; + + if (isDefined(paramValue)) { + if (paramValue === null) { + delete this.$$search[search]; + } else { + this.$$search[search] = paramValue; + } + } else { + this.$$search = isString(search) ? parseKeyValue(search) : search; + } + + this.$$compose(); + return this; + }, + + /** + * @ngdoc method + * @name ng.$location#hash + * @methodOf ng.$location + * + * @description + * This method is getter / setter. + * + * Return hash fragment when called without any parameter. + * + * Change hash fragment when called with parameter and return `$location`. + * + * @param {string=} hash New hash fragment + * @return {string} hash + */ + hash: locationGetterSetter('$$hash', identity), + + /** + * @ngdoc method + * @name ng.$location#replace + * @methodOf ng.$location + * + * @description + * If called, all changes to $location during current `$digest` will be replacing current history + * record, instead of adding new one. + */ + replace: function() { + this.$$replace = true; + return this; + } +}; + +LocationHashbangUrl.prototype = inherit(LocationUrl.prototype); + +function LocationHashbangInHtml5Url(url, hashPrefix, appBaseUrl, baseExtra) { + LocationHashbangUrl.apply(this, arguments); + + + this.$$rewriteAppUrl = function(absoluteLinkUrl) { + if (absoluteLinkUrl.indexOf(appBaseUrl) == 0) { + return appBaseUrl + baseExtra + '#' + hashPrefix + absoluteLinkUrl.substr(appBaseUrl.length); + } + } +} + +LocationHashbangInHtml5Url.prototype = inherit(LocationHashbangUrl.prototype); + +function locationGetter(property) { + return function() { + return this[property]; + }; +} + + +function locationGetterSetter(property, preprocess) { + return function(value) { + if (isUndefined(value)) + return this[property]; + + this[property] = preprocess(value); + this.$$compose(); + + return this; + }; +} + + +/** + * @ngdoc object + * @name ng.$location + * + * @requires $browser + * @requires $sniffer + * @requires $rootElement + * + * @description + * The $location service parses the URL in the browser address bar (based on the + * {@link https://developer.mozilla.org/en/window.location window.location}) and makes the URL + * available to your application. Changes to the URL in the address bar are reflected into + * $location service and changes to $location are reflected into the browser address bar. + * + * **The $location service:** + * + * - Exposes the current URL in the browser address bar, so you can + * - Watch and observe the URL. + * - Change the URL. + * - Synchronizes the URL with the browser when the user + * - Changes the address bar. + * - Clicks the back or forward button (or clicks a History link). + * - Clicks on a link. + * - Represents the URL object as a set of methods (protocol, host, port, path, search, hash). + * + * For more information see {@link guide/dev_guide.services.$location Developer Guide: Angular + * Services: Using $location} + */ + +/** + * @ngdoc object + * @name ng.$locationProvider + * @description + * Use the `$locationProvider` to configure how the application deep linking paths are stored. + */ +function $LocationProvider(){ + var hashPrefix = '', + html5Mode = false; + + /** + * @ngdoc property + * @name ng.$locationProvider#hashPrefix + * @methodOf ng.$locationProvider + * @description + * @param {string=} prefix Prefix for hash part (containing path and search) + * @returns {*} current value if used as getter or itself (chaining) if used as setter + */ + this.hashPrefix = function(prefix) { + if (isDefined(prefix)) { + hashPrefix = prefix; + return this; + } else { + return hashPrefix; + } + }; + + /** + * @ngdoc property + * @name ng.$locationProvider#html5Mode + * @methodOf ng.$locationProvider + * @description + * @param {string=} mode Use HTML5 strategy if available. + * @returns {*} current value if used as getter or itself (chaining) if used as setter + */ + this.html5Mode = function(mode) { + if (isDefined(mode)) { + html5Mode = mode; + return this; + } else { + return html5Mode; + } + }; + + this.$get = ['$rootScope', '$browser', '$sniffer', '$rootElement', + function( $rootScope, $browser, $sniffer, $rootElement) { + var $location, + basePath, + pathPrefix, + initUrl = $browser.url(), + initUrlParts = matchUrl(initUrl), + appBaseUrl; + + if (html5Mode) { + basePath = $browser.baseHref() || '/'; + pathPrefix = pathPrefixFromBase(basePath); + appBaseUrl = + composeProtocolHostPort(initUrlParts.protocol, initUrlParts.host, initUrlParts.port) + + pathPrefix + '/'; + + if ($sniffer.history) { + $location = new LocationUrl( + convertToHtml5Url(initUrl, basePath, hashPrefix), + pathPrefix, appBaseUrl); + } else { + $location = new LocationHashbangInHtml5Url( + convertToHashbangUrl(initUrl, basePath, hashPrefix), + hashPrefix, appBaseUrl, basePath.substr(pathPrefix.length + 1)); + } + } else { + appBaseUrl = + composeProtocolHostPort(initUrlParts.protocol, initUrlParts.host, initUrlParts.port) + + (initUrlParts.path || '') + + (initUrlParts.search ? ('?' + initUrlParts.search) : '') + + '#' + hashPrefix + '/'; + + $location = new LocationHashbangUrl(initUrl, hashPrefix, appBaseUrl); + } + + $rootElement.bind('click', function(event) { + // TODO(vojta): rewrite link when opening in new tab/window (in legacy browser) + // currently we open nice url link and redirect then + + if (event.ctrlKey || event.metaKey || event.which == 2) return; + + var elm = jqLite(event.target); + + // traverse the DOM up to find first A tag + while (lowercase(elm[0].nodeName) !== 'a') { + // ignore rewriting if no A tag (reached root element, or no parent - removed from document) + if (elm[0] === $rootElement[0] || !(elm = elm.parent())[0]) return; + } + + var absHref = elm.prop('href'), + rewrittenUrl = $location.$$rewriteAppUrl(absHref); + + if (absHref && !elm.attr('target') && rewrittenUrl) { + // update location manually + $location.$$parse(rewrittenUrl); + $rootScope.$apply(); + event.preventDefault(); + // hack to work around FF6 bug 684208 when scenario runner clicks on links + window.angular['ff-684208-preventDefault'] = true; + } + }); + + + // rewrite hashbang url <> html5 url + if ($location.absUrl() != initUrl) { + $browser.url($location.absUrl(), true); + } + + // update $location when $browser url changes + $browser.onUrlChange(function(newUrl) { + if ($location.absUrl() != newUrl) { + $rootScope.$evalAsync(function() { + var oldUrl = $location.absUrl(); + + $location.$$parse(newUrl); + afterLocationChange(oldUrl); + }); + if (!$rootScope.$$phase) $rootScope.$digest(); + } + }); + + // update browser + var changeCounter = 0; + $rootScope.$watch(function $locationWatch() { + var oldUrl = $browser.url(); + + if (!changeCounter || oldUrl != $location.absUrl()) { + changeCounter++; + $rootScope.$evalAsync(function() { + if ($rootScope.$broadcast('$locationChangeStart', $location.absUrl(), oldUrl). + defaultPrevented) { + $location.$$parse(oldUrl); + } else { + $browser.url($location.absUrl(), $location.$$replace); + $location.$$replace = false; + afterLocationChange(oldUrl); + } + }); + } + + return changeCounter; + }); + + return $location; + + function afterLocationChange(oldUrl) { + $rootScope.$broadcast('$locationChangeSuccess', $location.absUrl(), oldUrl); + } +}]; +} + +/** + * @ngdoc object + * @name ng.$log + * @requires $window + * + * @description + * Simple service for logging. Default implementation writes the message + * into the browser's console (if present). + * + * The main purpose of this service is to simplify debugging and troubleshooting. + * + * @example + + + function LogCtrl($scope, $log) { + $scope.$log = $log; + $scope.message = 'Hello World!'; + } + + +
+

Reload this page with open console, enter text and hit the log button...

+ Message: + + + + + +
+
+
+ */ + +function $LogProvider(){ + this.$get = ['$window', function($window){ + return { + /** + * @ngdoc method + * @name ng.$log#log + * @methodOf ng.$log + * + * @description + * Write a log message + */ + log: consoleLog('log'), + + /** + * @ngdoc method + * @name ng.$log#warn + * @methodOf ng.$log + * + * @description + * Write a warning message + */ + warn: consoleLog('warn'), + + /** + * @ngdoc method + * @name ng.$log#info + * @methodOf ng.$log + * + * @description + * Write an information message + */ + info: consoleLog('info'), + + /** + * @ngdoc method + * @name ng.$log#error + * @methodOf ng.$log + * + * @description + * Write an error message + */ + error: consoleLog('error') + }; + + function formatError(arg) { + if (arg instanceof Error) { + if (arg.stack) { + arg = (arg.message && arg.stack.indexOf(arg.message) === -1) + ? 'Error: ' + arg.message + '\n' + arg.stack + : arg.stack; + } else if (arg.sourceURL) { + arg = arg.message + '\n' + arg.sourceURL + ':' + arg.line; + } + } + return arg; + } + + function consoleLog(type) { + var console = $window.console || {}, + logFn = console[type] || console.log || noop; + + if (logFn.apply) { + return function() { + var args = []; + forEach(arguments, function(arg) { + args.push(formatError(arg)); + }); + return logFn.apply(console, args); + }; + } + + // we are IE which either doesn't have window.console => this is noop and we do nothing, + // or we are IE where console.log doesn't have apply so we log at least first 2 args + return function(arg1, arg2) { + logFn(arg1, arg2); + } + } + }]; +} + +var OPERATORS = { + 'null':function(){return null;}, + 'true':function(){return true;}, + 'false':function(){return false;}, + undefined:noop, + '+':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)+(isDefined(b)?b:0);}, + '-':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)-(isDefined(b)?b:0);}, + '*':function(self, locals, a,b){return a(self, locals)*b(self, locals);}, + '/':function(self, locals, a,b){return a(self, locals)/b(self, locals);}, + '%':function(self, locals, a,b){return a(self, locals)%b(self, locals);}, + '^':function(self, locals, a,b){return a(self, locals)^b(self, locals);}, + '=':noop, + '==':function(self, locals, a,b){return a(self, locals)==b(self, locals);}, + '!=':function(self, locals, a,b){return a(self, locals)!=b(self, locals);}, + '<':function(self, locals, a,b){return a(self, locals)':function(self, locals, a,b){return a(self, locals)>b(self, locals);}, + '<=':function(self, locals, a,b){return a(self, locals)<=b(self, locals);}, + '>=':function(self, locals, a,b){return a(self, locals)>=b(self, locals);}, + '&&':function(self, locals, a,b){return a(self, locals)&&b(self, locals);}, + '||':function(self, locals, a,b){return a(self, locals)||b(self, locals);}, + '&':function(self, locals, a,b){return a(self, locals)&b(self, locals);}, +// '|':function(self, locals, a,b){return a|b;}, + '|':function(self, locals, a,b){return b(self, locals)(self, locals, a(self, locals));}, + '!':function(self, locals, a){return !a(self, locals);} +}; +var ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v", "'":"'", '"':'"'}; + +function lex(text, csp){ + var tokens = [], + token, + index = 0, + json = [], + ch, + lastCh = ':'; // can start regexp + + while (index < text.length) { + ch = text.charAt(index); + if (is('"\'')) { + readString(ch); + } else if (isNumber(ch) || is('.') && isNumber(peek())) { + readNumber(); + } else if (isIdent(ch)) { + readIdent(); + // identifiers can only be if the preceding char was a { or , + if (was('{,') && json[0]=='{' && + (token=tokens[tokens.length-1])) { + token.json = token.text.indexOf('.') == -1; + } + } else if (is('(){}[].,;:')) { + tokens.push({ + index:index, + text:ch, + json:(was(':[,') && is('{[')) || is('}]:,') + }); + if (is('{[')) json.unshift(ch); + if (is('}]')) json.shift(); + index++; + } else if (isWhitespace(ch)) { + index++; + continue; + } else { + var ch2 = ch + peek(), + fn = OPERATORS[ch], + fn2 = OPERATORS[ch2]; + if (fn2) { + tokens.push({index:index, text:ch2, fn:fn2}); + index += 2; + } else if (fn) { + tokens.push({index:index, text:ch, fn:fn, json: was('[,:') && is('+-')}); + index += 1; + } else { + throwError("Unexpected next character ", index, index+1); + } + } + lastCh = ch; + } + return tokens; + + function is(chars) { + return chars.indexOf(ch) != -1; + } + + function was(chars) { + return chars.indexOf(lastCh) != -1; + } + + function peek() { + return index + 1 < text.length ? text.charAt(index + 1) : false; + } + function isNumber(ch) { + return '0' <= ch && ch <= '9'; + } + function isWhitespace(ch) { + return ch == ' ' || ch == '\r' || ch == '\t' || + ch == '\n' || ch == '\v' || ch == '\u00A0'; // IE treats non-breaking space as \u00A0 + } + function isIdent(ch) { + return 'a' <= ch && ch <= 'z' || + 'A' <= ch && ch <= 'Z' || + '_' == ch || ch == '$'; + } + function isExpOperator(ch) { + return ch == '-' || ch == '+' || isNumber(ch); + } + + function throwError(error, start, end) { + end = end || index; + throw Error("Lexer Error: " + error + " at column" + + (isDefined(start) + ? "s " + start + "-" + index + " [" + text.substring(start, end) + "]" + : " " + end) + + " in expression [" + text + "]."); + } + + function readNumber() { + var number = ""; + var start = index; + while (index < text.length) { + var ch = lowercase(text.charAt(index)); + if (ch == '.' || isNumber(ch)) { + number += ch; + } else { + var peekCh = peek(); + if (ch == 'e' && isExpOperator(peekCh)) { + number += ch; + } else if (isExpOperator(ch) && + peekCh && isNumber(peekCh) && + number.charAt(number.length - 1) == 'e') { + number += ch; + } else if (isExpOperator(ch) && + (!peekCh || !isNumber(peekCh)) && + number.charAt(number.length - 1) == 'e') { + throwError('Invalid exponent'); + } else { + break; + } + } + index++; + } + number = 1 * number; + tokens.push({index:start, text:number, json:true, + fn:function() {return number;}}); + } + function readIdent() { + var ident = "", + start = index, + lastDot, peekIndex, methodName; + + while (index < text.length) { + var ch = text.charAt(index); + if (ch == '.' || isIdent(ch) || isNumber(ch)) { + if (ch == '.') lastDot = index; + ident += ch; + } else { + break; + } + index++; + } + + //check if this is not a method invocation and if it is back out to last dot + if (lastDot) { + peekIndex = index; + while(peekIndex < text.length) { + var ch = text.charAt(peekIndex); + if (ch == '(') { + methodName = ident.substr(lastDot - start + 1); + ident = ident.substr(0, lastDot - start); + index = peekIndex; + break; + } + if(isWhitespace(ch)) { + peekIndex++; + } else { + break; + } + } + } + + + var token = { + index:start, + text:ident + }; + + if (OPERATORS.hasOwnProperty(ident)) { + token.fn = token.json = OPERATORS[ident]; + } else { + var getter = getterFn(ident, csp); + token.fn = extend(function(self, locals) { + return (getter(self, locals)); + }, { + assign: function(self, value) { + return setter(self, ident, value); + } + }); + } + + tokens.push(token); + + if (methodName) { + tokens.push({ + index:lastDot, + text: '.', + json: false + }); + tokens.push({ + index: lastDot + 1, + text: methodName, + json: false + }); + } + } + + function readString(quote) { + var start = index; + index++; + var string = ""; + var rawString = quote; + var escape = false; + while (index < text.length) { + var ch = text.charAt(index); + rawString += ch; + if (escape) { + if (ch == 'u') { + var hex = text.substring(index + 1, index + 5); + if (!hex.match(/[\da-f]{4}/i)) + throwError( "Invalid unicode escape [\\u" + hex + "]"); + index += 4; + string += String.fromCharCode(parseInt(hex, 16)); + } else { + var rep = ESCAPE[ch]; + if (rep) { + string += rep; + } else { + string += ch; + } + } + escape = false; + } else if (ch == '\\') { + escape = true; + } else if (ch == quote) { + index++; + tokens.push({ + index:start, + text:rawString, + string:string, + json:true, + fn:function() { return string; } + }); + return; + } else { + string += ch; + } + index++; + } + throwError("Unterminated quote", start); + } +} + +///////////////////////////////////////// + +function parser(text, json, $filter, csp){ + var ZERO = valueFn(0), + value, + tokens = lex(text, csp), + assignment = _assignment, + functionCall = _functionCall, + fieldAccess = _fieldAccess, + objectIndex = _objectIndex, + filterChain = _filterChain; + + if(json){ + // The extra level of aliasing is here, just in case the lexer misses something, so that + // we prevent any accidental execution in JSON. + assignment = logicalOR; + functionCall = + fieldAccess = + objectIndex = + filterChain = + function() { throwError("is not valid json", {text:text, index:0}); }; + value = primary(); + } else { + value = statements(); + } + if (tokens.length !== 0) { + throwError("is an unexpected token", tokens[0]); + } + return value; + + /////////////////////////////////// + function throwError(msg, token) { + throw Error("Syntax Error: Token '" + token.text + + "' " + msg + " at column " + + (token.index + 1) + " of the expression [" + + text + "] starting at [" + text.substring(token.index) + "]."); + } + + function peekToken() { + if (tokens.length === 0) + throw Error("Unexpected end of expression: " + text); + return tokens[0]; + } + + function peek(e1, e2, e3, e4) { + if (tokens.length > 0) { + var token = tokens[0]; + var t = token.text; + if (t==e1 || t==e2 || t==e3 || t==e4 || + (!e1 && !e2 && !e3 && !e4)) { + return token; + } + } + return false; + } + + function expect(e1, e2, e3, e4){ + var token = peek(e1, e2, e3, e4); + if (token) { + if (json && !token.json) { + throwError("is not valid json", token); + } + tokens.shift(); + return token; + } + return false; + } + + function consume(e1){ + if (!expect(e1)) { + throwError("is unexpected, expecting [" + e1 + "]", peek()); + } + } + + function unaryFn(fn, right) { + return function(self, locals) { + return fn(self, locals, right); + }; + } + + function binaryFn(left, fn, right) { + return function(self, locals) { + return fn(self, locals, left, right); + }; + } + + function statements() { + var statements = []; + while(true) { + if (tokens.length > 0 && !peek('}', ')', ';', ']')) + statements.push(filterChain()); + if (!expect(';')) { + // optimize for the common case where there is only one statement. + // TODO(size): maybe we should not support multiple statements? + return statements.length == 1 + ? statements[0] + : function(self, locals){ + var value; + for ( var i = 0; i < statements.length; i++) { + var statement = statements[i]; + if (statement) + value = statement(self, locals); + } + return value; + }; + } + } + } + + function _filterChain() { + var left = expression(); + var token; + while(true) { + if ((token = expect('|'))) { + left = binaryFn(left, token.fn, filter()); + } else { + return left; + } + } + } + + function filter() { + var token = expect(); + var fn = $filter(token.text); + var argsFn = []; + while(true) { + if ((token = expect(':'))) { + argsFn.push(expression()); + } else { + var fnInvoke = function(self, locals, input){ + var args = [input]; + for ( var i = 0; i < argsFn.length; i++) { + args.push(argsFn[i](self, locals)); + } + return fn.apply(self, args); + }; + return function() { + return fnInvoke; + }; + } + } + } + + function expression() { + return assignment(); + } + + function _assignment() { + var left = logicalOR(); + var right; + var token; + if ((token = expect('='))) { + if (!left.assign) { + throwError("implies assignment but [" + + text.substring(0, token.index) + "] can not be assigned to", token); + } + right = logicalOR(); + return function(self, locals){ + return left.assign(self, right(self, locals), locals); + }; + } else { + return left; + } + } + + function logicalOR() { + var left = logicalAND(); + var token; + while(true) { + if ((token = expect('||'))) { + left = binaryFn(left, token.fn, logicalAND()); + } else { + return left; + } + } + } + + function logicalAND() { + var left = equality(); + var token; + if ((token = expect('&&'))) { + left = binaryFn(left, token.fn, logicalAND()); + } + return left; + } + + function equality() { + var left = relational(); + var token; + if ((token = expect('==','!='))) { + left = binaryFn(left, token.fn, equality()); + } + return left; + } + + function relational() { + var left = additive(); + var token; + if ((token = expect('<', '>', '<=', '>='))) { + left = binaryFn(left, token.fn, relational()); + } + return left; + } + + function additive() { + var left = multiplicative(); + var token; + while ((token = expect('+','-'))) { + left = binaryFn(left, token.fn, multiplicative()); + } + return left; + } + + function multiplicative() { + var left = unary(); + var token; + while ((token = expect('*','/','%'))) { + left = binaryFn(left, token.fn, unary()); + } + return left; + } + + function unary() { + var token; + if (expect('+')) { + return primary(); + } else if ((token = expect('-'))) { + return binaryFn(ZERO, token.fn, unary()); + } else if ((token = expect('!'))) { + return unaryFn(token.fn, unary()); + } else { + return primary(); + } + } + + + function primary() { + var primary; + if (expect('(')) { + primary = filterChain(); + consume(')'); + } else if (expect('[')) { + primary = arrayDeclaration(); + } else if (expect('{')) { + primary = object(); + } else { + var token = expect(); + primary = token.fn; + if (!primary) { + throwError("not a primary expression", token); + } + } + + var next, context; + while ((next = expect('(', '[', '.'))) { + if (next.text === '(') { + primary = functionCall(primary, context); + context = null; + } else if (next.text === '[') { + context = primary; + primary = objectIndex(primary); + } else if (next.text === '.') { + context = primary; + primary = fieldAccess(primary); + } else { + throwError("IMPOSSIBLE"); + } + } + return primary; + } + + function _fieldAccess(object) { + var field = expect().text; + var getter = getterFn(field, csp); + return extend( + function(self, locals) { + return getter(object(self, locals), locals); + }, + { + assign:function(self, value, locals) { + return setter(object(self, locals), field, value); + } + } + ); + } + + function _objectIndex(obj) { + var indexFn = expression(); + consume(']'); + return extend( + function(self, locals){ + var o = obj(self, locals), + i = indexFn(self, locals), + v, p; + + if (!o) return undefined; + v = o[i]; + if (v && v.then) { + p = v; + if (!('$$v' in v)) { + p.$$v = undefined; + p.then(function(val) { p.$$v = val; }); + } + v = v.$$v; + } + return v; + }, { + assign:function(self, value, locals){ + return obj(self, locals)[indexFn(self, locals)] = value; + } + }); + } + + function _functionCall(fn, contextGetter) { + var argsFn = []; + if (peekToken().text != ')') { + do { + argsFn.push(expression()); + } while (expect(',')); + } + consume(')'); + return function(self, locals){ + var args = [], + context = contextGetter ? contextGetter(self, locals) : self; + + for ( var i = 0; i < argsFn.length; i++) { + args.push(argsFn[i](self, locals)); + } + var fnPtr = fn(self, locals) || noop; + // IE stupidity! + return fnPtr.apply + ? fnPtr.apply(context, args) + : fnPtr(args[0], args[1], args[2], args[3], args[4]); + }; + } + + // This is used with json array declaration + function arrayDeclaration () { + var elementFns = []; + if (peekToken().text != ']') { + do { + elementFns.push(expression()); + } while (expect(',')); + } + consume(']'); + return function(self, locals){ + var array = []; + for ( var i = 0; i < elementFns.length; i++) { + array.push(elementFns[i](self, locals)); + } + return array; + }; + } + + function object () { + var keyValues = []; + if (peekToken().text != '}') { + do { + var token = expect(), + key = token.string || token.text; + consume(":"); + var value = expression(); + keyValues.push({key:key, value:value}); + } while (expect(',')); + } + consume('}'); + return function(self, locals){ + var object = {}; + for ( var i = 0; i < keyValues.length; i++) { + var keyValue = keyValues[i]; + var value = keyValue.value(self, locals); + object[keyValue.key] = value; + } + return object; + }; + } +} + +////////////////////////////////////////////////// +// Parser helper functions +////////////////////////////////////////////////// + +function setter(obj, path, setValue) { + var element = path.split('.'); + for (var i = 0; element.length > 1; i++) { + var key = element.shift(); + var propertyObj = obj[key]; + if (!propertyObj) { + propertyObj = {}; + obj[key] = propertyObj; + } + obj = propertyObj; + } + obj[element.shift()] = setValue; + return setValue; +} + +/** + * Return the value accesible from the object by path. Any undefined traversals are ignored + * @param {Object} obj starting object + * @param {string} path path to traverse + * @param {boolean=true} bindFnToScope + * @returns value as accesbile by path + */ +//TODO(misko): this function needs to be removed +function getter(obj, path, bindFnToScope) { + if (!path) return obj; + var keys = path.split('.'); + var key; + var lastInstance = obj; + var len = keys.length; + + for (var i = 0; i < len; i++) { + key = keys[i]; + if (obj) { + obj = (lastInstance = obj)[key]; + } + } + if (!bindFnToScope && isFunction(obj)) { + return bind(lastInstance, obj); + } + return obj; +} + +var getterFnCache = {}; + +/** + * Implementation of the "Black Hole" variant from: + * - http://jsperf.com/angularjs-parse-getter/4 + * - http://jsperf.com/path-evaluation-simplified/7 + */ +function cspSafeGetterFn(key0, key1, key2, key3, key4) { + return function(scope, locals) { + var pathVal = (locals && locals.hasOwnProperty(key0)) ? locals : scope, + promise; + + if (pathVal === null || pathVal === undefined) return pathVal; + + pathVal = pathVal[key0]; + if (pathVal && pathVal.then) { + if (!("$$v" in pathVal)) { + promise = pathVal; + promise.$$v = undefined; + promise.then(function(val) { promise.$$v = val; }); + } + pathVal = pathVal.$$v; + } + if (!key1 || pathVal === null || pathVal === undefined) return pathVal; + + pathVal = pathVal[key1]; + if (pathVal && pathVal.then) { + if (!("$$v" in pathVal)) { + promise = pathVal; + promise.$$v = undefined; + promise.then(function(val) { promise.$$v = val; }); + } + pathVal = pathVal.$$v; + } + if (!key2 || pathVal === null || pathVal === undefined) return pathVal; + + pathVal = pathVal[key2]; + if (pathVal && pathVal.then) { + if (!("$$v" in pathVal)) { + promise = pathVal; + promise.$$v = undefined; + promise.then(function(val) { promise.$$v = val; }); + } + pathVal = pathVal.$$v; + } + if (!key3 || pathVal === null || pathVal === undefined) return pathVal; + + pathVal = pathVal[key3]; + if (pathVal && pathVal.then) { + if (!("$$v" in pathVal)) { + promise = pathVal; + promise.$$v = undefined; + promise.then(function(val) { promise.$$v = val; }); + } + pathVal = pathVal.$$v; + } + if (!key4 || pathVal === null || pathVal === undefined) return pathVal; + + pathVal = pathVal[key4]; + if (pathVal && pathVal.then) { + if (!("$$v" in pathVal)) { + promise = pathVal; + promise.$$v = undefined; + promise.then(function(val) { promise.$$v = val; }); + } + pathVal = pathVal.$$v; + } + return pathVal; + }; +}; + +function getterFn(path, csp) { + if (getterFnCache.hasOwnProperty(path)) { + return getterFnCache[path]; + } + + var pathKeys = path.split('.'), + pathKeysLength = pathKeys.length, + fn; + + if (csp) { + fn = (pathKeysLength < 6) + ? cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4]) + : function(scope, locals) { + var i = 0, val + do { + val = cspSafeGetterFn( + pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++] + )(scope, locals); + + locals = undefined; // clear after first iteration + scope = val; + } while (i < pathKeysLength); + return val; + } + } else { + var code = 'var l, fn, p;\n'; + forEach(pathKeys, function(key, index) { + code += 'if(s === null || s === undefined) return s;\n' + + 'l=s;\n' + + 's='+ (index + // we simply dereference 's' on any .dot notation + ? 's' + // but if we are first then we check locals first, and if so read it first + : '((k&&k.hasOwnProperty("' + key + '"))?k:s)') + '["' + key + '"]' + ';\n' + + 'if (s && s.then) {\n' + + ' if (!("$$v" in s)) {\n' + + ' p=s;\n' + + ' p.$$v = undefined;\n' + + ' p.then(function(v) {p.$$v=v;});\n' + + '}\n' + + ' s=s.$$v\n' + + '}\n'; + }); + code += 'return s;'; + fn = Function('s', 'k', code); // s=scope, k=locals + fn.toString = function() { return code; }; + } + + return getterFnCache[path] = fn; +} + +/////////////////////////////////// + +/** + * @ngdoc function + * @name ng.$parse + * @function + * + * @description + * + * Converts Angular {@link guide/expression expression} into a function. + * + *
+ *   var getter = $parse('user.name');
+ *   var setter = getter.assign;
+ *   var context = {user:{name:'angular'}};
+ *   var locals = {user:{name:'local'}};
+ *
+ *   expect(getter(context)).toEqual('angular');
+ *   setter(context, 'newValue');
+ *   expect(context.user.name).toEqual('newValue');
+ *   expect(getter(context, locals)).toEqual('local');
+ * 
+ * + * + * @param {string} expression String expression to compile. + * @returns {function(context, locals)} a function which represents the compiled expression: + * + * * `context`: an object against which any expressions embedded in the strings are evaluated + * against (Topically a scope object). + * * `locals`: local variables context object, useful for overriding values in `context`. + * + * The return function also has an `assign` property, if the expression is assignable, which + * allows one to set values to expressions. + * + */ +function $ParseProvider() { + var cache = {}; + this.$get = ['$filter', '$sniffer', function($filter, $sniffer) { + return function(exp) { + switch(typeof exp) { + case 'string': + return cache.hasOwnProperty(exp) + ? cache[exp] + : cache[exp] = parser(exp, false, $filter, $sniffer.csp); + case 'function': + return exp; + default: + return noop; + } + }; + }]; +} + +/** + * @ngdoc service + * @name ng.$q + * @requires $rootScope + * + * @description + * A promise/deferred implementation inspired by [Kris Kowal's Q](https://github.com/kriskowal/q). + * + * [The CommonJS Promise proposal](http://wiki.commonjs.org/wiki/Promises) describes a promise as an + * interface for interacting with an object that represents the result of an action that is + * performed asynchronously, and may or may not be finished at any given point in time. + * + * From the perspective of dealing with error handling, deferred and promise apis are to + * asynchronous programing what `try`, `catch` and `throw` keywords are to synchronous programing. + * + *
+ *   // for the purpose of this example let's assume that variables `$q` and `scope` are
+ *   // available in the current lexical scope (they could have been injected or passed in).
+ *
+ *   function asyncGreet(name) {
+ *     var deferred = $q.defer();
+ *
+ *     setTimeout(function() {
+ *       // since this fn executes async in a future turn of the event loop, we need to wrap
+ *       // our code into an $apply call so that the model changes are properly observed.
+ *       scope.$apply(function() {
+ *         if (okToGreet(name)) {
+ *           deferred.resolve('Hello, ' + name + '!');
+ *         } else {
+ *           deferred.reject('Greeting ' + name + ' is not allowed.');
+ *         }
+ *       });
+ *     }, 1000);
+ *
+ *     return deferred.promise;
+ *   }
+ *
+ *   var promise = asyncGreet('Robin Hood');
+ *   promise.then(function(greeting) {
+ *     alert('Success: ' + greeting);
+ *   }, function(reason) {
+ *     alert('Failed: ' + reason);
+ *   );
+ * 
+ * + * At first it might not be obvious why this extra complexity is worth the trouble. The payoff + * comes in the way of + * [guarantees that promise and deferred apis make](https://github.com/kriskowal/uncommonjs/blob/master/promises/specification.md). + * + * Additionally the promise api allows for composition that is very hard to do with the + * traditional callback ([CPS](http://en.wikipedia.org/wiki/Continuation-passing_style)) approach. + * For more on this please see the [Q documentation](https://github.com/kriskowal/q) especially the + * section on serial or parallel joining of promises. + * + * + * # The Deferred API + * + * A new instance of deferred is constructed by calling `$q.defer()`. + * + * The purpose of the deferred object is to expose the associated Promise instance as well as apis + * that can be used for signaling the successful or unsuccessful completion of the task. + * + * **Methods** + * + * - `resolve(value)` – resolves the derived promise with the `value`. If the value is a rejection + * constructed via `$q.reject`, the promise will be rejected instead. + * - `reject(reason)` – rejects the derived promise with the `reason`. This is equivalent to + * resolving it with a rejection constructed via `$q.reject`. + * + * **Properties** + * + * - promise – `{Promise}` – promise object associated with this deferred. + * + * + * # The Promise API + * + * A new promise instance is created when a deferred instance is created and can be retrieved by + * calling `deferred.promise`. + * + * The purpose of the promise object is to allow for interested parties to get access to the result + * of the deferred task when it completes. + * + * **Methods** + * + * - `then(successCallback, errorCallback)` – regardless of when the promise was or will be resolved + * or rejected calls one of the success or error callbacks asynchronously as soon as the result + * is available. The callbacks are called with a single argument the result or rejection reason. + * + * This method *returns a new promise* which is resolved or rejected via the return value of the + * `successCallback` or `errorCallback`. + * + * + * # Chaining promises + * + * Because calling `then` api of a promise returns a new derived promise, it is easily possible + * to create a chain of promises: + * + *
+ *   promiseB = promiseA.then(function(result) {
+ *     return result + 1;
+ *   });
+ *
+ *   // promiseB will be resolved immediately after promiseA is resolved and it's value will be
+ *   // the result of promiseA incremented by 1
+ * 
+ * + * It is possible to create chains of any length and since a promise can be resolved with another + * promise (which will defer its resolution further), it is possible to pause/defer resolution of + * the promises at any point in the chain. This makes it possible to implement powerful apis like + * $http's response interceptors. + * + * + * # Differences between Kris Kowal's Q and $q + * + * There are three main differences: + * + * - $q is integrated with the {@link ng.$rootScope.Scope} Scope model observation + * mechanism in angular, which means faster propagation of resolution or rejection into your + * models and avoiding unnecessary browser repaints, which would result in flickering UI. + * - $q promises are recognized by the templating engine in angular, which means that in templates + * you can treat promises attached to a scope as if they were the resulting values. + * - Q has many more features that $q, but that comes at a cost of bytes. $q is tiny, but contains + * all the important functionality needed for common async tasks. + */ +function $QProvider() { + + this.$get = ['$rootScope', '$exceptionHandler', function($rootScope, $exceptionHandler) { + return qFactory(function(callback) { + $rootScope.$evalAsync(callback); + }, $exceptionHandler); + }]; +} + + +/** + * Constructs a promise manager. + * + * @param {function(function)} nextTick Function for executing functions in the next turn. + * @param {function(...*)} exceptionHandler Function into which unexpected exceptions are passed for + * debugging purposes. + * @returns {object} Promise manager. + */ +function qFactory(nextTick, exceptionHandler) { + + /** + * @ngdoc + * @name ng.$q#defer + * @methodOf ng.$q + * @description + * Creates a `Deferred` object which represents a task which will finish in the future. + * + * @returns {Deferred} Returns a new instance of deferred. + */ + var defer = function() { + var pending = [], + value, deferred; + + deferred = { + + resolve: function(val) { + if (pending) { + var callbacks = pending; + pending = undefined; + value = ref(val); + + if (callbacks.length) { + nextTick(function() { + var callback; + for (var i = 0, ii = callbacks.length; i < ii; i++) { + callback = callbacks[i]; + value.then(callback[0], callback[1]); + } + }); + } + } + }, + + + reject: function(reason) { + deferred.resolve(reject(reason)); + }, + + + promise: { + then: function(callback, errback) { + var result = defer(); + + var wrappedCallback = function(value) { + try { + result.resolve((callback || defaultCallback)(value)); + } catch(e) { + exceptionHandler(e); + result.reject(e); + } + }; + + var wrappedErrback = function(reason) { + try { + result.resolve((errback || defaultErrback)(reason)); + } catch(e) { + exceptionHandler(e); + result.reject(e); + } + }; + + if (pending) { + pending.push([wrappedCallback, wrappedErrback]); + } else { + value.then(wrappedCallback, wrappedErrback); + } + + return result.promise; + } + } + }; + + return deferred; + }; + + + var ref = function(value) { + if (value && value.then) return value; + return { + then: function(callback) { + var result = defer(); + nextTick(function() { + result.resolve(callback(value)); + }); + return result.promise; + } + }; + }; + + + /** + * @ngdoc + * @name ng.$q#reject + * @methodOf ng.$q + * @description + * Creates a promise that is resolved as rejected with the specified `reason`. This api should be + * used to forward rejection in a chain of promises. If you are dealing with the last promise in + * a promise chain, you don't need to worry about it. + * + * When comparing deferreds/promises to the familiar behavior of try/catch/throw, think of + * `reject` as the `throw` keyword in JavaScript. This also means that if you "catch" an error via + * a promise error callback and you want to forward the error to the promise derived from the + * current promise, you have to "rethrow" the error by returning a rejection constructed via + * `reject`. + * + *
+   *   promiseB = promiseA.then(function(result) {
+   *     // success: do something and resolve promiseB
+   *     //          with the old or a new result
+   *     return result;
+   *   }, function(reason) {
+   *     // error: handle the error if possible and
+   *     //        resolve promiseB with newPromiseOrValue,
+   *     //        otherwise forward the rejection to promiseB
+   *     if (canHandle(reason)) {
+   *      // handle the error and recover
+   *      return newPromiseOrValue;
+   *     }
+   *     return $q.reject(reason);
+   *   });
+   * 
+ * + * @param {*} reason Constant, message, exception or an object representing the rejection reason. + * @returns {Promise} Returns a promise that was already resolved as rejected with the `reason`. + */ + var reject = function(reason) { + return { + then: function(callback, errback) { + var result = defer(); + nextTick(function() { + result.resolve((errback || defaultErrback)(reason)); + }); + return result.promise; + } + }; + }; + + + /** + * @ngdoc + * @name ng.$q#when + * @methodOf ng.$q + * @description + * Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise. + * This is useful when you are dealing with on object that might or might not be a promise, or if + * the promise comes from a source that can't be trusted. + * + * @param {*} value Value or a promise + * @returns {Promise} Returns a single promise that will be resolved with an array of values, + * each value coresponding to the promise at the same index in the `promises` array. If any of + * the promises is resolved with a rejection, this resulting promise will be resolved with the + * same rejection. + */ + var when = function(value, callback, errback) { + var result = defer(), + done; + + var wrappedCallback = function(value) { + try { + return (callback || defaultCallback)(value); + } catch (e) { + exceptionHandler(e); + return reject(e); + } + }; + + var wrappedErrback = function(reason) { + try { + return (errback || defaultErrback)(reason); + } catch (e) { + exceptionHandler(e); + return reject(e); + } + }; + + nextTick(function() { + ref(value).then(function(value) { + if (done) return; + done = true; + result.resolve(ref(value).then(wrappedCallback, wrappedErrback)); + }, function(reason) { + if (done) return; + done = true; + result.resolve(wrappedErrback(reason)); + }); + }); + + return result.promise; + }; + + + function defaultCallback(value) { + return value; + } + + + function defaultErrback(reason) { + return reject(reason); + } + + + /** + * @ngdoc + * @name ng.$q#all + * @methodOf ng.$q + * @description + * Combines multiple promises into a single promise that is resolved when all of the input + * promises are resolved. + * + * @param {Array.} promises An array of promises. + * @returns {Promise} Returns a single promise that will be resolved with an array of values, + * each value coresponding to the promise at the same index in the `promises` array. If any of + * the promises is resolved with a rejection, this resulting promise will be resolved with the + * same rejection. + */ + function all(promises) { + var deferred = defer(), + counter = promises.length, + results = []; + + if (counter) { + forEach(promises, function(promise, index) { + ref(promise).then(function(value) { + if (index in results) return; + results[index] = value; + if (!(--counter)) deferred.resolve(results); + }, function(reason) { + if (index in results) return; + deferred.reject(reason); + }); + }); + } else { + deferred.resolve(results); + } + + return deferred.promise; + } + + return { + defer: defer, + reject: reject, + when: when, + all: all + }; +} + +/** + * @ngdoc object + * @name ng.$routeProvider + * @function + * + * @description + * + * Used for configuring routes. See {@link ng.$route $route} for an example. + */ +function $RouteProvider(){ + var routes = {}; + + /** + * @ngdoc method + * @name ng.$routeProvider#when + * @methodOf ng.$routeProvider + * + * @param {string} path Route path (matched against `$location.path`). If `$location.path` + * contains redundant trailing slash or is missing one, the route will still match and the + * `$location.path` will be updated to add or drop the trailing slash to exacly match the + * route definition. + * @param {Object} route Mapping information to be assigned to `$route.current` on route + * match. + * + * Object properties: + * + * - `controller` – `{(string|function()=}` – Controller fn that should be associated with newly + * created scope or the name of a {@link angular.Module#controller registered controller} + * if passed as a string. + * - `template` – `{string=}` – html template as a string that should be used by + * {@link ng.directive:ngView ngView} or + * {@link ng.directive:ngInclude ngInclude} directives. + * this property takes precedence over `templateUrl`. + * - `templateUrl` – `{string=}` – path to an html template that should be used by + * {@link ng.directive:ngView ngView}. + * - `resolve` - `{Object.=}` - An optional map of dependencies which should + * be injected into the controller. If any of these dependencies are promises, they will be + * resolved and converted to a value before the controller is instantiated and the + * `$afterRouteChange` event is fired. The map object is: + * + * - `key` – `{string}`: a name of a dependency to be injected into the controller. + * - `factory` - `{string|function}`: If `string` then it is an alias for a service. + * Otherwise if function, then it is {@link api/AUTO.$injector#invoke injected} + * and the return value is treated as the dependency. If the result is a promise, it is resolved + * before its value is injected into the controller. + * + * - `redirectTo` – {(string|function())=} – value to update + * {@link ng.$location $location} path with and trigger route redirection. + * + * If `redirectTo` is a function, it will be called with the following parameters: + * + * - `{Object.}` - route parameters extracted from the current + * `$location.path()` by applying the current route templateUrl. + * - `{string}` - current `$location.path()` + * - `{Object}` - current `$location.search()` + * + * The custom `redirectTo` function is expected to return a string which will be used + * to update `$location.path()` and `$location.search()`. + * + * - `[reloadOnSearch=true]` - {boolean=} - reload route when only $location.search() + * changes. + * + * If the option is set to `false` and url in the browser changes, then + * `$routeUpdate` event is broadcasted on the root scope. + * + * @returns {Object} self + * + * @description + * Adds a new route definition to the `$route` service. + */ + this.when = function(path, route) { + routes[path] = extend({reloadOnSearch: true}, route); + + // create redirection for trailing slashes + if (path) { + var redirectPath = (path[path.length-1] == '/') + ? path.substr(0, path.length-1) + : path +'/'; + + routes[redirectPath] = {redirectTo: path}; + } + + return this; + }; + + /** + * @ngdoc method + * @name ng.$routeProvider#otherwise + * @methodOf ng.$routeProvider + * + * @description + * Sets route definition that will be used on route change when no other route definition + * is matched. + * + * @param {Object} params Mapping information to be assigned to `$route.current`. + * @returns {Object} self + */ + this.otherwise = function(params) { + this.when(null, params); + return this; + }; + + + this.$get = ['$rootScope', '$location', '$routeParams', '$q', '$injector', '$http', '$templateCache', + function( $rootScope, $location, $routeParams, $q, $injector, $http, $templateCache) { + + /** + * @ngdoc object + * @name ng.$route + * @requires $location + * @requires $routeParams + * + * @property {Object} current Reference to the current route definition. + * The route definition contains: + * + * - `controller`: The controller constructor as define in route definition. + * - `locals`: A map of locals which is used by {@link ng.$controller $controller} service for + * controller instantiation. The `locals` contain + * the resolved values of the `resolve` map. Additionally the `locals` also contain: + * + * - `$scope` - The current route scope. + * - `$template` - The current route template HTML. + * + * @property {Array.} routes Array of all configured routes. + * + * @description + * Is used for deep-linking URLs to controllers and views (HTML partials). + * It watches `$location.url()` and tries to map the path to an existing route definition. + * + * You can define routes through {@link ng.$routeProvider $routeProvider}'s API. + * + * The `$route` service is typically used in conjunction with {@link ng.directive:ngView ngView} + * directive and the {@link ng.$routeParams $routeParams} service. + * + * @example + This example shows how changing the URL hash causes the `$route` to match a route against the + URL, and the `ngView` pulls in the partial. + + Note that this example is using {@link ng.directive:script inlined templates} + to get it working on jsfiddle as well. + + + +
+ Choose: + Moby | + Moby: Ch1 | + Gatsby | + Gatsby: Ch4 | + Scarlet Letter
+ +
+
+ +
$location.path() = {{$location.path()}}
+
$route.current.templateUrl = {{$route.current.templateUrl}}
+
$route.current.params = {{$route.current.params}}
+
$route.current.scope.name = {{$route.current.scope.name}}
+
$routeParams = {{$routeParams}}
+
+
+ + + controller: {{name}}
+ Book Id: {{params.bookId}}
+
+ + + controller: {{name}}
+ Book Id: {{params.bookId}}
+ Chapter Id: {{params.chapterId}} +
+ + + angular.module('ngView', [], function($routeProvider, $locationProvider) { + $routeProvider.when('/Book/:bookId', { + templateUrl: 'book.html', + controller: BookCntl, + resolve: { + // I will cause a 1 second delay + delay: function($q, $timeout) { + var delay = $q.defer(); + $timeout(delay.resolve, 1000); + return delay.promise; + } + } + }); + $routeProvider.when('/Book/:bookId/ch/:chapterId', { + templateUrl: 'chapter.html', + controller: ChapterCntl + }); + + // configure html5 to get links working on jsfiddle + $locationProvider.html5Mode(true); + }); + + function MainCntl($scope, $route, $routeParams, $location) { + $scope.$route = $route; + $scope.$location = $location; + $scope.$routeParams = $routeParams; + } + + function BookCntl($scope, $routeParams) { + $scope.name = "BookCntl"; + $scope.params = $routeParams; + } + + function ChapterCntl($scope, $routeParams) { + $scope.name = "ChapterCntl"; + $scope.params = $routeParams; + } + + + + it('should load and compile correct template', function() { + element('a:contains("Moby: Ch1")').click(); + var content = element('.doc-example-live [ng-view]').text(); + expect(content).toMatch(/controller\: ChapterCntl/); + expect(content).toMatch(/Book Id\: Moby/); + expect(content).toMatch(/Chapter Id\: 1/); + + element('a:contains("Scarlet")').click(); + sleep(2); // promises are not part of scenario waiting + content = element('.doc-example-live [ng-view]').text(); + expect(content).toMatch(/controller\: BookCntl/); + expect(content).toMatch(/Book Id\: Scarlet/); + }); + +
+ */ + + /** + * @ngdoc event + * @name ng.$route#$routeChangeStart + * @eventOf ng.$route + * @eventType broadcast on root scope + * @description + * Broadcasted before a route change. At this point the route services starts + * resolving all of the dependencies needed for the route change to occurs. + * Typically this involves fetching the view template as well as any dependencies + * defined in `resolve` route property. Once all of the dependencies are resolved + * `$routeChangeSuccess` is fired. + * + * @param {Route} next Future route information. + * @param {Route} current Current route information. + */ + + /** + * @ngdoc event + * @name ng.$route#$routeChangeSuccess + * @eventOf ng.$route + * @eventType broadcast on root scope + * @description + * Broadcasted after a route dependencies are resolved. + * {@link ng.directive:ngView ngView} listens for the directive + * to instantiate the controller and render the view. + * + * @param {Route} current Current route information. + * @param {Route} previous Previous route information. + */ + + /** + * @ngdoc event + * @name ng.$route#$routeChangeError + * @eventOf ng.$route + * @eventType broadcast on root scope + * @description + * Broadcasted if any of the resolve promises are rejected. + * + * @param {Route} current Current route information. + * @param {Route} previous Previous route information. + * @param {Route} rejection Rejection of the promise. Usually the error of the failed promise. + */ + + /** + * @ngdoc event + * @name ng.$route#$routeUpdate + * @eventOf ng.$route + * @eventType broadcast on root scope + * @description + * + * The `reloadOnSearch` property has been set to false, and we are reusing the same + * instance of the Controller. + */ + + var matcher = switchRouteMatcher, + forceReload = false, + $route = { + routes: routes, + + /** + * @ngdoc method + * @name ng.$route#reload + * @methodOf ng.$route + * + * @description + * Causes `$route` service to reload the current route even if + * {@link ng.$location $location} hasn't changed. + * + * As a result of that, {@link ng.directive:ngView ngView} + * creates new scope, reinstantiates the controller. + */ + reload: function() { + forceReload = true; + $rootScope.$evalAsync(updateRoute); + } + }; + + $rootScope.$on('$locationChangeSuccess', updateRoute); + + return $route; + + ///////////////////////////////////////////////////// + + function switchRouteMatcher(on, when) { + // TODO(i): this code is convoluted and inefficient, we should construct the route matching + // regex only once and then reuse it + var regex = '^' + when.replace(/([\.\\\(\)\^\$])/g, "\\$1") + '$', + params = [], + dst = {}; + forEach(when.split(/\W/), function(param) { + if (param) { + var paramRegExp = new RegExp(":" + param + "([\\W])"); + if (regex.match(paramRegExp)) { + regex = regex.replace(paramRegExp, "([^\\/]*)$1"); + params.push(param); + } + } + }); + var match = on.match(new RegExp(regex)); + if (match) { + forEach(params, function(name, index) { + dst[name] = match[index + 1]; + }); + } + return match ? dst : null; + } + + function updateRoute() { + var next = parseRoute(), + last = $route.current; + + if (next && last && next.$route === last.$route + && equals(next.pathParams, last.pathParams) && !next.reloadOnSearch && !forceReload) { + last.params = next.params; + copy(last.params, $routeParams); + $rootScope.$broadcast('$routeUpdate', last); + } else if (next || last) { + forceReload = false; + $rootScope.$broadcast('$routeChangeStart', next, last); + $route.current = next; + if (next) { + if (next.redirectTo) { + if (isString(next.redirectTo)) { + $location.path(interpolate(next.redirectTo, next.params)).search(next.params) + .replace(); + } else { + $location.url(next.redirectTo(next.pathParams, $location.path(), $location.search())) + .replace(); + } + } + } + + $q.when(next). + then(function() { + if (next) { + var keys = [], + values = [], + template; + + forEach(next.resolve || {}, function(value, key) { + keys.push(key); + values.push(isFunction(value) ? $injector.invoke(value) : $injector.get(value)); + }); + if (isDefined(template = next.template)) { + } else if (isDefined(template = next.templateUrl)) { + template = $http.get(template, {cache: $templateCache}). + then(function(response) { return response.data; }); + } + if (isDefined(template)) { + keys.push('$template'); + values.push(template); + } + return $q.all(values).then(function(values) { + var locals = {}; + forEach(values, function(value, index) { + locals[keys[index]] = value; + }); + return locals; + }); + } + }). + // after route change + then(function(locals) { + if (next == $route.current) { + if (next) { + next.locals = locals; + copy(next.params, $routeParams); + } + $rootScope.$broadcast('$routeChangeSuccess', next, last); + } + }, function(error) { + if (next == $route.current) { + $rootScope.$broadcast('$routeChangeError', next, last, error); + } + }); + } + } + + + /** + * @returns the current active route, by matching it against the URL + */ + function parseRoute() { + // Match a route + var params, match; + forEach(routes, function(route, path) { + if (!match && (params = matcher($location.path(), path))) { + match = inherit(route, { + params: extend({}, $location.search(), params), + pathParams: params}); + match.$route = route; + } + }); + // No route matched; fallback to "otherwise" route + return match || routes[null] && inherit(routes[null], {params: {}, pathParams:{}}); + } + + /** + * @returns interpolation of the redirect path with the parametrs + */ + function interpolate(string, params) { + var result = []; + forEach((string||'').split(':'), function(segment, i) { + if (i == 0) { + result.push(segment); + } else { + var segmentMatch = segment.match(/(\w+)(.*)/); + var key = segmentMatch[1]; + result.push(params[key]); + result.push(segmentMatch[2] || ''); + delete params[key]; + } + }); + return result.join(''); + } + }]; +} + +/** + * @ngdoc object + * @name ng.$routeParams + * @requires $route + * + * @description + * Current set of route parameters. The route parameters are a combination of the + * {@link ng.$location $location} `search()`, and `path()`. The `path` parameters + * are extracted when the {@link ng.$route $route} path is matched. + * + * In case of parameter name collision, `path` params take precedence over `search` params. + * + * The service guarantees that the identity of the `$routeParams` object will remain unchanged + * (but its properties will likely change) even when a route change occurs. + * + * @example + *
+ *  // Given:
+ *  // URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby
+ *  // Route: /Chapter/:chapterId/Section/:sectionId
+ *  //
+ *  // Then
+ *  $routeParams ==> {chapterId:1, sectionId:2, search:'moby'}
+ * 
+ */ +function $RouteParamsProvider() { + this.$get = valueFn({}); +} + +/** + * DESIGN NOTES + * + * The design decisions behind the scope ware heavily favored for speed and memory consumption. + * + * The typical use of scope is to watch the expressions, which most of the time return the same + * value as last time so we optimize the operation. + * + * Closures construction is expensive from speed as well as memory: + * - no closures, instead ups prototypical inheritance for API + * - Internal state needs to be stored on scope directly, which means that private state is + * exposed as $$____ properties + * + * Loop operations are optimized by using while(count--) { ... } + * - this means that in order to keep the same order of execution as addition we have to add + * items to the array at the begging (shift) instead of at the end (push) + * + * Child scopes are created and removed often + * - Using array would be slow since inserts in meddle are expensive so we use linked list + * + * There are few watches then a lot of observers. This is why you don't want the observer to be + * implemented in the same way as watch. Watch requires return of initialization function which + * are expensive to construct. + */ + + +/** + * @ngdoc object + * @name ng.$rootScopeProvider + * @description + * + * Provider for the $rootScope service. + */ + +/** + * @ngdoc function + * @name ng.$rootScopeProvider#digestTtl + * @methodOf ng.$rootScopeProvider + * @description + * + * Sets the number of digest iteration the scope should attempt to execute before giving up and + * assuming that the model is unstable. + * + * The current default is 10 iterations. + * + * @param {number} limit The number of digest iterations. + */ + + +/** + * @ngdoc object + * @name ng.$rootScope + * @description + * + * Every application has a single root {@link ng.$rootScope.Scope scope}. + * All other scopes are child scopes of the root scope. Scopes provide mechanism for watching the model and provide + * event processing life-cycle. See {@link guide/scope developer guide on scopes}. + */ +function $RootScopeProvider(){ + var TTL = 10; + + this.digestTtl = function(value) { + if (arguments.length) { + TTL = value; + } + return TTL; + }; + + this.$get = ['$injector', '$exceptionHandler', '$parse', + function( $injector, $exceptionHandler, $parse) { + + /** + * @ngdoc function + * @name ng.$rootScope.Scope + * + * @description + * A root scope can be retrieved using the {@link ng.$rootScope $rootScope} key from the + * {@link AUTO.$injector $injector}. Child scopes are created using the + * {@link ng.$rootScope.Scope#$new $new()} method. (Most scopes are created automatically when + * compiled HTML template is executed.) + * + * Here is a simple scope snippet to show how you can interact with the scope. + *
+        angular.injector(['ng']).invoke(function($rootScope) {
+           var scope = $rootScope.$new();
+           scope.salutation = 'Hello';
+           scope.name = 'World';
+
+           expect(scope.greeting).toEqual(undefined);
+
+           scope.$watch('name', function() {
+             this.greeting = this.salutation + ' ' + this.name + '!';
+           }); // initialize the watch
+
+           expect(scope.greeting).toEqual(undefined);
+           scope.name = 'Misko';
+           // still old value, since watches have not been called yet
+           expect(scope.greeting).toEqual(undefined);
+
+           scope.$digest(); // fire all  the watches
+           expect(scope.greeting).toEqual('Hello Misko!');
+        });
+     * 
+ * + * # Inheritance + * A scope can inherit from a parent scope, as in this example: + *
+         var parent = $rootScope;
+         var child = parent.$new();
+
+         parent.salutation = "Hello";
+         child.name = "World";
+         expect(child.salutation).toEqual('Hello');
+
+         child.salutation = "Welcome";
+         expect(child.salutation).toEqual('Welcome');
+         expect(parent.salutation).toEqual('Hello');
+     * 
+ * + * + * @param {Object.=} providers Map of service factory which need to be provided + * for the current scope. Defaults to {@link ng}. + * @param {Object.=} instanceCache Provides pre-instantiated services which should + * append/override services provided by `providers`. This is handy when unit-testing and having + * the need to override a default service. + * @returns {Object} Newly created scope. + * + */ + function Scope() { + this.$id = nextUid(); + this.$$phase = this.$parent = this.$$watchers = + this.$$nextSibling = this.$$prevSibling = + this.$$childHead = this.$$childTail = null; + this['this'] = this.$root = this; + this.$$asyncQueue = []; + this.$$listeners = {}; + } + + /** + * @ngdoc property + * @name ng.$rootScope.Scope#$id + * @propertyOf ng.$rootScope.Scope + * @returns {number} Unique scope ID (monotonically increasing alphanumeric sequence) useful for + * debugging. + */ + + + Scope.prototype = { + /** + * @ngdoc function + * @name ng.$rootScope.Scope#$new + * @methodOf ng.$rootScope.Scope + * @function + * + * @description + * Creates a new child {@link ng.$rootScope.Scope scope}. + * + * The parent scope will propagate the {@link ng.$rootScope.Scope#$digest $digest()} and + * {@link ng.$rootScope.Scope#$digest $digest()} events. The scope can be removed from the scope + * hierarchy using {@link ng.$rootScope.Scope#$destroy $destroy()}. + * + * {@link ng.$rootScope.Scope#$destroy $destroy()} must be called on a scope when it is desired for + * the scope and its child scopes to be permanently detached from the parent and thus stop + * participating in model change detection and listener notification by invoking. + * + * @param {boolean} isolate if true then the scoped does not prototypically inherit from the + * parent scope. The scope is isolated, as it can not se parent scope properties. + * When creating widgets it is useful for the widget to not accidently read parent + * state. + * + * @returns {Object} The newly created child scope. + * + */ + $new: function(isolate) { + var Child, + child; + + if (isFunction(isolate)) { + // TODO: remove at some point + throw Error('API-CHANGE: Use $controller to instantiate controllers.'); + } + if (isolate) { + child = new Scope(); + child.$root = this.$root; + } else { + Child = function() {}; // should be anonymous; This is so that when the minifier munges + // the name it does not become random set of chars. These will then show up as class + // name in the debugger. + Child.prototype = this; + child = new Child(); + child.$id = nextUid(); + } + child['this'] = child; + child.$$listeners = {}; + child.$parent = this; + child.$$asyncQueue = []; + child.$$watchers = child.$$nextSibling = child.$$childHead = child.$$childTail = null; + child.$$prevSibling = this.$$childTail; + if (this.$$childHead) { + this.$$childTail.$$nextSibling = child; + this.$$childTail = child; + } else { + this.$$childHead = this.$$childTail = child; + } + return child; + }, + + /** + * @ngdoc function + * @name ng.$rootScope.Scope#$watch + * @methodOf ng.$rootScope.Scope + * @function + * + * @description + * Registers a `listener` callback to be executed whenever the `watchExpression` changes. + * + * - The `watchExpression` is called on every call to {@link ng.$rootScope.Scope#$digest $digest()} and + * should return the value which will be watched. (Since {@link ng.$rootScope.Scope#$digest $digest()} + * reruns when it detects changes the `watchExpression` can execute multiple times per + * {@link ng.$rootScope.Scope#$digest $digest()} and should be idempotent.) + * - The `listener` is called only when the value from the current `watchExpression` and the + * previous call to `watchExpression' are not equal (with the exception of the initial run + * see below). The inequality is determined according to + * {@link angular.equals} function. To save the value of the object for later comparison + * {@link angular.copy} function is used. It also means that watching complex options will + * have adverse memory and performance implications. + * - The watch `listener` may change the model, which may trigger other `listener`s to fire. This + * is achieved by rerunning the watchers until no changes are detected. The rerun iteration + * limit is 100 to prevent infinity loop deadlock. + * + * + * If you want to be notified whenever {@link ng.$rootScope.Scope#$digest $digest} is called, + * you can register an `watchExpression` function with no `listener`. (Since `watchExpression`, + * can execute multiple times per {@link ng.$rootScope.Scope#$digest $digest} cycle when a change is + * detected, be prepared for multiple calls to your listener.) + * + * After a watcher is registered with the scope, the `listener` fn is called asynchronously + * (via {@link ng.$rootScope.Scope#$evalAsync $evalAsync}) to initialize the + * watcher. In rare cases, this is undesirable because the listener is called when the result + * of `watchExpression` didn't change. To detect this scenario within the `listener` fn, you + * can compare the `newVal` and `oldVal`. If these two values are identical (`===`) then the + * listener was called due to initialization. + * + * + * # Example + *
+           // let's assume that scope was dependency injected as the $rootScope
+           var scope = $rootScope;
+           scope.name = 'misko';
+           scope.counter = 0;
+
+           expect(scope.counter).toEqual(0);
+           scope.$watch('name', function(newValue, oldValue) { counter = counter + 1; });
+           expect(scope.counter).toEqual(0);
+
+           scope.$digest();
+           // no variable change
+           expect(scope.counter).toEqual(0);
+
+           scope.name = 'adam';
+           scope.$digest();
+           expect(scope.counter).toEqual(1);
+       * 
+ * + * + * + * @param {(function()|string)} watchExpression Expression that is evaluated on each + * {@link ng.$rootScope.Scope#$digest $digest} cycle. A change in the return value triggers a + * call to the `listener`. + * + * - `string`: Evaluated as {@link guide/expression expression} + * - `function(scope)`: called with current `scope` as a parameter. + * @param {(function()|string)=} listener Callback called whenever the return value of + * the `watchExpression` changes. + * + * - `string`: Evaluated as {@link guide/expression expression} + * - `function(newValue, oldValue, scope)`: called with current and previous values as parameters. + * + * @param {boolean=} objectEquality Compare object for equality rather then for refference. + * @returns {function()} Returns a deregistration function for this listener. + */ + $watch: function(watchExp, listener, objectEquality) { + var scope = this, + get = compileToFn(watchExp, 'watch'), + array = scope.$$watchers, + watcher = { + fn: listener, + last: initWatchVal, + get: get, + exp: watchExp, + eq: !!objectEquality + }; + + // in the case user pass string, we need to compile it, do we really need this ? + if (!isFunction(listener)) { + var listenFn = compileToFn(listener || noop, 'listener'); + watcher.fn = function(newVal, oldVal, scope) {listenFn(scope);}; + } + + if (!array) { + array = scope.$$watchers = []; + } + // we use unshift since we use a while loop in $digest for speed. + // the while loop reads in reverse order. + array.unshift(watcher); + + return function() { + arrayRemove(array, watcher); + }; + }, + + /** + * @ngdoc function + * @name ng.$rootScope.Scope#$digest + * @methodOf ng.$rootScope.Scope + * @function + * + * @description + * Process all of the {@link ng.$rootScope.Scope#$watch watchers} of the current scope and its children. + * Because a {@link ng.$rootScope.Scope#$watch watcher}'s listener can change the model, the + * `$digest()` keeps calling the {@link ng.$rootScope.Scope#$watch watchers} until no more listeners are + * firing. This means that it is possible to get into an infinite loop. This function will throw + * `'Maximum iteration limit exceeded.'` if the number of iterations exceeds 10. + * + * Usually you don't call `$digest()` directly in + * {@link ng.directive:ngController controllers} or in + * {@link ng.$compileProvider#directive directives}. + * Instead a call to {@link ng.$rootScope.Scope#$apply $apply()} (typically from within a + * {@link ng.$compileProvider#directive directives}) will force a `$digest()`. + * + * If you want to be notified whenever `$digest()` is called, + * you can register a `watchExpression` function with {@link ng.$rootScope.Scope#$watch $watch()} + * with no `listener`. + * + * You may have a need to call `$digest()` from within unit-tests, to simulate the scope + * life-cycle. + * + * # Example + *
+           var scope = ...;
+           scope.name = 'misko';
+           scope.counter = 0;
+
+           expect(scope.counter).toEqual(0);
+           scope.$watch('name', function(newValue, oldValue) {
+             counter = counter + 1;
+           });
+           expect(scope.counter).toEqual(0);
+
+           scope.$digest();
+           // no variable change
+           expect(scope.counter).toEqual(0);
+
+           scope.name = 'adam';
+           scope.$digest();
+           expect(scope.counter).toEqual(1);
+       * 
+ * + */ + $digest: function() { + var watch, value, last, + watchers, + asyncQueue, + length, + dirty, ttl = TTL, + next, current, target = this, + watchLog = [], + logIdx, logMsg; + + beginPhase('$digest'); + + do { + dirty = false; + current = target; + do { + asyncQueue = current.$$asyncQueue; + while(asyncQueue.length) { + try { + current.$eval(asyncQueue.shift()); + } catch (e) { + $exceptionHandler(e); + } + } + if ((watchers = current.$$watchers)) { + // process our watches + length = watchers.length; + while (length--) { + try { + watch = watchers[length]; + // Most common watches are on primitives, in which case we can short + // circuit it with === operator, only when === fails do we use .equals + if ((value = watch.get(current)) !== (last = watch.last) && + !(watch.eq + ? equals(value, last) + : (typeof value == 'number' && typeof last == 'number' + && isNaN(value) && isNaN(last)))) { + dirty = true; + watch.last = watch.eq ? copy(value) : value; + watch.fn(value, ((last === initWatchVal) ? value : last), current); + if (ttl < 5) { + logIdx = 4 - ttl; + if (!watchLog[logIdx]) watchLog[logIdx] = []; + logMsg = (isFunction(watch.exp)) + ? 'fn: ' + (watch.exp.name || watch.exp.toString()) + : watch.exp; + logMsg += '; newVal: ' + toJson(value) + '; oldVal: ' + toJson(last); + watchLog[logIdx].push(logMsg); + } + } + } catch (e) { + $exceptionHandler(e); + } + } + } + + // Insanity Warning: scope depth-first traversal + // yes, this code is a bit crazy, but it works and we have tests to prove it! + // this piece should be kept in sync with the traversal in $broadcast + if (!(next = (current.$$childHead || (current !== target && current.$$nextSibling)))) { + while(current !== target && !(next = current.$$nextSibling)) { + current = current.$parent; + } + } + } while ((current = next)); + + if(dirty && !(ttl--)) { + clearPhase(); + throw Error(TTL + ' $digest() iterations reached. Aborting!\n' + + 'Watchers fired in the last 5 iterations: ' + toJson(watchLog)); + } + } while (dirty || asyncQueue.length); + + clearPhase(); + }, + + + /** + * @ngdoc event + * @name ng.$rootScope.Scope#$destroy + * @eventOf ng.$rootScope.Scope + * @eventType broadcast on scope being destroyed + * + * @description + * Broadcasted when a scope and its children are being destroyed. + */ + + /** + * @ngdoc function + * @name ng.$rootScope.Scope#$destroy + * @methodOf ng.$rootScope.Scope + * @function + * + * @description + * Remove the current scope (and all of its children) from the parent scope. Removal implies + * that calls to {@link ng.$rootScope.Scope#$digest $digest()} will no longer + * propagate to the current scope and its children. Removal also implies that the current + * scope is eligible for garbage collection. + * + * The `$destroy()` is usually used by directives such as + * {@link ng.directive:ngRepeat ngRepeat} for managing the + * unrolling of the loop. + * + * Just before a scope is destroyed a `$destroy` event is broadcasted on this scope. + * Application code can register a `$destroy` event handler that will give it chance to + * perform any necessary cleanup. + */ + $destroy: function() { + if ($rootScope == this) return; // we can't remove the root node; + var parent = this.$parent; + + this.$broadcast('$destroy'); + + if (parent.$$childHead == this) parent.$$childHead = this.$$nextSibling; + if (parent.$$childTail == this) parent.$$childTail = this.$$prevSibling; + if (this.$$prevSibling) this.$$prevSibling.$$nextSibling = this.$$nextSibling; + if (this.$$nextSibling) this.$$nextSibling.$$prevSibling = this.$$prevSibling; + }, + + /** + * @ngdoc function + * @name ng.$rootScope.Scope#$eval + * @methodOf ng.$rootScope.Scope + * @function + * + * @description + * Executes the `expression` on the current scope returning the result. Any exceptions in the + * expression are propagated (uncaught). This is useful when evaluating engular expressions. + * + * # Example + *
+           var scope = ng.$rootScope.Scope();
+           scope.a = 1;
+           scope.b = 2;
+
+           expect(scope.$eval('a+b')).toEqual(3);
+           expect(scope.$eval(function(scope){ return scope.a + scope.b; })).toEqual(3);
+       * 
+ * + * @param {(string|function())=} expression An angular expression to be executed. + * + * - `string`: execute using the rules as defined in {@link guide/expression expression}. + * - `function(scope)`: execute the function with the current `scope` parameter. + * + * @returns {*} The result of evaluating the expression. + */ + $eval: function(expr, locals) { + return $parse(expr)(this, locals); + }, + + /** + * @ngdoc function + * @name ng.$rootScope.Scope#$evalAsync + * @methodOf ng.$rootScope.Scope + * @function + * + * @description + * Executes the expression on the current scope at a later point in time. + * + * The `$evalAsync` makes no guarantees as to when the `expression` will be executed, only that: + * + * - it will execute in the current script execution context (before any DOM rendering). + * - at least one {@link ng.$rootScope.Scope#$digest $digest cycle} will be performed after + * `expression` execution. + * + * Any exceptions from the execution of the expression are forwarded to the + * {@link ng.$exceptionHandler $exceptionHandler} service. + * + * @param {(string|function())=} expression An angular expression to be executed. + * + * - `string`: execute using the rules as defined in {@link guide/expression expression}. + * - `function(scope)`: execute the function with the current `scope` parameter. + * + */ + $evalAsync: function(expr) { + this.$$asyncQueue.push(expr); + }, + + /** + * @ngdoc function + * @name ng.$rootScope.Scope#$apply + * @methodOf ng.$rootScope.Scope + * @function + * + * @description + * `$apply()` is used to execute an expression in angular from outside of the angular framework. + * (For example from browser DOM events, setTimeout, XHR or third party libraries). + * Because we are calling into the angular framework we need to perform proper scope life-cycle + * of {@link ng.$exceptionHandler exception handling}, + * {@link ng.$rootScope.Scope#$digest executing watches}. + * + * ## Life cycle + * + * # Pseudo-Code of `$apply()` + *
+           function $apply(expr) {
+             try {
+               return $eval(expr);
+             } catch (e) {
+               $exceptionHandler(e);
+             } finally {
+               $root.$digest();
+             }
+           }
+       * 
+ * + * + * Scope's `$apply()` method transitions through the following stages: + * + * 1. The {@link guide/expression expression} is executed using the + * {@link ng.$rootScope.Scope#$eval $eval()} method. + * 2. Any exceptions from the execution of the expression are forwarded to the + * {@link ng.$exceptionHandler $exceptionHandler} service. + * 3. The {@link ng.$rootScope.Scope#$watch watch} listeners are fired immediately after the expression + * was executed using the {@link ng.$rootScope.Scope#$digest $digest()} method. + * + * + * @param {(string|function())=} exp An angular expression to be executed. + * + * - `string`: execute using the rules as defined in {@link guide/expression expression}. + * - `function(scope)`: execute the function with current `scope` parameter. + * + * @returns {*} The result of evaluating the expression. + */ + $apply: function(expr) { + try { + beginPhase('$apply'); + return this.$eval(expr); + } catch (e) { + $exceptionHandler(e); + } finally { + clearPhase(); + try { + $rootScope.$digest(); + } catch (e) { + $exceptionHandler(e); + throw e; + } + } + }, + + /** + * @ngdoc function + * @name ng.$rootScope.Scope#$on + * @methodOf ng.$rootScope.Scope + * @function + * + * @description + * Listen on events of a given type. See {@link ng.$rootScope.Scope#$emit $emit} for discussion of + * event life cycle. + * + * @param {string} name Event name to listen on. + * @param {function(event)} listener Function to call when the event is emitted. + * @returns {function()} Returns a deregistration function for this listener. + * + * The event listener function format is: `function(event, args...)`. The `event` object + * passed into the listener has the following attributes: + * + * - `targetScope` - {Scope}: the scope on which the event was `$emit`-ed or `$broadcast`-ed. + * - `currentScope` - {Scope}: the current scope which is handling the event. + * - `name` - {string}: Name of the event. + * - `stopPropagation` - {function=}: calling `stopPropagation` function will cancel further event propagation + * (available only for events that were `$emit`-ed). + * - `preventDefault` - {function}: calling `preventDefault` sets `defaultPrevented` flag to true. + * - `defaultPrevented` - {boolean}: true if `preventDefault` was called. + */ + $on: function(name, listener) { + var namedListeners = this.$$listeners[name]; + if (!namedListeners) { + this.$$listeners[name] = namedListeners = []; + } + namedListeners.push(listener); + + return function() { + arrayRemove(namedListeners, listener); + }; + }, + + + /** + * @ngdoc function + * @name ng.$rootScope.Scope#$emit + * @methodOf ng.$rootScope.Scope + * @function + * + * @description + * Dispatches an event `name` upwards through the scope hierarchy notifying the + * registered {@link ng.$rootScope.Scope#$on} listeners. + * + * The event life cycle starts at the scope on which `$emit` was called. All + * {@link ng.$rootScope.Scope#$on listeners} listening for `name` event on this scope get notified. + * Afterwards, the event traverses upwards toward the root scope and calls all registered + * listeners along the way. The event will stop propagating if one of the listeners cancels it. + * + * Any exception emmited from the {@link ng.$rootScope.Scope#$on listeners} will be passed + * onto the {@link ng.$exceptionHandler $exceptionHandler} service. + * + * @param {string} name Event name to emit. + * @param {...*} args Optional set of arguments which will be passed onto the event listeners. + * @return {Object} Event object, see {@link ng.$rootScope.Scope#$on} + */ + $emit: function(name, args) { + var empty = [], + namedListeners, + scope = this, + stopPropagation = false, + event = { + name: name, + targetScope: scope, + stopPropagation: function() {stopPropagation = true;}, + preventDefault: function() { + event.defaultPrevented = true; + }, + defaultPrevented: false + }, + listenerArgs = concat([event], arguments, 1), + i, length; + + do { + namedListeners = scope.$$listeners[name] || empty; + event.currentScope = scope; + for (i=0, length=namedListeners.length; i 7), + hasEvent: function(event) { + // IE9 implements 'input' event it's so fubared that we rather pretend that it doesn't have + // it. In particular the event is not fired when backspace or delete key are pressed or + // when cut operation is performed. + if (event == 'input' && msie == 9) return false; + + if (isUndefined(eventSupport[event])) { + var divElm = $window.document.createElement('div'); + eventSupport[event] = 'on' + event in divElm; + } + + return eventSupport[event]; + }, + // TODO(i): currently there is no way to feature detect CSP without triggering alerts + csp: false + }; + }]; +} + +/** + * @ngdoc object + * @name ng.$window + * + * @description + * A reference to the browser's `window` object. While `window` + * is globally available in JavaScript, it causes testability problems, because + * it is a global variable. In angular we always refer to it through the + * `$window` service, so it may be overriden, removed or mocked for testing. + * + * All expressions are evaluated with respect to current scope so they don't + * suffer from window globality. + * + * @example + + + + + + + + + */ +function $WindowProvider(){ + this.$get = valueFn(window); +} + +/** + * Parse headers into key value object + * + * @param {string} headers Raw headers as a string + * @returns {Object} Parsed headers as key value object + */ +function parseHeaders(headers) { + var parsed = {}, key, val, i; + + if (!headers) return parsed; + + forEach(headers.split('\n'), function(line) { + i = line.indexOf(':'); + key = lowercase(trim(line.substr(0, i))); + val = trim(line.substr(i + 1)); + + if (key) { + if (parsed[key]) { + parsed[key] += ', ' + val; + } else { + parsed[key] = val; + } + } + }); + + return parsed; +} + + +/** + * Returns a function that provides access to parsed headers. + * + * Headers are lazy parsed when first requested. + * @see parseHeaders + * + * @param {(string|Object)} headers Headers to provide access to. + * @returns {function(string=)} Returns a getter function which if called with: + * + * - if called with single an argument returns a single header value or null + * - if called with no arguments returns an object containing all headers. + */ +function headersGetter(headers) { + var headersObj = isObject(headers) ? headers : undefined; + + return function(name) { + if (!headersObj) headersObj = parseHeaders(headers); + + if (name) { + return headersObj[lowercase(name)] || null; + } + + return headersObj; + }; +} + + +/** + * Chain all given functions + * + * This function is used for both request and response transforming + * + * @param {*} data Data to transform. + * @param {function(string=)} headers Http headers getter fn. + * @param {(function|Array.)} fns Function or an array of functions. + * @returns {*} Transformed data. + */ +function transformData(data, headers, fns) { + if (isFunction(fns)) + return fns(data, headers); + + forEach(fns, function(fn) { + data = fn(data, headers); + }); + + return data; +} + + +function isSuccess(status) { + return 200 <= status && status < 300; +} + + +function $HttpProvider() { + var JSON_START = /^\s*(\[|\{[^\{])/, + JSON_END = /[\}\]]\s*$/, + PROTECTION_PREFIX = /^\)\]\}',?\n/; + + var $config = this.defaults = { + // transform incoming response data + transformResponse: [function(data) { + if (isString(data)) { + // strip json vulnerability protection prefix + data = data.replace(PROTECTION_PREFIX, ''); + if (JSON_START.test(data) && JSON_END.test(data)) + data = fromJson(data, true); + } + return data; + }], + + // transform outgoing request data + transformRequest: [function(d) { + return isObject(d) && !isFile(d) ? toJson(d) : d; + }], + + // default headers + headers: { + common: { + 'Accept': 'application/json, text/plain, */*', + 'X-Requested-With': 'XMLHttpRequest' + }, + post: {'Content-Type': 'application/json;charset=utf-8'}, + put: {'Content-Type': 'application/json;charset=utf-8'} + } + }; + + var providerResponseInterceptors = this.responseInterceptors = []; + + this.$get = ['$httpBackend', '$browser', '$cacheFactory', '$rootScope', '$q', '$injector', + function($httpBackend, $browser, $cacheFactory, $rootScope, $q, $injector) { + + var defaultCache = $cacheFactory('$http'), + responseInterceptors = []; + + forEach(providerResponseInterceptors, function(interceptor) { + responseInterceptors.push( + isString(interceptor) + ? $injector.get(interceptor) + : $injector.invoke(interceptor) + ); + }); + + + /** + * @ngdoc function + * @name ng.$http + * @requires $httpBacked + * @requires $browser + * @requires $cacheFactory + * @requires $rootScope + * @requires $q + * @requires $injector + * + * @description + * The `$http` service is a core Angular service that facilitates communication with the remote + * HTTP servers via browser's {@link https://developer.mozilla.org/en/xmlhttprequest + * XMLHttpRequest} object or via {@link http://en.wikipedia.org/wiki/JSONP JSONP}. + * + * For unit testing applications that use `$http` service, see + * {@link ngMock.$httpBackend $httpBackend mock}. + * + * For a higher level of abstraction, please check out the {@link ngResource.$resource + * $resource} service. + * + * The $http API is based on the {@link ng.$q deferred/promise APIs} exposed by + * the $q service. While for simple usage patters this doesn't matter much, for advanced usage, + * it is important to familiarize yourself with these apis and guarantees they provide. + * + * + * # General usage + * The `$http` service is a function which takes a single argument — a configuration object — + * that is used to generate an http request and returns a {@link ng.$q promise} + * with two $http specific methods: `success` and `error`. + * + *
+     *   $http({method: 'GET', url: '/someUrl'}).
+     *     success(function(data, status, headers, config) {
+     *       // this callback will be called asynchronously
+     *       // when the response is available
+     *     }).
+     *     error(function(data, status, headers, config) {
+     *       // called asynchronously if an error occurs
+     *       // or server returns response with status
+     *       // code outside of the <200, 400) range
+     *     });
+     * 
+ * + * Since the returned value of calling the $http function is a Promise object, you can also use + * the `then` method to register callbacks, and these callbacks will receive a single argument – + * an object representing the response. See the api signature and type info below for more + * details. + * + * + * # Shortcut methods + * + * Since all invocation of the $http service require definition of the http method and url and + * POST and PUT requests require response body/data to be provided as well, shortcut methods + * were created to simplify using the api: + * + *
+     *   $http.get('/someUrl').success(successCallback);
+     *   $http.post('/someUrl', data).success(successCallback);
+     * 
+ * + * Complete list of shortcut methods: + * + * - {@link ng.$http#get $http.get} + * - {@link ng.$http#head $http.head} + * - {@link ng.$http#post $http.post} + * - {@link ng.$http#put $http.put} + * - {@link ng.$http#delete $http.delete} + * - {@link ng.$http#jsonp $http.jsonp} + * + * + * # Setting HTTP Headers + * + * The $http service will automatically add certain http headers to all requests. These defaults + * can be fully configured by accessing the `$httpProvider.defaults.headers` configuration + * object, which currently contains this default configuration: + * + * - `$httpProvider.defaults.headers.common` (headers that are common for all requests): + * - `Accept: application/json, text/plain, * / *` + * - `X-Requested-With: XMLHttpRequest` + * - `$httpProvider.defaults.headers.post`: (header defaults for HTTP POST requests) + * - `Content-Type: application/json` + * - `$httpProvider.defaults.headers.put` (header defaults for HTTP PUT requests) + * - `Content-Type: application/json` + * + * To add or overwrite these defaults, simply add or remove a property from this configuration + * objects. To add headers for an HTTP method other than POST or PUT, simply add a new object + * with name equal to the lower-cased http method name, e.g. + * `$httpProvider.defaults.headers.get['My-Header']='value'`. + * + * Additionally, the defaults can be set at runtime via the `$http.defaults` object in a similar + * fassion as described above. + * + * + * # Transforming Requests and Responses + * + * Both requests and responses can be transformed using transform functions. By default, Angular + * applies these transformations: + * + * Request transformations: + * + * - if the `data` property of the request config object contains an object, serialize it into + * JSON format. + * + * Response transformations: + * + * - if XSRF prefix is detected, strip it (see Security Considerations section below) + * - if json response is detected, deserialize it using a JSON parser + * + * To override these transformation locally, specify transform functions as `transformRequest` + * and/or `transformResponse` properties of the config object. To globally override the default + * transforms, override the `$httpProvider.defaults.transformRequest` and + * `$httpProvider.defaults.transformResponse` properties of the `$httpProvider`. + * + * + * # Caching + * + * To enable caching set the configuration property `cache` to `true`. When the cache is + * enabled, `$http` stores the response from the server in local cache. Next time the + * response is served from the cache without sending a request to the server. + * + * Note that even if the response is served from cache, delivery of the data is asynchronous in + * the same way that real requests are. + * + * If there are multiple GET requests for the same url that should be cached using the same + * cache, but the cache is not populated yet, only one request to the server will be made and + * the remaining requests will be fulfilled using the response for the first request. + * + * + * # Response interceptors + * + * Before you start creating interceptors, be sure to understand the + * {@link ng.$q $q and deferred/promise APIs}. + * + * For purposes of global error handling, authentication or any kind of synchronous or + * asynchronous preprocessing of received responses, it is desirable to be able to intercept + * responses for http requests before they are handed over to the application code that + * initiated these requests. The response interceptors leverage the {@link ng.$q + * promise apis} to fulfil this need for both synchronous and asynchronous preprocessing. + * + * The interceptors are service factories that are registered with the $httpProvider by + * adding them to the `$httpProvider.responseInterceptors` array. The factory is called and + * injected with dependencies (if specified) and returns the interceptor — a function that + * takes a {@link ng.$q promise} and returns the original or a new promise. + * + *
+     *   // register the interceptor as a service
+     *   $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
+     *     return function(promise) {
+     *       return promise.then(function(response) {
+     *         // do something on success
+     *       }, function(response) {
+     *         // do something on error
+     *         if (canRecover(response)) {
+     *           return responseOrNewPromise
+     *         }
+     *         return $q.reject(response);
+     *       });
+     *     }
+     *   });
+     *
+     *   $httpProvider.responseInterceptors.push('myHttpInterceptor');
+     *
+     *
+     *   // register the interceptor via an anonymous factory
+     *   $httpProvider.responseInterceptors.push(function($q, dependency1, dependency2) {
+     *     return function(promise) {
+     *       // same as above
+     *     }
+     *   });
+     * 
+ * + * + * # Security Considerations + * + * When designing web applications, consider security threats from: + * + * - {@link http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx + * JSON Vulnerability} + * - {@link http://en.wikipedia.org/wiki/Cross-site_request_forgery XSRF} + * + * Both server and the client must cooperate in order to eliminate these threats. Angular comes + * pre-configured with strategies that address these issues, but for this to work backend server + * cooperation is required. + * + * ## JSON Vulnerability Protection + * + * A {@link http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx + * JSON Vulnerability} allows third party web-site to turn your JSON resource URL into + * {@link http://en.wikipedia.org/wiki/JSON#JSONP JSONP} request under some conditions. To + * counter this your server can prefix all JSON requests with following string `")]}',\n"`. + * Angular will automatically strip the prefix before processing it as JSON. + * + * For example if your server needs to return: + *
+     * ['one','two']
+     * 
+ * + * which is vulnerable to attack, your server can return: + *
+     * )]}',
+     * ['one','two']
+     * 
+ * + * Angular will strip the prefix, before processing the JSON. + * + * + * ## Cross Site Request Forgery (XSRF) Protection + * + * {@link http://en.wikipedia.org/wiki/Cross-site_request_forgery XSRF} is a technique by which + * an unauthorized site can gain your user's private data. Angular provides following mechanism + * to counter XSRF. When performing XHR requests, the $http service reads a token from a cookie + * called `XSRF-TOKEN` and sets it as the HTTP header `X-XSRF-TOKEN`. Since only JavaScript that + * runs on your domain could read the cookie, your server can be assured that the XHR came from + * JavaScript running on your domain. + * + * To take advantage of this, your server needs to set a token in a JavaScript readable session + * cookie called `XSRF-TOKEN` on first HTTP GET request. On subsequent non-GET requests the + * server can verify that the cookie matches `X-XSRF-TOKEN` HTTP header, and therefore be sure + * that only JavaScript running on your domain could have read the token. The token must be + * unique for each user and must be verifiable by the server (to prevent the JavaScript making + * up its own tokens). We recommend that the token is a digest of your site's authentication + * cookie with {@link http://en.wikipedia.org/wiki/Rainbow_table salt for added security}. + * + * + * @param {object} config Object describing the request to be made and how it should be + * processed. The object has following properties: + * + * - **method** – `{string}` – HTTP method (e.g. 'GET', 'POST', etc) + * - **url** – `{string}` – Absolute or relative URL of the resource that is being requested. + * - **params** – `{Object.}` – Map of strings or objects which will be turned to + * `?key1=value1&key2=value2` after the url. If the value is not a string, it will be JSONified. + * - **data** – `{string|Object}` – Data to be sent as the request message data. + * - **headers** – `{Object}` – Map of strings representing HTTP headers to send to the server. + * - **transformRequest** – `{function(data, headersGetter)|Array.}` – + * transform function or an array of such functions. The transform function takes the http + * request body and headers and returns its transformed (typically serialized) version. + * - **transformResponse** – `{function(data, headersGetter)|Array.}` – + * transform function or an array of such functions. The transform function takes the http + * response body and headers and returns its transformed (typically deserialized) version. + * - **cache** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the + * GET request, otherwise if a cache instance built with + * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for + * caching. + * - **timeout** – `{number}` – timeout in milliseconds. + * - **withCredentials** - `{boolean}` - whether to to set the `withCredentials` flag on the + * XHR object. See {@link https://developer.mozilla.org/en/http_access_control#section_5 + * requests with credentials} for more information. + * + * @returns {HttpPromise} Returns a {@link ng.$q promise} object with the + * standard `then` method and two http specific methods: `success` and `error`. The `then` + * method takes two arguments a success and an error callback which will be called with a + * response object. The `success` and `error` methods take a single argument - a function that + * will be called when the request succeeds or fails respectively. The arguments passed into + * these functions are destructured representation of the response object passed into the + * `then` method. The response object has these properties: + * + * - **data** – `{string|Object}` – The response body transformed with the transform functions. + * - **status** – `{number}` – HTTP status code of the response. + * - **headers** – `{function([headerName])}` – Header getter function. + * - **config** – `{Object}` – The configuration object that was used to generate the request. + * + * @property {Array.} pendingRequests Array of config objects for currently pending + * requests. This is primarily meant to be used for debugging purposes. + * + * + * @example + + +
+ + +
+ + + +
http status code: {{status}}
+
http response data: {{data}}
+
+
+ + function FetchCtrl($scope, $http, $templateCache) { + $scope.method = 'GET'; + $scope.url = 'http-hello.html'; + + $scope.fetch = function() { + $scope.code = null; + $scope.response = null; + + $http({method: $scope.method, url: $scope.url, cache: $templateCache}). + success(function(data, status) { + $scope.status = status; + $scope.data = data; + }). + error(function(data, status) { + $scope.data = data || "Request failed"; + $scope.status = status; + }); + }; + + $scope.updateModel = function(method, url) { + $scope.method = method; + $scope.url = url; + }; + } + + + Hello, $http! + + + it('should make an xhr GET request', function() { + element(':button:contains("Sample GET")').click(); + element(':button:contains("fetch")').click(); + expect(binding('status')).toBe('200'); + expect(binding('data')).toMatch(/Hello, \$http!/); + }); + + it('should make a JSONP request to angularjs.org', function() { + element(':button:contains("Sample JSONP")').click(); + element(':button:contains("fetch")').click(); + expect(binding('status')).toBe('200'); + expect(binding('data')).toMatch(/Super Hero!/); + }); + + it('should make JSONP request to invalid URL and invoke the error handler', + function() { + element(':button:contains("Invalid JSONP")').click(); + element(':button:contains("fetch")').click(); + expect(binding('status')).toBe('0'); + expect(binding('data')).toBe('Request failed'); + }); + +
+ */ + function $http(config) { + config.method = uppercase(config.method); + + var reqTransformFn = config.transformRequest || $config.transformRequest, + respTransformFn = config.transformResponse || $config.transformResponse, + defHeaders = $config.headers, + reqHeaders = extend({'X-XSRF-TOKEN': $browser.cookies()['XSRF-TOKEN']}, + defHeaders.common, defHeaders[lowercase(config.method)], config.headers), + reqData = transformData(config.data, headersGetter(reqHeaders), reqTransformFn), + promise; + + // strip content-type if data is undefined + if (isUndefined(config.data)) { + delete reqHeaders['Content-Type']; + } + + // send request + promise = sendReq(config, reqData, reqHeaders); + + + // transform future response + promise = promise.then(transformResponse, transformResponse); + + // apply interceptors + forEach(responseInterceptors, function(interceptor) { + promise = interceptor(promise); + }); + + promise.success = function(fn) { + promise.then(function(response) { + fn(response.data, response.status, response.headers, config); + }); + return promise; + }; + + promise.error = function(fn) { + promise.then(null, function(response) { + fn(response.data, response.status, response.headers, config); + }); + return promise; + }; + + return promise; + + function transformResponse(response) { + // make a copy since the response must be cacheable + var resp = extend({}, response, { + data: transformData(response.data, response.headers, respTransformFn) + }); + return (isSuccess(response.status)) + ? resp + : $q.reject(resp); + } + } + + $http.pendingRequests = []; + + /** + * @ngdoc method + * @name ng.$http#get + * @methodOf ng.$http + * + * @description + * Shortcut method to perform `GET` request + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + + /** + * @ngdoc method + * @name ng.$http#delete + * @methodOf ng.$http + * + * @description + * Shortcut method to perform `DELETE` request + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + + /** + * @ngdoc method + * @name ng.$http#head + * @methodOf ng.$http + * + * @description + * Shortcut method to perform `HEAD` request + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + + /** + * @ngdoc method + * @name ng.$http#jsonp + * @methodOf ng.$http + * + * @description + * Shortcut method to perform `JSONP` request + * + * @param {string} url Relative or absolute URL specifying the destination of the request. + * Should contain `JSON_CALLBACK` string. + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + createShortMethods('get', 'delete', 'head', 'jsonp'); + + /** + * @ngdoc method + * @name ng.$http#post + * @methodOf ng.$http + * + * @description + * Shortcut method to perform `POST` request + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {*} data Request content + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + + /** + * @ngdoc method + * @name ng.$http#put + * @methodOf ng.$http + * + * @description + * Shortcut method to perform `PUT` request + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {*} data Request content + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + createShortMethodsWithData('post', 'put'); + + /** + * @ngdoc property + * @name ng.$http#defaults + * @propertyOf ng.$http + * + * @description + * Runtime equivalent of the `$httpProvider.defaults` property. Allows configuration of + * default headers as well as request and response transformations. + * + * See "Setting HTTP Headers" and "Transforming Requests and Responses" sections above. + */ + $http.defaults = $config; + + + return $http; + + + function createShortMethods(names) { + forEach(arguments, function(name) { + $http[name] = function(url, config) { + return $http(extend(config || {}, { + method: name, + url: url + })); + }; + }); + } + + + function createShortMethodsWithData(name) { + forEach(arguments, function(name) { + $http[name] = function(url, data, config) { + return $http(extend(config || {}, { + method: name, + url: url, + data: data + })); + }; + }); + } + + + /** + * Makes the request + * + * !!! ACCESSES CLOSURE VARS: + * $httpBackend, $config, $log, $rootScope, defaultCache, $http.pendingRequests + */ + function sendReq(config, reqData, reqHeaders) { + var deferred = $q.defer(), + promise = deferred.promise, + cache, + cachedResp, + url = buildUrl(config.url, config.params); + + $http.pendingRequests.push(config); + promise.then(removePendingReq, removePendingReq); + + + if (config.cache && config.method == 'GET') { + cache = isObject(config.cache) ? config.cache : defaultCache; + } + + if (cache) { + cachedResp = cache.get(url); + if (cachedResp) { + if (cachedResp.then) { + // cached request has already been sent, but there is no response yet + cachedResp.then(removePendingReq, removePendingReq); + return cachedResp; + } else { + // serving from cache + if (isArray(cachedResp)) { + resolvePromise(cachedResp[1], cachedResp[0], copy(cachedResp[2])); + } else { + resolvePromise(cachedResp, 200, {}); + } + } + } else { + // put the promise for the non-transformed response into cache as a placeholder + cache.put(url, promise); + } + } + + // if we won't have the response in cache, send the request to the backend + if (!cachedResp) { + $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, + config.withCredentials); + } + + return promise; + + + /** + * Callback registered to $httpBackend(): + * - caches the response if desired + * - resolves the raw $http promise + * - calls $apply + */ + function done(status, response, headersString) { + if (cache) { + if (isSuccess(status)) { + cache.put(url, [status, response, parseHeaders(headersString)]); + } else { + // remove promise from the cache + cache.remove(url); + } + } + + resolvePromise(response, status, headersString); + $rootScope.$apply(); + } + + + /** + * Resolves the raw $http promise. + */ + function resolvePromise(response, status, headers) { + // normalize internal statuses to 0 + status = Math.max(status, 0); + + (isSuccess(status) ? deferred.resolve : deferred.reject)({ + data: response, + status: status, + headers: headersGetter(headers), + config: config + }); + } + + + function removePendingReq() { + var idx = indexOf($http.pendingRequests, config); + if (idx !== -1) $http.pendingRequests.splice(idx, 1); + } + } + + + function buildUrl(url, params) { + if (!params) return url; + var parts = []; + forEachSorted(params, function(value, key) { + if (value == null || value == undefined) return; + if (isObject(value)) { + value = toJson(value); + } + parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); + }); + return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&'); + } + + + }]; +} +var XHR = window.XMLHttpRequest || function() { + try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e1) {} + try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e2) {} + try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e3) {} + throw new Error("This browser does not support XMLHttpRequest."); +}; + + +/** + * @ngdoc object + * @name ng.$httpBackend + * @requires $browser + * @requires $window + * @requires $document + * + * @description + * HTTP backend used by the {@link ng.$http service} that delegates to + * XMLHttpRequest object or JSONP and deals with browser incompatibilities. + * + * You should never need to use this service directly, instead use the higher-level abstractions: + * {@link ng.$http $http} or {@link ngResource.$resource $resource}. + * + * During testing this implementation is swapped with {@link ngMock.$httpBackend mock + * $httpBackend} which can be trained with responses. + */ +function $HttpBackendProvider() { + this.$get = ['$browser', '$window', '$document', function($browser, $window, $document) { + return createHttpBackend($browser, XHR, $browser.defer, $window.angular.callbacks, + $document[0], $window.location.protocol.replace(':', '')); + }]; +} + +function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, locationProtocol) { + // TODO(vojta): fix the signature + return function(method, url, post, callback, headers, timeout, withCredentials) { + $browser.$$incOutstandingRequestCount(); + url = url || $browser.url(); + + if (lowercase(method) == 'jsonp') { + var callbackId = '_' + (callbacks.counter++).toString(36); + callbacks[callbackId] = function(data) { + callbacks[callbackId].data = data; + }; + + jsonpReq(url.replace('JSON_CALLBACK', 'angular.callbacks.' + callbackId), + function() { + if (callbacks[callbackId].data) { + completeRequest(callback, 200, callbacks[callbackId].data); + } else { + completeRequest(callback, -2); + } + delete callbacks[callbackId]; + }); + } else { + var xhr = new XHR(); + xhr.open(method, url, true); + forEach(headers, function(value, key) { + if (value) xhr.setRequestHeader(key, value); + }); + + var status; + + // In IE6 and 7, this might be called synchronously when xhr.send below is called and the + // response is in the cache. the promise api will ensure that to the app code the api is + // always async + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + completeRequest( + callback, status || xhr.status, xhr.responseText, xhr.getAllResponseHeaders()); + } + }; + + if (withCredentials) { + xhr.withCredentials = true; + } + + xhr.send(post || ''); + + if (timeout > 0) { + $browserDefer(function() { + status = -1; + xhr.abort(); + }, timeout); + } + } + + + function completeRequest(callback, status, response, headersString) { + // URL_MATCH is defined in src/service/location.js + var protocol = (url.match(URL_MATCH) || ['', locationProtocol])[1]; + + // fix status code for file protocol (it's always 0) + status = (protocol == 'file') ? (response ? 200 : 404) : status; + + // normalize IE bug (http://bugs.jquery.com/ticket/1450) + status = status == 1223 ? 204 : status; + + callback(status, response, headersString); + $browser.$$completeOutstandingRequest(noop); + } + }; + + function jsonpReq(url, done) { + // we can't use jQuery/jqLite here because jQuery does crazy shit with script elements, e.g.: + // - fetches local scripts via XHR and evals them + // - adds and immediately removes script elements from the document + var script = rawDocument.createElement('script'), + doneWrapper = function() { + rawDocument.body.removeChild(script); + if (done) done(); + }; + + script.type = 'text/javascript'; + script.src = url; + + if (msie) { + script.onreadystatechange = function() { + if (/loaded|complete/.test(script.readyState)) doneWrapper(); + }; + } else { + script.onload = script.onerror = doneWrapper; + } + + rawDocument.body.appendChild(script); + } +} + +/** + * @ngdoc object + * @name ng.$locale + * + * @description + * $locale service provides localization rules for various Angular components. As of right now the + * only public api is: + * + * * `id` – `{string}` – locale id formatted as `languageId-countryId` (e.g. `en-us`) + */ +function $LocaleProvider(){ + this.$get = function() { + return { + id: 'en-us', + + NUMBER_FORMATS: { + DECIMAL_SEP: '.', + GROUP_SEP: ',', + PATTERNS: [ + { // Decimal Pattern + minInt: 1, + minFrac: 0, + maxFrac: 3, + posPre: '', + posSuf: '', + negPre: '-', + negSuf: '', + gSize: 3, + lgSize: 3 + },{ //Currency Pattern + minInt: 1, + minFrac: 2, + maxFrac: 2, + posPre: '\u00A4', + posSuf: '', + negPre: '(\u00A4', + negSuf: ')', + gSize: 3, + lgSize: 3 + } + ], + CURRENCY_SYM: '$' + }, + + DATETIME_FORMATS: { + MONTH: 'January,February,March,April,May,June,July,August,September,October,November,December' + .split(','), + SHORTMONTH: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(','), + DAY: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','), + SHORTDAY: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(','), + AMPMS: ['AM','PM'], + medium: 'MMM d, y h:mm:ss a', + short: 'M/d/yy h:mm a', + fullDate: 'EEEE, MMMM d, y', + longDate: 'MMMM d, y', + mediumDate: 'MMM d, y', + shortDate: 'M/d/yy', + mediumTime: 'h:mm:ss a', + shortTime: 'h:mm a' + }, + + pluralCat: function(num) { + if (num === 1) { + return 'one'; + } + return 'other'; + } + }; + }; +} + +function $TimeoutProvider() { + this.$get = ['$rootScope', '$browser', '$q', '$exceptionHandler', + function($rootScope, $browser, $q, $exceptionHandler) { + var deferreds = {}; + + + /** + * @ngdoc function + * @name ng.$timeout + * @requires $browser + * + * @description + * Angular's wrapper for `window.setTimeout`. The `fn` function is wrapped into a try/catch + * block and delegates any exceptions to + * {@link ng.$exceptionHandler $exceptionHandler} service. + * + * The return value of registering a timeout function is a promise which will be resolved when + * the timeout is reached and the timeout function is executed. + * + * To cancel a the timeout request, call `$timeout.cancel(promise)`. + * + * In tests you can use {@link ngMock.$timeout `$timeout.flush()`} to + * synchronously flush the queue of deferred functions. + * + * @param {function()} fn A function, who's execution should be delayed. + * @param {number=} [delay=0] Delay in milliseconds. + * @param {boolean=} [invokeApply=true] If set to false skips model dirty checking, otherwise + * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block. + * @returns {*} Promise that will be resolved when the timeout is reached. The value this + * promise will be resolved with is the return value of the `fn` function. + */ + function timeout(fn, delay, invokeApply) { + var deferred = $q.defer(), + promise = deferred.promise, + skipApply = (isDefined(invokeApply) && !invokeApply), + timeoutId, cleanup; + + timeoutId = $browser.defer(function() { + try { + deferred.resolve(fn()); + } catch(e) { + deferred.reject(e); + $exceptionHandler(e); + } + + if (!skipApply) $rootScope.$apply(); + }, delay); + + cleanup = function() { + delete deferreds[promise.$$timeoutId]; + }; + + promise.$$timeoutId = timeoutId; + deferreds[timeoutId] = deferred; + promise.then(cleanup, cleanup); + + return promise; + } + + + /** + * @ngdoc function + * @name ng.$timeout#cancel + * @methodOf ng.$timeout + * + * @description + * Cancels a task associated with the `promise`. As a result of this the promise will be + * resolved with a rejection. + * + * @param {Promise=} promise Promise returned by the `$timeout` function. + * @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully + * canceled. + */ + timeout.cancel = function(promise) { + if (promise && promise.$$timeoutId in deferreds) { + deferreds[promise.$$timeoutId].reject('canceled'); + return $browser.defer.cancel(promise.$$timeoutId); + } + return false; + }; + + return timeout; + }]; +} + +/** + * @ngdoc object + * @name ng.$filterProvider + * @description + * + * Filters are just functions which transform input to an output. However filters need to be Dependency Injected. To + * achieve this a filter definition consists of a factory function which is annotated with dependencies and is + * responsible for creating a the filter function. + * + *
+ *   // Filter registration
+ *   function MyModule($provide, $filterProvider) {
+ *     // create a service to demonstrate injection (not always needed)
+ *     $provide.value('greet', function(name){
+ *       return 'Hello ' + name + '!';
+ *     });
+ *
+ *     // register a filter factory which uses the
+ *     // greet service to demonstrate DI.
+ *     $filterProvider.register('greet', function(greet){
+ *       // return the filter function which uses the greet service
+ *       // to generate salutation
+ *       return function(text) {
+ *         // filters need to be forgiving so check input validity
+ *         return text && greet(text) || text;
+ *       };
+ *     });
+ *   }
+ * 
+ * + * The filter function is registered with the `$injector` under the filter name suffixe with `Filter`. + *
+ *   it('should be the same instance', inject(
+ *     function($filterProvider) {
+ *       $filterProvider.register('reverse', function(){
+ *         return ...;
+ *       });
+ *     },
+ *     function($filter, reverseFilter) {
+ *       expect($filter('reverse')).toBe(reverseFilter);
+ *     });
+ * 
+ * + * + * For more information about how angular filters work, and how to create your own filters, see + * {@link guide/dev_guide.templates.filters Understanding Angular Filters} in the angular Developer + * Guide. + */ +/** + * @ngdoc method + * @name ng.$filterProvider#register + * @methodOf ng.$filterProvider + * @description + * Register filter factory function. + * + * @param {String} name Name of the filter. + * @param {function} fn The filter factory function which is injectable. + */ + + +/** + * @ngdoc function + * @name ng.$filter + * @function + * @description + * Filters are used for formatting data displayed to the user. + * + * The general syntax in templates is as follows: + * + * {{ expression | [ filter_name ] }} + * + * @param {String} name Name of the filter function to retrieve + * @return {Function} the filter function + */ +$FilterProvider.$inject = ['$provide']; +function $FilterProvider($provide) { + var suffix = 'Filter'; + + function register(name, factory) { + return $provide.factory(name + suffix, factory); + } + this.register = register; + + this.$get = ['$injector', function($injector) { + return function(name) { + return $injector.get(name + suffix); + } + }]; + + //////////////////////////////////////// + + register('currency', currencyFilter); + register('date', dateFilter); + register('filter', filterFilter); + register('json', jsonFilter); + register('limitTo', limitToFilter); + register('lowercase', lowercaseFilter); + register('number', numberFilter); + register('orderBy', orderByFilter); + register('uppercase', uppercaseFilter); +} + +/** + * @ngdoc filter + * @name ng.filter:filter + * @function + * + * @description + * Selects a subset of items from `array` and returns it as a new array. + * + * Note: This function is used to augment the `Array` type in Angular expressions. See + * {@link ng.$filter} for more information about Angular arrays. + * + * @param {Array} array The source array. + * @param {string|Object|function()} expression The predicate to be used for selecting items from + * `array`. + * + * Can be one of: + * + * - `string`: Predicate that results in a substring match using the value of `expression` + * string. All strings or objects with string properties in `array` that contain this string + * will be returned. The predicate can be negated by prefixing the string with `!`. + * + * - `Object`: A pattern object can be used to filter specific properties on objects contained + * by `array`. For example `{name:"M", phone:"1"}` predicate will return an array of items + * which have property `name` containing "M" and property `phone` containing "1". A special + * property name `$` can be used (as in `{$:"text"}`) to accept a match against any + * property of the object. That's equivalent to the simple substring match with a `string` + * as described above. + * + * - `function`: A predicate function can be used to write arbitrary filters. The function is + * called for each element of `array`. The final result is an array of those elements that + * the predicate returned true for. + * + * @example + + +
+ + Search: + + + + + + +
NamePhone
{{friend.name}}{{friend.phone}}
+
+ Any:
+ Name only
+ Phone only
+ + + + + + +
NamePhone
{{friend.name}}{{friend.phone}}
+
+ + it('should search across all fields when filtering with a string', function() { + input('searchText').enter('m'); + expect(repeater('#searchTextResults tr', 'friend in friends').column('friend.name')). + toEqual(['Mary', 'Mike', 'Adam']); + + input('searchText').enter('76'); + expect(repeater('#searchTextResults tr', 'friend in friends').column('friend.name')). + toEqual(['John', 'Julie']); + }); + + it('should search in specific fields when filtering with a predicate object', function() { + input('search.$').enter('i'); + expect(repeater('#searchObjResults tr', 'friend in friends').column('friend.name')). + toEqual(['Mary', 'Mike', 'Julie']); + }); + +
+ */ +function filterFilter() { + return function(array, expression) { + if (!(array instanceof Array)) return array; + var predicates = []; + predicates.check = function(value) { + for (var j = 0; j < predicates.length; j++) { + if(!predicates[j](value)) { + return false; + } + } + return true; + }; + var search = function(obj, text){ + if (text.charAt(0) === '!') { + return !search(obj, text.substr(1)); + } + switch (typeof obj) { + case "boolean": + case "number": + case "string": + return ('' + obj).toLowerCase().indexOf(text) > -1; + case "object": + for ( var objKey in obj) { + if (objKey.charAt(0) !== '$' && search(obj[objKey], text)) { + return true; + } + } + return false; + case "array": + for ( var i = 0; i < obj.length; i++) { + if (search(obj[i], text)) { + return true; + } + } + return false; + default: + return false; + } + }; + switch (typeof expression) { + case "boolean": + case "number": + case "string": + expression = {$:expression}; + case "object": + for (var key in expression) { + if (key == '$') { + (function() { + var text = (''+expression[key]).toLowerCase(); + if (!text) return; + predicates.push(function(value) { + return search(value, text); + }); + })(); + } else { + (function() { + var path = key; + var text = (''+expression[key]).toLowerCase(); + if (!text) return; + predicates.push(function(value) { + return search(getter(value, path), text); + }); + })(); + } + } + break; + case 'function': + predicates.push(expression); + break; + default: + return array; + } + var filtered = []; + for ( var j = 0; j < array.length; j++) { + var value = array[j]; + if (predicates.check(value)) { + filtered.push(value); + } + } + return filtered; + } +} + +/** + * @ngdoc filter + * @name ng.filter:currency + * @function + * + * @description + * Formats a number as a currency (ie $1,234.56). When no currency symbol is provided, default + * symbol for current locale is used. + * + * @param {number} amount Input to filter. + * @param {string=} symbol Currency symbol or identifier to be displayed. + * @returns {string} Formatted number. + * + * + * @example + + + +
+
+ default currency symbol ($): {{amount | currency}}
+ custom currency identifier (USD$): {{amount | currency:"USD$"}} +
+
+ + it('should init with 1234.56', function() { + expect(binding('amount | currency')).toBe('$1,234.56'); + expect(binding('amount | currency:"USD$"')).toBe('USD$1,234.56'); + }); + it('should update', function() { + input('amount').enter('-1234'); + expect(binding('amount | currency')).toBe('($1,234.00)'); + expect(binding('amount | currency:"USD$"')).toBe('(USD$1,234.00)'); + }); + +
+ */ +currencyFilter.$inject = ['$locale']; +function currencyFilter($locale) { + var formats = $locale.NUMBER_FORMATS; + return function(amount, currencySymbol){ + if (isUndefined(currencySymbol)) currencySymbol = formats.CURRENCY_SYM; + return formatNumber(amount, formats.PATTERNS[1], formats.GROUP_SEP, formats.DECIMAL_SEP, 2). + replace(/\u00A4/g, currencySymbol); + }; +} + +/** + * @ngdoc filter + * @name ng.filter:number + * @function + * + * @description + * Formats a number as text. + * + * If the input is not a number an empty string is returned. + * + * @param {number|string} number Number to format. + * @param {(number|string)=} [fractionSize=2] Number of decimal places to round the number to. + * @returns {string} Number rounded to decimalPlaces and places a “,” after each third digit. + * + * @example + + + +
+ Enter number:
+ Default formatting: {{val | number}}
+ No fractions: {{val | number:0}}
+ Negative number: {{-val | number:4}} +
+
+ + it('should format numbers', function() { + expect(binding('val | number')).toBe('1,234.568'); + expect(binding('val | number:0')).toBe('1,235'); + expect(binding('-val | number:4')).toBe('-1,234.5679'); + }); + + it('should update', function() { + input('val').enter('3374.333'); + expect(binding('val | number')).toBe('3,374.333'); + expect(binding('val | number:0')).toBe('3,374'); + expect(binding('-val | number:4')).toBe('-3,374.3330'); + }); + +
+ */ + + +numberFilter.$inject = ['$locale']; +function numberFilter($locale) { + var formats = $locale.NUMBER_FORMATS; + return function(number, fractionSize) { + return formatNumber(number, formats.PATTERNS[0], formats.GROUP_SEP, formats.DECIMAL_SEP, + fractionSize); + }; +} + +var DECIMAL_SEP = '.'; +function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) { + if (isNaN(number) || !isFinite(number)) return ''; + + var isNegative = number < 0; + number = Math.abs(number); + var numStr = number + '', + formatedText = '', + parts = []; + + if (numStr.indexOf('e') !== -1) { + formatedText = numStr; + } else { + var fractionLen = (numStr.split(DECIMAL_SEP)[1] || '').length; + + // determine fractionSize if it is not specified + if (isUndefined(fractionSize)) { + fractionSize = Math.min(Math.max(pattern.minFrac, fractionLen), pattern.maxFrac); + } + + var pow = Math.pow(10, fractionSize); + number = Math.round(number * pow) / pow; + var fraction = ('' + number).split(DECIMAL_SEP); + var whole = fraction[0]; + fraction = fraction[1] || ''; + + var pos = 0, + lgroup = pattern.lgSize, + group = pattern.gSize; + + if (whole.length >= (lgroup + group)) { + pos = whole.length - lgroup; + for (var i = 0; i < pos; i++) { + if ((pos - i)%group === 0 && i !== 0) { + formatedText += groupSep; + } + formatedText += whole.charAt(i); + } + } + + for (i = pos; i < whole.length; i++) { + if ((whole.length - i)%lgroup === 0 && i !== 0) { + formatedText += groupSep; + } + formatedText += whole.charAt(i); + } + + // format fraction part. + while(fraction.length < fractionSize) { + fraction += '0'; + } + + if (fractionSize) formatedText += decimalSep + fraction.substr(0, fractionSize); + } + + parts.push(isNegative ? pattern.negPre : pattern.posPre); + parts.push(formatedText); + parts.push(isNegative ? pattern.negSuf : pattern.posSuf); + return parts.join(''); +} + +function padNumber(num, digits, trim) { + var neg = ''; + if (num < 0) { + neg = '-'; + num = -num; + } + num = '' + num; + while(num.length < digits) num = '0' + num; + if (trim) + num = num.substr(num.length - digits); + return neg + num; +} + + +function dateGetter(name, size, offset, trim) { + return function(date) { + var value = date['get' + name](); + if (offset > 0 || value > -offset) + value += offset; + if (value === 0 && offset == -12 ) value = 12; + return padNumber(value, size, trim); + }; +} + +function dateStrGetter(name, shortForm) { + return function(date, formats) { + var value = date['get' + name](); + var get = uppercase(shortForm ? ('SHORT' + name) : name); + + return formats[get][value]; + }; +} + +function timeZoneGetter(date) { + var offset = date.getTimezoneOffset(); + return padNumber(offset / 60, 2) + padNumber(Math.abs(offset % 60), 2); +} + +function ampmGetter(date, formats) { + return date.getHours() < 12 ? formats.AMPMS[0] : formats.AMPMS[1]; +} + +var DATE_FORMATS = { + yyyy: dateGetter('FullYear', 4), + yy: dateGetter('FullYear', 2, 0, true), + y: dateGetter('FullYear', 1), + MMMM: dateStrGetter('Month'), + MMM: dateStrGetter('Month', true), + MM: dateGetter('Month', 2, 1), + M: dateGetter('Month', 1, 1), + dd: dateGetter('Date', 2), + d: dateGetter('Date', 1), + HH: dateGetter('Hours', 2), + H: dateGetter('Hours', 1), + hh: dateGetter('Hours', 2, -12), + h: dateGetter('Hours', 1, -12), + mm: dateGetter('Minutes', 2), + m: dateGetter('Minutes', 1), + ss: dateGetter('Seconds', 2), + s: dateGetter('Seconds', 1), + EEEE: dateStrGetter('Day'), + EEE: dateStrGetter('Day', true), + a: ampmGetter, + Z: timeZoneGetter +}; + +var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/, + NUMBER_STRING = /^\d+$/; + +/** + * @ngdoc filter + * @name ng.filter:date + * @function + * + * @description + * Formats `date` to a string based on the requested `format`. + * + * `format` string can be composed of the following elements: + * + * * `'yyyy'`: 4 digit representation of year (e.g. AD 1 => 0001, AD 2010 => 2010) + * * `'yy'`: 2 digit representation of year, padded (00-99). (e.g. AD 2001 => 01, AD 2010 => 10) + * * `'y'`: 1 digit representation of year, e.g. (AD 1 => 1, AD 199 => 199) + * * `'MMMM'`: Month in year (January-December) + * * `'MMM'`: Month in year (Jan-Dec) + * * `'MM'`: Month in year, padded (01-12) + * * `'M'`: Month in year (1-12) + * * `'dd'`: Day in month, padded (01-31) + * * `'d'`: Day in month (1-31) + * * `'EEEE'`: Day in Week,(Sunday-Saturday) + * * `'EEE'`: Day in Week, (Sun-Sat) + * * `'HH'`: Hour in day, padded (00-23) + * * `'H'`: Hour in day (0-23) + * * `'hh'`: Hour in am/pm, padded (01-12) + * * `'h'`: Hour in am/pm, (1-12) + * * `'mm'`: Minute in hour, padded (00-59) + * * `'m'`: Minute in hour (0-59) + * * `'ss'`: Second in minute, padded (00-59) + * * `'s'`: Second in minute (0-59) + * * `'a'`: am/pm marker + * * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-1200) + * + * `format` string can also be one of the following predefined + * {@link guide/i18n localizable formats}: + * + * * `'medium'`: equivalent to `'MMM d, y h:mm:ss a'` for en_US locale + * (e.g. Sep 3, 2010 12:05:08 pm) + * * `'short'`: equivalent to `'M/d/yy h:mm a'` for en_US locale (e.g. 9/3/10 12:05 pm) + * * `'fullDate'`: equivalent to `'EEEE, MMMM d,y'` for en_US locale + * (e.g. Friday, September 3, 2010) + * * `'longDate'`: equivalent to `'MMMM d, y'` for en_US locale (e.g. September 3, 2010 + * * `'mediumDate'`: equivalent to `'MMM d, y'` for en_US locale (e.g. Sep 3, 2010) + * * `'shortDate'`: equivalent to `'M/d/yy'` for en_US locale (e.g. 9/3/10) + * * `'mediumTime'`: equivalent to `'h:mm:ss a'` for en_US locale (e.g. 12:05:08 pm) + * * `'shortTime'`: equivalent to `'h:mm a'` for en_US locale (e.g. 12:05 pm) + * + * `format` string can contain literal values. These need to be quoted with single quotes (e.g. + * `"h 'in the morning'"`). In order to output single quote, use two single quotes in a sequence + * (e.g. `"h o''clock"`). + * + * @param {(Date|number|string)} date Date to format either as Date object, milliseconds (string or + * number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.SSSZ and it's + * shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). + * @param {string=} format Formatting rules (see Description). If not specified, + * `mediumDate` is used. + * @returns {string} Formatted string or the input if input is not recognized as date/millis. + * + * @example + + + {{1288323623006 | date:'medium'}}: + {{1288323623006 | date:'medium'}}
+ {{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}: + {{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}
+ {{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}: + {{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}
+
+ + it('should format date', function() { + expect(binding("1288323623006 | date:'medium'")). + toMatch(/Oct 2\d, 2010 \d{1,2}:\d{2}:\d{2} (AM|PM)/); + expect(binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")). + toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} \-?\d{4}/); + expect(binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")). + toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(AM|PM)/); + }); + +
+ */ +dateFilter.$inject = ['$locale']; +function dateFilter($locale) { + + + var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/; + function jsonStringToDate(string){ + var match; + if (match = string.match(R_ISO8601_STR)) { + var date = new Date(0), + tzHour = 0, + tzMin = 0; + if (match[9]) { + tzHour = int(match[9] + match[10]); + tzMin = int(match[9] + match[11]); + } + date.setUTCFullYear(int(match[1]), int(match[2]) - 1, int(match[3])); + date.setUTCHours(int(match[4]||0) - tzHour, int(match[5]||0) - tzMin, int(match[6]||0), int(match[7]||0)); + return date; + } + return string; + } + + + return function(date, format) { + var text = '', + parts = [], + fn, match; + + format = format || 'mediumDate'; + format = $locale.DATETIME_FORMATS[format] || format; + if (isString(date)) { + if (NUMBER_STRING.test(date)) { + date = int(date); + } else { + date = jsonStringToDate(date); + } + } + + if (isNumber(date)) { + date = new Date(date); + } + + if (!isDate(date)) { + return date; + } + + while(format) { + match = DATE_FORMATS_SPLIT.exec(format); + if (match) { + parts = concat(parts, match, 1); + format = parts.pop(); + } else { + parts.push(format); + format = null; + } + } + + forEach(parts, function(value){ + fn = DATE_FORMATS[value]; + text += fn ? fn(date, $locale.DATETIME_FORMATS) + : value.replace(/(^'|'$)/g, '').replace(/''/g, "'"); + }); + + return text; + }; +} + + +/** + * @ngdoc filter + * @name ng.filter:json + * @function + * + * @description + * Allows you to convert a JavaScript object into JSON string. + * + * This filter is mostly useful for debugging. When using the double curly {{value}} notation + * the binding is automatically converted to JSON. + * + * @param {*} object Any JavaScript object (including arrays and primitive types) to filter. + * @returns {string} JSON string. + * + * + * @example: + + +
{{ {'name':'value'} | json }}
+
+ + it('should jsonify filtered objects', function() { + expect(binding("{'name':'value'}")).toMatch(/\{\n "name": ?"value"\n}/); + }); + +
+ * + */ +function jsonFilter() { + return function(object) { + return toJson(object, true); + }; +} + + +/** + * @ngdoc filter + * @name ng.filter:lowercase + * @function + * @description + * Converts string to lowercase. + * @see angular.lowercase + */ +var lowercaseFilter = valueFn(lowercase); + + +/** + * @ngdoc filter + * @name ng.filter:uppercase + * @function + * @description + * Converts string to uppercase. + * @see angular.uppercase + */ +var uppercaseFilter = valueFn(uppercase); + +/** + * @ngdoc function + * @name ng.filter:limitTo + * @function + * + * @description + * Creates a new array containing only a specified number of elements in an array. The elements + * are taken from either the beginning or the end of the source array, as specified by the + * value and sign (positive or negative) of `limit`. + * + * Note: This function is used to augment the `Array` type in Angular expressions. See + * {@link ng.$filter} for more information about Angular arrays. + * + * @param {Array} array Source array to be limited. + * @param {string|Number} limit The length of the returned array. If the `limit` number is + * positive, `limit` number of items from the beginning of the source array are copied. + * If the number is negative, `limit` number of items from the end of the source array are + * copied. The `limit` will be trimmed if it exceeds `array.length` + * @returns {Array} A new sub-array of length `limit` or less if input array had less than `limit` + * elements. + * + * @example + + + +
+ Limit {{numbers}} to: +

Output: {{ numbers | limitTo:limit }}

+
+
+ + it('should limit the numer array to first three items', function() { + expect(element('.doc-example-live input[ng-model=limit]').val()).toBe('3'); + expect(binding('numbers | limitTo:limit')).toEqual('[1,2,3]'); + }); + + it('should update the output when -3 is entered', function() { + input('limit').enter(-3); + expect(binding('numbers | limitTo:limit')).toEqual('[7,8,9]'); + }); + + it('should not exceed the maximum size of input array', function() { + input('limit').enter(100); + expect(binding('numbers | limitTo:limit')).toEqual('[1,2,3,4,5,6,7,8,9]'); + }); + +
+ */ +function limitToFilter(){ + return function(array, limit) { + if (!(array instanceof Array)) return array; + limit = int(limit); + var out = [], + i, n; + + // check that array is iterable + if (!array || !(array instanceof Array)) + return out; + + // if abs(limit) exceeds maximum length, trim it + if (limit > array.length) + limit = array.length; + else if (limit < -array.length) + limit = -array.length; + + if (limit > 0) { + i = 0; + n = limit; + } else { + i = array.length + limit; + n = array.length; + } + + for (; i} expression A predicate to be + * used by the comparator to determine the order of elements. + * + * Can be one of: + * + * - `function`: Getter function. The result of this function will be sorted using the + * `<`, `=`, `>` operator. + * - `string`: An Angular expression which evaluates to an object to order by, such as 'name' + * to sort by a property called 'name'. Optionally prefixed with `+` or `-` to control + * ascending or descending sort order (for example, +name or -name). + * - `Array`: An array of function or string predicates. The first predicate in the array + * is used for sorting, but when two items are equivalent, the next predicate is used. + * + * @param {boolean=} reverse Reverse the order the array. + * @returns {Array} Sorted copy of the source array. + * + * @example + + + +
+
Sorting predicate = {{predicate}}; reverse = {{reverse}}
+
+ [ unsorted ] + + + + + + + + + + + +
Name + (^)Phone NumberAge
{{friend.name}}{{friend.phone}}{{friend.age}}
+
+
+ + it('should be reverse ordered by aged', function() { + expect(binding('predicate')).toBe('-age'); + expect(repeater('table.friend', 'friend in friends').column('friend.age')). + toEqual(['35', '29', '21', '19', '10']); + expect(repeater('table.friend', 'friend in friends').column('friend.name')). + toEqual(['Adam', 'Julie', 'Mike', 'Mary', 'John']); + }); + + it('should reorder the table when user selects different predicate', function() { + element('.doc-example-live a:contains("Name")').click(); + expect(repeater('table.friend', 'friend in friends').column('friend.name')). + toEqual(['Adam', 'John', 'Julie', 'Mary', 'Mike']); + expect(repeater('table.friend', 'friend in friends').column('friend.age')). + toEqual(['35', '10', '29', '19', '21']); + + element('.doc-example-live a:contains("Phone")').click(); + expect(repeater('table.friend', 'friend in friends').column('friend.phone')). + toEqual(['555-9876', '555-8765', '555-5678', '555-4321', '555-1212']); + expect(repeater('table.friend', 'friend in friends').column('friend.name')). + toEqual(['Mary', 'Julie', 'Adam', 'Mike', 'John']); + }); + +
+ */ +orderByFilter.$inject = ['$parse']; +function orderByFilter($parse){ + return function(array, sortPredicate, reverseOrder) { + if (!(array instanceof Array)) return array; + if (!sortPredicate) return array; + sortPredicate = isArray(sortPredicate) ? sortPredicate: [sortPredicate]; + sortPredicate = map(sortPredicate, function(predicate){ + var descending = false, get = predicate || identity; + if (isString(predicate)) { + if ((predicate.charAt(0) == '+' || predicate.charAt(0) == '-')) { + descending = predicate.charAt(0) == '-'; + predicate = predicate.substring(1); + } + get = $parse(predicate); + } + return reverseComparator(function(a,b){ + return compare(get(a),get(b)); + }, descending); + }); + var arrayCopy = []; + for ( var i = 0; i < array.length; i++) { arrayCopy.push(array[i]); } + return arrayCopy.sort(reverseComparator(comparator, reverseOrder)); + + function comparator(o1, o2){ + for ( var i = 0; i < sortPredicate.length; i++) { + var comp = sortPredicate[i](o1, o2); + if (comp !== 0) return comp; + } + return 0; + } + function reverseComparator(comp, descending) { + return toBoolean(descending) + ? function(a,b){return comp(b,a);} + : comp; + } + function compare(v1, v2){ + var t1 = typeof v1; + var t2 = typeof v2; + if (t1 == t2) { + if (t1 == "string") v1 = v1.toLowerCase(); + if (t1 == "string") v2 = v2.toLowerCase(); + if (v1 === v2) return 0; + return v1 < v2 ? -1 : 1; + } else { + return t1 < t2 ? -1 : 1; + } + } + } +} + +function ngDirective(directive) { + if (isFunction(directive)) { + directive = { + link: directive + } + } + directive.restrict = directive.restrict || 'AC'; + return valueFn(directive); +} + +/** + * @ngdoc directive + * @name ng.directive:a + * @restrict E + * + * @description + * Modifies the default behavior of html A tag, so that the default action is prevented when href + * attribute is empty. + * + * The reasoning for this change is to allow easy creation of action links with `ngClick` directive + * without changing the location or causing page reloads, e.g.: + * Save + */ +var htmlAnchorDirective = valueFn({ + restrict: 'E', + compile: function(element, attr) { + // turn link into a link in IE + // but only if it doesn't have name attribute, in which case it's an anchor + if (!attr.href) { + attr.$set('href', ''); + } + + return function(scope, element) { + element.bind('click', function(event){ + // if we have no href url, then don't navigate anywhere. + if (!element.attr('href')) { + event.preventDefault(); + } + }); + } + } +}); + +/** + * @ngdoc directive + * @name ng.directive:ngHref + * @restrict A + * + * @description + * Using Angular markup like {{hash}} in an href attribute makes + * the page open to a wrong URL, if the user clicks that link before + * angular has a chance to replace the {{hash}} with actual URL, the + * link will be broken and will most likely return a 404 error. + * The `ngHref` directive solves this problem. + * + * The buggy way to write it: + *
+ * 
+ * 
+ * + * The correct way to write it: + *
+ * 
+ * 
+ * + * @element A + * @param {template} ngHref any string which can contain `{{}}` markup. + * + * @example + * This example uses `link` variable inside `href` attribute: + + +
+
link 1 (link, don't reload)
+ link 2 (link, don't reload)
+ link 3 (link, reload!)
+ anchor (link, don't reload)
+ anchor (no link)
+ link (link, change location) + + + it('should execute ng-click but not reload when href without value', function() { + element('#link-1').click(); + expect(input('value').val()).toEqual('1'); + expect(element('#link-1').attr('href')).toBe(""); + }); + + it('should execute ng-click but not reload when href empty string', function() { + element('#link-2').click(); + expect(input('value').val()).toEqual('2'); + expect(element('#link-2').attr('href')).toBe(""); + }); + + it('should execute ng-click and change url when ng-href specified', function() { + expect(element('#link-3').attr('href')).toBe("/123"); + + element('#link-3').click(); + expect(browser().window().path()).toEqual('/123'); + }); + + it('should execute ng-click but not reload when href empty string and name specified', function() { + element('#link-4').click(); + expect(input('value').val()).toEqual('4'); + expect(element('#link-4').attr('href')).toBe(''); + }); + + it('should execute ng-click but not reload when no href but name specified', function() { + element('#link-5').click(); + expect(input('value').val()).toEqual('5'); + expect(element('#link-5').attr('href')).toBe(''); + }); + + it('should only change url when only ng-href', function() { + input('value').enter('6'); + expect(element('#link-6').attr('href')).toBe('6'); + + element('#link-6').click(); + expect(browser().location().url()).toEqual('/6'); + }); + + + */ + +/** + * @ngdoc directive + * @name ng.directive:ngSrc + * @restrict A + * + * @description + * Using Angular markup like `{{hash}}` in a `src` attribute doesn't + * work right: The browser will fetch from the URL with the literal + * text `{{hash}}` until Angular replaces the expression inside + * `{{hash}}`. The `ngSrc` directive solves this problem. + * + * The buggy way to write it: + *
+ * 
+ * 
+ * + * The correct way to write it: + *
+ * 
+ * 
+ * + * @element IMG + * @param {template} ngSrc any string which can contain `{{}}` markup. + */ + +/** + * @ngdoc directive + * @name ng.directive:ngDisabled + * @restrict A + * + * @description + * + * The following markup will make the button enabled on Chrome/Firefox but not on IE8 and older IEs: + *
+ * 
+ * + *
+ *
+ * + * The HTML specs do not require browsers to preserve the special attributes such as disabled. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce the `ngDisabled` directive. + * + * @example + + + Click me to toggle:
+ +
+ + it('should toggle button', function() { + expect(element('.doc-example-live :button').prop('disabled')).toBeFalsy(); + input('checked').check(); + expect(element('.doc-example-live :button').prop('disabled')).toBeTruthy(); + }); + +
+ * + * @element INPUT + * @param {expression} ngDisabled Angular expression that will be evaluated. + */ + + +/** + * @ngdoc directive + * @name ng.directive:ngChecked + * @restrict A + * + * @description + * The HTML specs do not require browsers to preserve the special attributes such as checked. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce the `ngChecked` directive. + * @example + + + Check me to check both:
+ +
+ + it('should check both checkBoxes', function() { + expect(element('.doc-example-live #checkSlave').prop('checked')).toBeFalsy(); + input('master').check(); + expect(element('.doc-example-live #checkSlave').prop('checked')).toBeTruthy(); + }); + +
+ * + * @element INPUT + * @param {expression} ngChecked Angular expression that will be evaluated. + */ + + +/** + * @ngdoc directive + * @name ng.directive:ngMultiple + * @restrict A + * + * @description + * The HTML specs do not require browsers to preserve the special attributes such as multiple. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce the `ngMultiple` directive. + * + * @example + + + Check me check multiple:
+ +
+ + it('should toggle multiple', function() { + expect(element('.doc-example-live #select').prop('multiple')).toBeFalsy(); + input('checked').check(); + expect(element('.doc-example-live #select').prop('multiple')).toBeTruthy(); + }); + +
+ * + * @element SELECT + * @param {expression} ngMultiple Angular expression that will be evaluated. + */ + + +/** + * @ngdoc directive + * @name ng.directive:ngReadonly + * @restrict A + * + * @description + * The HTML specs do not require browsers to preserve the special attributes such as readonly. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce the `ngReadonly` directive. + * @example + + + Check me to make text readonly:
+ +
+ + it('should toggle readonly attr', function() { + expect(element('.doc-example-live :text').prop('readonly')).toBeFalsy(); + input('checked').check(); + expect(element('.doc-example-live :text').prop('readonly')).toBeTruthy(); + }); + +
+ * + * @element INPUT + * @param {string} expression Angular expression that will be evaluated. + */ + + +/** + * @ngdoc directive + * @name ng.directive:ngSelected + * @restrict A + * + * @description + * The HTML specs do not require browsers to preserve the special attributes such as selected. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduced the `ngSelected` directive. + * @example + + + Check me to select:
+ +
+ + it('should select Greetings!', function() { + expect(element('.doc-example-live #greet').prop('selected')).toBeFalsy(); + input('selected').check(); + expect(element('.doc-example-live #greet').prop('selected')).toBeTruthy(); + }); + +
+ * + * @element OPTION + * @param {string} expression Angular expression that will be evaluated. + */ + + +var ngAttributeAliasDirectives = {}; + + +// boolean attrs are evaluated +forEach(BOOLEAN_ATTR, function(propName, attrName) { + var normalized = directiveNormalize('ng-' + attrName); + ngAttributeAliasDirectives[normalized] = function() { + return { + priority: 100, + compile: function() { + return function(scope, element, attr) { + scope.$watch(attr[normalized], function(value) { + attr.$set(attrName, !!value); + }); + }; + } + }; + }; +}); + + +// ng-src, ng-href are interpolated +forEach(['src', 'href'], function(attrName) { + var normalized = directiveNormalize('ng-' + attrName); + ngAttributeAliasDirectives[normalized] = function() { + return { + priority: 99, // it needs to run after the attributes are interpolated + link: function(scope, element, attr) { + attr.$observe(normalized, function(value) { + attr.$set(attrName, value); + + // on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist + // then calling element.setAttribute('src', 'foo') doesn't do anything, so we need + // to set the property as well to achieve the desired effect + if (msie) element.prop(attrName, value); + }); + } + }; + }; +}); + +var nullFormCtrl = { + $addControl: noop, + $removeControl: noop, + $setValidity: noop, + $setDirty: noop +}; + +/** + * @ngdoc object + * @name ng.directive:form.FormController + * + * @property {boolean} $pristine True if user has not interacted with the form yet. + * @property {boolean} $dirty True if user has already interacted with the form. + * @property {boolean} $valid True if all of the containg forms and controls are valid. + * @property {boolean} $invalid True if at least one containing control or form is invalid. + * + * @property {Object} $error Is an object hash, containing references to all invalid controls or + * forms, where: + * + * - keys are validation tokens (error names) — such as `REQUIRED`, `URL` or `EMAIL`), + * - values are arrays of controls or forms that are invalid with given error. + * + * @description + * `FormController` keeps track of all its controls and nested forms as well as state of them, + * such as being valid/invalid or dirty/pristine. + * + * Each {@link ng.directive:form form} directive creates an instance + * of `FormController`. + * + */ +//asks for $scope to fool the BC controller module +FormController.$inject = ['$element', '$attrs', '$scope']; +function FormController(element, attrs) { + var form = this, + parentForm = element.parent().controller('form') || nullFormCtrl, + invalidCount = 0, // used to easily determine if we are valid + errors = form.$error = {}; + + // init state + form.$name = attrs.name; + form.$dirty = false; + form.$pristine = true; + form.$valid = true; + form.$invalid = false; + + parentForm.$addControl(form); + + // Setup initial state of the control + element.addClass(PRISTINE_CLASS); + toggleValidCss(true); + + // convenience method for easy toggling of classes + function toggleValidCss(isValid, validationErrorKey) { + validationErrorKey = validationErrorKey ? '-' + snake_case(validationErrorKey, '-') : ''; + element. + removeClass((isValid ? INVALID_CLASS : VALID_CLASS) + validationErrorKey). + addClass((isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey); + } + + form.$addControl = function(control) { + if (control.$name && !form.hasOwnProperty(control.$name)) { + form[control.$name] = control; + } + }; + + form.$removeControl = function(control) { + if (control.$name && form[control.$name] === control) { + delete form[control.$name]; + } + forEach(errors, function(queue, validationToken) { + form.$setValidity(validationToken, true, control); + }); + }; + + form.$setValidity = function(validationToken, isValid, control) { + var queue = errors[validationToken]; + + if (isValid) { + if (queue) { + arrayRemove(queue, control); + if (!queue.length) { + invalidCount--; + if (!invalidCount) { + toggleValidCss(isValid); + form.$valid = true; + form.$invalid = false; + } + errors[validationToken] = false; + toggleValidCss(true, validationToken); + parentForm.$setValidity(validationToken, true, form); + } + } + + } else { + if (!invalidCount) { + toggleValidCss(isValid); + } + if (queue) { + if (includes(queue, control)) return; + } else { + errors[validationToken] = queue = []; + invalidCount++; + toggleValidCss(false, validationToken); + parentForm.$setValidity(validationToken, false, form); + } + queue.push(control); + + form.$valid = false; + form.$invalid = true; + } + }; + + form.$setDirty = function() { + element.removeClass(PRISTINE_CLASS).addClass(DIRTY_CLASS); + form.$dirty = true; + form.$pristine = false; + }; + +} + + +/** + * @ngdoc directive + * @name ng.directive:ngForm + * @restrict EAC + * + * @description + * Nestable alias of {@link ng.directive:form `form`} directive. HTML + * does not allow nesting of form elements. It is useful to nest forms, for example if the validity of a + * sub-group of controls needs to be determined. + * + * @param {string=} ngForm|name Name of the form. If specified, the form controller will be published into + * related scope, under this name. + * + */ + + /** + * @ngdoc directive + * @name ng.directive:form + * @restrict E + * + * @description + * Directive that instantiates + * {@link ng.directive:form.FormController FormController}. + * + * If `name` attribute is specified, the form controller is published onto the current scope under + * this name. + * + * # Alias: {@link ng.directive:ngForm `ngForm`} + * + * In angular forms can be nested. This means that the outer form is valid when all of the child + * forms are valid as well. However browsers do not allow nesting of `
` elements, for this + * reason angular provides {@link ng.directive:ngForm `ngForm`} alias + * which behaves identical to `` but allows form nesting. + * + * + * # CSS classes + * - `ng-valid` Is set if the form is valid. + * - `ng-invalid` Is set if the form is invalid. + * - `ng-pristine` Is set if the form is pristine. + * - `ng-dirty` Is set if the form is dirty. + * + * + * # Submitting a form and preventing default action + * + * Since the role of forms in client-side Angular applications is different than in classical + * roundtrip apps, it is desirable for the browser not to translate the form submission into a full + * page reload that sends the data to the server. Instead some javascript logic should be triggered + * to handle the form submission in application specific way. + * + * For this reason, Angular prevents the default action (form submission to the server) unless the + * `` element has an `action` attribute specified. + * + * You can use one of the following two ways to specify what javascript method should be called when + * a form is submitted: + * + * - {@link ng.directive:ngSubmit ngSubmit} directive on the form element + * - {@link ng.directive:ngClick ngClick} directive on the first + * button or input field of type submit (input[type=submit]) + * + * To prevent double execution of the handler, use only one of ngSubmit or ngClick directives. This + * is because of the following form submission rules coming from the html spec: + * + * - If a form has only one input field then hitting enter in this field triggers form submit + * (`ngSubmit`) + * - if a form has has 2+ input fields and no buttons or input[type=submit] then hitting enter + * doesn't trigger submit + * - if a form has one or more input fields and one or more buttons or input[type=submit] then + * hitting enter in any of the input fields will trigger the click handler on the *first* button or + * input[type=submit] (`ngClick`) *and* a submit handler on the enclosing form (`ngSubmit`) + * + * @param {string=} name Name of the form. If specified, the form controller will be published into + * related scope, under this name. + * + * @example + + + + + userType: + Required!
+ userType = {{userType}}
+ myForm.input.$valid = {{myForm.input.$valid}}
+ myForm.input.$error = {{myForm.input.$error}}
+ myForm.$valid = {{myForm.$valid}}
+ myForm.$error.REQUIRED = {{!!myForm.$error.REQUIRED}}
+ +
+ + it('should initialize to model', function() { + expect(binding('userType')).toEqual('guest'); + expect(binding('myForm.input.$valid')).toEqual('true'); + }); + + it('should be invalid if empty', function() { + input('userType').enter(''); + expect(binding('userType')).toEqual(''); + expect(binding('myForm.input.$valid')).toEqual('false'); + }); + +
+ */ +var formDirectiveFactory = function(isNgForm) { + return ['$timeout', function($timeout) { + var formDirective = { + name: 'form', + restrict: 'E', + controller: FormController, + compile: function() { + return { + pre: function(scope, formElement, attr, controller) { + if (!attr.action) { + // we can't use jq events because if a form is destroyed during submission the default + // action is not prevented. see #1238 + // + // IE 9 is not affected because it doesn't fire a submit event and try to do a full + // page reload if the form was destroyed by submission of the form via a click handler + // on a button in the form. Looks like an IE9 specific bug. + var preventDefaultListener = function(event) { + event.preventDefault + ? event.preventDefault() + : event.returnValue = false; // IE + }; + + addEventListenerFn(formElement[0], 'submit', preventDefaultListener); + + // unregister the preventDefault listener so that we don't not leak memory but in a + // way that will achieve the prevention of the default action. + formElement.bind('$destroy', function() { + $timeout(function() { + removeEventListenerFn(formElement[0], 'submit', preventDefaultListener); + }, 0, false); + }); + } + + var parentFormCtrl = formElement.parent().controller('form'), + alias = attr.name || attr.ngForm; + + if (alias) { + scope[alias] = controller; + } + if (parentFormCtrl) { + formElement.bind('$destroy', function() { + parentFormCtrl.$removeControl(controller); + if (alias) { + scope[alias] = undefined; + } + extend(controller, nullFormCtrl); //stop propagating child destruction handlers upwards + }); + } + } + }; + } + }; + + return isNgForm ? extend(copy(formDirective), {restrict: 'EAC'}) : formDirective; + }]; +}; + +var formDirective = formDirectiveFactory(); +var ngFormDirective = formDirectiveFactory(true); + +var URL_REGEXP = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/; +var EMAIL_REGEXP = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/; +var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/; + +var inputType = { + + /** + * @ngdoc inputType + * @name ng.directive:input.text + * + * @description + * Standard HTML text input with angular data binding. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. + * @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the + * RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for + * patterns defined as scope expressions. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
+ Single word: + + Required! + + Single word only! + + text = {{text}}
+ myForm.input.$valid = {{myForm.input.$valid}}
+ myForm.input.$error = {{myForm.input.$error}}
+ myForm.$valid = {{myForm.$valid}}
+ myForm.$error.required = {{!!myForm.$error.required}}
+
+
+ + it('should initialize to model', function() { + expect(binding('text')).toEqual('guest'); + expect(binding('myForm.input.$valid')).toEqual('true'); + }); + + it('should be invalid if empty', function() { + input('text').enter(''); + expect(binding('text')).toEqual(''); + expect(binding('myForm.input.$valid')).toEqual('false'); + }); + + it('should be invalid if multi word', function() { + input('text').enter('hello world'); + expect(binding('myForm.input.$valid')).toEqual('false'); + }); + +
+ */ + 'text': textInputType, + + + /** + * @ngdoc inputType + * @name ng.directive:input.number + * + * @description + * Text input with number validation and transformation. Sets the `number` validation + * error if not a valid number. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} min Sets the `min` validation error key if the value entered is less then `min`. + * @param {string=} max Sets the `max` validation error key if the value entered is greater then `min`. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. + * @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the + * RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for + * patterns defined as scope expressions. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
+ Number: + + Required! + + Not valid number! + value = {{value}}
+ myForm.input.$valid = {{myForm.input.$valid}}
+ myForm.input.$error = {{myForm.input.$error}}
+ myForm.$valid = {{myForm.$valid}}
+ myForm.$error.required = {{!!myForm.$error.required}}
+
+
+ + it('should initialize to model', function() { + expect(binding('value')).toEqual('12'); + expect(binding('myForm.input.$valid')).toEqual('true'); + }); + + it('should be invalid if empty', function() { + input('value').enter(''); + expect(binding('value')).toEqual(''); + expect(binding('myForm.input.$valid')).toEqual('false'); + }); + + it('should be invalid if over max', function() { + input('value').enter('123'); + expect(binding('value')).toEqual(''); + expect(binding('myForm.input.$valid')).toEqual('false'); + }); + +
+ */ + 'number': numberInputType, + + + /** + * @ngdoc inputType + * @name ng.directive:input.url + * + * @description + * Text input with URL validation. Sets the `url` validation error key if the content is not a + * valid URL. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. + * @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the + * RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for + * patterns defined as scope expressions. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
+ URL: + + Required! + + Not valid url! + text = {{text}}
+ myForm.input.$valid = {{myForm.input.$valid}}
+ myForm.input.$error = {{myForm.input.$error}}
+ myForm.$valid = {{myForm.$valid}}
+ myForm.$error.required = {{!!myForm.$error.required}}
+ myForm.$error.url = {{!!myForm.$error.url}}
+
+
+ + it('should initialize to model', function() { + expect(binding('text')).toEqual('http://google.com'); + expect(binding('myForm.input.$valid')).toEqual('true'); + }); + + it('should be invalid if empty', function() { + input('text').enter(''); + expect(binding('text')).toEqual(''); + expect(binding('myForm.input.$valid')).toEqual('false'); + }); + + it('should be invalid if not url', function() { + input('text').enter('xxx'); + expect(binding('myForm.input.$valid')).toEqual('false'); + }); + +
+ */ + 'url': urlInputType, + + + /** + * @ngdoc inputType + * @name ng.directive:input.email + * + * @description + * Text input with email validation. Sets the `email` validation error key if not a valid email + * address. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. + * @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the + * RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for + * patterns defined as scope expressions. + * + * @example + + + +
+ Email: + + Required! + + Not valid email! + text = {{text}}
+ myForm.input.$valid = {{myForm.input.$valid}}
+ myForm.input.$error = {{myForm.input.$error}}
+ myForm.$valid = {{myForm.$valid}}
+ myForm.$error.required = {{!!myForm.$error.required}}
+ myForm.$error.email = {{!!myForm.$error.email}}
+
+
+ + it('should initialize to model', function() { + expect(binding('text')).toEqual('me@example.com'); + expect(binding('myForm.input.$valid')).toEqual('true'); + }); + + it('should be invalid if empty', function() { + input('text').enter(''); + expect(binding('text')).toEqual(''); + expect(binding('myForm.input.$valid')).toEqual('false'); + }); + + it('should be invalid if not email', function() { + input('text').enter('xxx'); + expect(binding('myForm.input.$valid')).toEqual('false'); + }); + +
+ */ + 'email': emailInputType, + + + /** + * @ngdoc inputType + * @name ng.directive:input.radio + * + * @description + * HTML radio button. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string} value The value to which the expression should be set when selected. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
+ Red
+ Green
+ Blue
+ color = {{color}}
+
+
+ + it('should change state', function() { + expect(binding('color')).toEqual('blue'); + + input('color').select('red'); + expect(binding('color')).toEqual('red'); + }); + +
+ */ + 'radio': radioInputType, + + + /** + * @ngdoc inputType + * @name ng.directive:input.checkbox + * + * @description + * HTML checkbox. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} ngTrueValue The value to which the expression should be set when selected. + * @param {string=} ngFalseValue The value to which the expression should be set when not selected. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
+ Value1:
+ Value2:
+ value1 = {{value1}}
+ value2 = {{value2}}
+
+
+ + it('should change state', function() { + expect(binding('value1')).toEqual('true'); + expect(binding('value2')).toEqual('YES'); + + input('value1').check(); + input('value2').check(); + expect(binding('value1')).toEqual('false'); + expect(binding('value2')).toEqual('NO'); + }); + +
+ */ + 'checkbox': checkboxInputType, + + 'hidden': noop, + 'button': noop, + 'submit': noop, + 'reset': noop +}; + + +function isEmpty(value) { + return isUndefined(value) || value === '' || value === null || value !== value; +} + + +function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { + + var listener = function() { + var value = trim(element.val()); + + if (ctrl.$viewValue !== value) { + scope.$apply(function() { + ctrl.$setViewValue(value); + }); + } + }; + + // if the browser does support "input" event, we are fine - except on IE9 which doesn't fire the + // input event on backspace, delete or cut + if ($sniffer.hasEvent('input')) { + element.bind('input', listener); + } else { + var timeout; + + element.bind('keydown', function(event) { + var key = event.keyCode; + + // ignore + // command modifiers arrows + if (key === 91 || (15 < key && key < 19) || (37 <= key && key <= 40)) return; + + if (!timeout) { + timeout = $browser.defer(function() { + listener(); + timeout = null; + }); + } + }); + + // if user paste into input using mouse, we need "change" event to catch it + element.bind('change', listener); + } + + + ctrl.$render = function() { + element.val(isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue); + }; + + // pattern validator + var pattern = attr.ngPattern, + patternValidator; + + var validate = function(regexp, value) { + if (isEmpty(value) || regexp.test(value)) { + ctrl.$setValidity('pattern', true); + return value; + } else { + ctrl.$setValidity('pattern', false); + return undefined; + } + }; + + if (pattern) { + if (pattern.match(/^\/(.*)\/$/)) { + pattern = new RegExp(pattern.substr(1, pattern.length - 2)); + patternValidator = function(value) { + return validate(pattern, value) + }; + } else { + patternValidator = function(value) { + var patternObj = scope.$eval(pattern); + + if (!patternObj || !patternObj.test) { + throw new Error('Expected ' + pattern + ' to be a RegExp but was ' + patternObj); + } + return validate(patternObj, value); + }; + } + + ctrl.$formatters.push(patternValidator); + ctrl.$parsers.push(patternValidator); + } + + // min length validator + if (attr.ngMinlength) { + var minlength = int(attr.ngMinlength); + var minLengthValidator = function(value) { + if (!isEmpty(value) && value.length < minlength) { + ctrl.$setValidity('minlength', false); + return undefined; + } else { + ctrl.$setValidity('minlength', true); + return value; + } + }; + + ctrl.$parsers.push(minLengthValidator); + ctrl.$formatters.push(minLengthValidator); + } + + // max length validator + if (attr.ngMaxlength) { + var maxlength = int(attr.ngMaxlength); + var maxLengthValidator = function(value) { + if (!isEmpty(value) && value.length > maxlength) { + ctrl.$setValidity('maxlength', false); + return undefined; + } else { + ctrl.$setValidity('maxlength', true); + return value; + } + }; + + ctrl.$parsers.push(maxLengthValidator); + ctrl.$formatters.push(maxLengthValidator); + } +} + +function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) { + textInputType(scope, element, attr, ctrl, $sniffer, $browser); + + ctrl.$parsers.push(function(value) { + var empty = isEmpty(value); + if (empty || NUMBER_REGEXP.test(value)) { + ctrl.$setValidity('number', true); + return value === '' ? null : (empty ? value : parseFloat(value)); + } else { + ctrl.$setValidity('number', false); + return undefined; + } + }); + + ctrl.$formatters.push(function(value) { + return isEmpty(value) ? '' : '' + value; + }); + + if (attr.min) { + var min = parseFloat(attr.min); + var minValidator = function(value) { + if (!isEmpty(value) && value < min) { + ctrl.$setValidity('min', false); + return undefined; + } else { + ctrl.$setValidity('min', true); + return value; + } + }; + + ctrl.$parsers.push(minValidator); + ctrl.$formatters.push(minValidator); + } + + if (attr.max) { + var max = parseFloat(attr.max); + var maxValidator = function(value) { + if (!isEmpty(value) && value > max) { + ctrl.$setValidity('max', false); + return undefined; + } else { + ctrl.$setValidity('max', true); + return value; + } + }; + + ctrl.$parsers.push(maxValidator); + ctrl.$formatters.push(maxValidator); + } + + ctrl.$formatters.push(function(value) { + + if (isEmpty(value) || isNumber(value)) { + ctrl.$setValidity('number', true); + return value; + } else { + ctrl.$setValidity('number', false); + return undefined; + } + }); +} + +function urlInputType(scope, element, attr, ctrl, $sniffer, $browser) { + textInputType(scope, element, attr, ctrl, $sniffer, $browser); + + var urlValidator = function(value) { + if (isEmpty(value) || URL_REGEXP.test(value)) { + ctrl.$setValidity('url', true); + return value; + } else { + ctrl.$setValidity('url', false); + return undefined; + } + }; + + ctrl.$formatters.push(urlValidator); + ctrl.$parsers.push(urlValidator); +} + +function emailInputType(scope, element, attr, ctrl, $sniffer, $browser) { + textInputType(scope, element, attr, ctrl, $sniffer, $browser); + + var emailValidator = function(value) { + if (isEmpty(value) || EMAIL_REGEXP.test(value)) { + ctrl.$setValidity('email', true); + return value; + } else { + ctrl.$setValidity('email', false); + return undefined; + } + }; + + ctrl.$formatters.push(emailValidator); + ctrl.$parsers.push(emailValidator); +} + +function radioInputType(scope, element, attr, ctrl) { + // make the name unique, if not defined + if (isUndefined(attr.name)) { + element.attr('name', nextUid()); + } + + element.bind('click', function() { + if (element[0].checked) { + scope.$apply(function() { + ctrl.$setViewValue(attr.value); + }); + } + }); + + ctrl.$render = function() { + var value = attr.value; + element[0].checked = (value == ctrl.$viewValue); + }; + + attr.$observe('value', ctrl.$render); +} + +function checkboxInputType(scope, element, attr, ctrl) { + var trueValue = attr.ngTrueValue, + falseValue = attr.ngFalseValue; + + if (!isString(trueValue)) trueValue = true; + if (!isString(falseValue)) falseValue = false; + + element.bind('click', function() { + scope.$apply(function() { + ctrl.$setViewValue(element[0].checked); + }); + }); + + ctrl.$render = function() { + element[0].checked = ctrl.$viewValue; + }; + + ctrl.$formatters.push(function(value) { + return value === trueValue; + }); + + ctrl.$parsers.push(function(value) { + return value ? trueValue : falseValue; + }); +} + + +/** + * @ngdoc directive + * @name ng.directive:textarea + * @restrict E + * + * @description + * HTML textarea element control with angular data-binding. The data-binding and validation + * properties of this element are exactly the same as those of the + * {@link ng.directive:input input element}. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. + * @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the + * RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for + * patterns defined as scope expressions. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + */ + + +/** + * @ngdoc directive + * @name ng.directive:input + * @restrict E + * + * @description + * HTML input element control with angular data-binding. Input control follows HTML5 input types + * and polyfills the HTML5 validation behavior for older browsers. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. + * @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the + * RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for + * patterns defined as scope expressions. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
+
+ User name: + + Required!
+ Last name: + + Too short! + + Too long!
+
+
+ user = {{user}}
+ myForm.userName.$valid = {{myForm.userName.$valid}}
+ myForm.userName.$error = {{myForm.userName.$error}}
+ myForm.lastName.$valid = {{myForm.lastName.$valid}}
+ myForm.userName.$error = {{myForm.lastName.$error}}
+ myForm.$valid = {{myForm.$valid}}
+ myForm.$error.required = {{!!myForm.$error.required}}
+ myForm.$error.minlength = {{!!myForm.$error.minlength}}
+ myForm.$error.maxlength = {{!!myForm.$error.maxlength}}
+
+
+ + it('should initialize to model', function() { + expect(binding('user')).toEqual('{"name":"guest","last":"visitor"}'); + expect(binding('myForm.userName.$valid')).toEqual('true'); + expect(binding('myForm.$valid')).toEqual('true'); + }); + + it('should be invalid if empty when required', function() { + input('user.name').enter(''); + expect(binding('user')).toEqual('{"last":"visitor"}'); + expect(binding('myForm.userName.$valid')).toEqual('false'); + expect(binding('myForm.$valid')).toEqual('false'); + }); + + it('should be valid if empty when min length is set', function() { + input('user.last').enter(''); + expect(binding('user')).toEqual('{"name":"guest","last":""}'); + expect(binding('myForm.lastName.$valid')).toEqual('true'); + expect(binding('myForm.$valid')).toEqual('true'); + }); + + it('should be invalid if less than required min length', function() { + input('user.last').enter('xx'); + expect(binding('user')).toEqual('{"name":"guest"}'); + expect(binding('myForm.lastName.$valid')).toEqual('false'); + expect(binding('myForm.lastName.$error')).toMatch(/minlength/); + expect(binding('myForm.$valid')).toEqual('false'); + }); + + it('should be invalid if longer than max length', function() { + input('user.last').enter('some ridiculously long name'); + expect(binding('user')) + .toEqual('{"name":"guest"}'); + expect(binding('myForm.lastName.$valid')).toEqual('false'); + expect(binding('myForm.lastName.$error')).toMatch(/maxlength/); + expect(binding('myForm.$valid')).toEqual('false'); + }); + +
+ */ +var inputDirective = ['$browser', '$sniffer', function($browser, $sniffer) { + return { + restrict: 'E', + require: '?ngModel', + link: function(scope, element, attr, ctrl) { + if (ctrl) { + (inputType[lowercase(attr.type)] || inputType.text)(scope, element, attr, ctrl, $sniffer, + $browser); + } + } + }; +}]; + +var VALID_CLASS = 'ng-valid', + INVALID_CLASS = 'ng-invalid', + PRISTINE_CLASS = 'ng-pristine', + DIRTY_CLASS = 'ng-dirty'; + +/** + * @ngdoc object + * @name ng.directive:ngModel.NgModelController + * + * @property {string} $viewValue Actual string value in the view. + * @property {*} $modelValue The value in the model, that the control is bound to. + * @property {Array.} $parsers Whenever the control reads value from the DOM, it executes + * all of these functions to sanitize / convert the value as well as validate. + * + * @property {Array.} $formatters Whenever the model value changes, it executes all of + * these functions to convert the value as well as validate. + * + * @property {Object} $error An bject hash with all errors as keys. + * + * @property {boolean} $pristine True if user has not interacted with the control yet. + * @property {boolean} $dirty True if user has already interacted with the control. + * @property {boolean} $valid True if there is no error. + * @property {boolean} $invalid True if at least one error on the control. + * + * @description + * + * `NgModelController` provides API for the `ng-model` directive. The controller contains + * services for data-binding, validation, CSS update, value formatting and parsing. It + * specifically does not contain any logic which deals with DOM rendering or listening to + * DOM events. The `NgModelController` is meant to be extended by other directives where, the + * directive provides DOM manipulation and the `NgModelController` provides the data-binding. + * + * This example shows how to use `NgModelController` with a custom control to achieve + * data-binding. Notice how different directives (`contenteditable`, `ng-model`, and `required`) + * collaborate together to achieve the desired result. + * + * + + [contenteditable] { + border: 1px solid black; + background-color: white; + min-height: 20px; + } + + .ng-invalid { + border: 1px solid red; + } + + + + angular.module('customControl', []). + directive('contenteditable', function() { + return { + restrict: 'A', // only activate on element attribute + require: '?ngModel', // get a hold of NgModelController + link: function(scope, element, attrs, ngModel) { + if(!ngModel) return; // do nothing if no ng-model + + // Specify how UI should be updated + ngModel.$render = function() { + element.html(ngModel.$viewValue || ''); + }; + + // Listen for change events to enable binding + element.bind('blur keyup change', function() { + scope.$apply(read); + }); + read(); // initialize + + // Write data to the model + function read() { + ngModel.$setViewValue(element.html()); + } + } + }; + }); + + +
+
Change me!
+ Required! +
+ +
+
+ + it('should data-bind and become invalid', function() { + var contentEditable = element('[contenteditable]'); + + expect(contentEditable.text()).toEqual('Change me!'); + input('userContent').enter(''); + expect(contentEditable.text()).toEqual(''); + expect(contentEditable.prop('className')).toMatch(/ng-invalid-required/); + }); + + *
+ * + */ +var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse', + function($scope, $exceptionHandler, $attr, $element, $parse) { + this.$viewValue = Number.NaN; + this.$modelValue = Number.NaN; + this.$parsers = []; + this.$formatters = []; + this.$viewChangeListeners = []; + this.$pristine = true; + this.$dirty = false; + this.$valid = true; + this.$invalid = false; + this.$name = $attr.name; + + var ngModelGet = $parse($attr.ngModel), + ngModelSet = ngModelGet.assign; + + if (!ngModelSet) { + throw Error(NON_ASSIGNABLE_MODEL_EXPRESSION + $attr.ngModel + + ' (' + startingTag($element) + ')'); + } + + /** + * @ngdoc function + * @name ng.directive:ngModel.NgModelController#$render + * @methodOf ng.directive:ngModel.NgModelController + * + * @description + * Called when the view needs to be updated. It is expected that the user of the ng-model + * directive will implement this method. + */ + this.$render = noop; + + var parentForm = $element.inheritedData('$formController') || nullFormCtrl, + invalidCount = 0, // used to easily determine if we are valid + $error = this.$error = {}; // keep invalid keys here + + + // Setup initial state of the control + $element.addClass(PRISTINE_CLASS); + toggleValidCss(true); + + // convenience method for easy toggling of classes + function toggleValidCss(isValid, validationErrorKey) { + validationErrorKey = validationErrorKey ? '-' + snake_case(validationErrorKey, '-') : ''; + $element. + removeClass((isValid ? INVALID_CLASS : VALID_CLASS) + validationErrorKey). + addClass((isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey); + } + + /** + * @ngdoc function + * @name ng.directive:ngModel.NgModelController#$setValidity + * @methodOf ng.directive:ngModel.NgModelController + * + * @description + * Change the validity state, and notifies the form when the control changes validity. (i.e. it + * does not notify form if given validator is already marked as invalid). + * + * This method should be called by validators - i.e. the parser or formatter functions. + * + * @param {string} validationErrorKey Name of the validator. the `validationErrorKey` will assign + * to `$error[validationErrorKey]=isValid` so that it is available for data-binding. + * The `validationErrorKey` should be in camelCase and will get converted into dash-case + * for class name. Example: `myError` will result in `ng-valid-my-error` and `ng-invalid-my-error` + * class and can be bound to as `{{someForm.someControl.$error.myError}}` . + * @param {boolean} isValid Whether the current state is valid (true) or invalid (false). + */ + this.$setValidity = function(validationErrorKey, isValid) { + if ($error[validationErrorKey] === !isValid) return; + + if (isValid) { + if ($error[validationErrorKey]) invalidCount--; + if (!invalidCount) { + toggleValidCss(true); + this.$valid = true; + this.$invalid = false; + } + } else { + toggleValidCss(false); + this.$invalid = true; + this.$valid = false; + invalidCount++; + } + + $error[validationErrorKey] = !isValid; + toggleValidCss(isValid, validationErrorKey); + + parentForm.$setValidity(validationErrorKey, isValid, this); + }; + + + /** + * @ngdoc function + * @name ng.directive:ngModel.NgModelController#$setViewValue + * @methodOf ng.directive:ngModel.NgModelController + * + * @description + * Read a value from view. + * + * This method should be called from within a DOM event handler. + * For example {@link ng.directive:input input} or + * {@link ng.directive:select select} directives call it. + * + * It internally calls all `formatters` and if resulted value is valid, updates the model and + * calls all registered change listeners. + * + * @param {string} value Value from the view. + */ + this.$setViewValue = function(value) { + this.$viewValue = value; + + // change to dirty + if (this.$pristine) { + this.$dirty = true; + this.$pristine = false; + $element.removeClass(PRISTINE_CLASS).addClass(DIRTY_CLASS); + parentForm.$setDirty(); + } + + forEach(this.$parsers, function(fn) { + value = fn(value); + }); + + if (this.$modelValue !== value) { + this.$modelValue = value; + ngModelSet($scope, value); + forEach(this.$viewChangeListeners, function(listener) { + try { + listener(); + } catch(e) { + $exceptionHandler(e); + } + }) + } + }; + + // model -> value + var ctrl = this; + $scope.$watch(ngModelGet, function(value) { + + // ignore change from view + if (ctrl.$modelValue === value) return; + + var formatters = ctrl.$formatters, + idx = formatters.length; + + ctrl.$modelValue = value; + while(idx--) { + value = formatters[idx](value); + } + + if (ctrl.$viewValue !== value) { + ctrl.$viewValue = value; + ctrl.$render(); + } + }); +}]; + + +/** + * @ngdoc directive + * @name ng.directive:ngModel + * + * @element input + * + * @description + * Is directive that tells Angular to do two-way data binding. It works together with `input`, + * `select`, `textarea`. You can easily write your own directives to use `ngModel` as well. + * + * `ngModel` is responsible for: + * + * - binding the view into the model, which other directives such as `input`, `textarea` or `select` + * require, + * - providing validation behavior (i.e. required, number, email, url), + * - keeping state of the control (valid/invalid, dirty/pristine, validation errors), + * - setting related css class onto the element (`ng-valid`, `ng-invalid`, `ng-dirty`, `ng-pristine`), + * - register the control with parent {@link ng.directive:form form}. + * + * For basic examples, how to use `ngModel`, see: + * + * - {@link ng.directive:input input} + * - {@link ng.directive:input.text text} + * - {@link ng.directive:input.checkbox checkbox} + * - {@link ng.directive:input.radio radio} + * - {@link ng.directive:input.number number} + * - {@link ng.directive:input.email email} + * - {@link ng.directive:input.url url} + * - {@link ng.directive:select select} + * - {@link ng.directive:textarea textarea} + * + */ +var ngModelDirective = function() { + return { + require: ['ngModel', '^?form'], + controller: NgModelController, + link: function(scope, element, attr, ctrls) { + // notify others, especially parent forms + + var modelCtrl = ctrls[0], + formCtrl = ctrls[1] || nullFormCtrl; + + formCtrl.$addControl(modelCtrl); + + element.bind('$destroy', function() { + formCtrl.$removeControl(modelCtrl); + }); + } + }; +}; + + +/** + * @ngdoc directive + * @name ng.directive:ngChange + * @restrict E + * + * @description + * Evaluate given expression when user changes the input. + * The expression is not evaluated when the value change is coming from the model. + * + * Note, this directive requires `ngModel` to be present. + * + * @element input + * + * @example + * + * + * + *
+ * + * + *
+ * debug = {{confirmed}}
+ * counter = {{counter}} + *
+ *
+ * + * it('should evaluate the expression if changing from view', function() { + * expect(binding('counter')).toEqual('0'); + * element('#ng-change-example1').click(); + * expect(binding('counter')).toEqual('1'); + * expect(binding('confirmed')).toEqual('true'); + * }); + * + * it('should not evaluate the expression if changing from model', function() { + * element('#ng-change-example2').click(); + * expect(binding('counter')).toEqual('0'); + * expect(binding('confirmed')).toEqual('true'); + * }); + * + *
+ */ +var ngChangeDirective = valueFn({ + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + ctrl.$viewChangeListeners.push(function() { + scope.$eval(attr.ngChange); + }); + } +}); + + +var requiredDirective = function() { + return { + require: '?ngModel', + link: function(scope, elm, attr, ctrl) { + if (!ctrl) return; + attr.required = true; // force truthy in case we are on non input element + + var validator = function(value) { + if (attr.required && (isEmpty(value) || value === false)) { + ctrl.$setValidity('required', false); + return; + } else { + ctrl.$setValidity('required', true); + return value; + } + }; + + ctrl.$formatters.push(validator); + ctrl.$parsers.unshift(validator); + + attr.$observe('required', function() { + validator(ctrl.$viewValue); + }); + } + }; +}; + + +/** + * @ngdoc directive + * @name ng.directive:ngList + * + * @description + * Text input that converts between comma-seperated string into an array of strings. + * + * @element input + * @param {string=} ngList optional delimiter that should be used to split the value. If + * specified in form `/something/` then the value will be converted into a regular expression. + * + * @example + + + +
+ List: + + Required! + names = {{names}}
+ myForm.namesInput.$valid = {{myForm.namesInput.$valid}}
+ myForm.namesInput.$error = {{myForm.namesInput.$error}}
+ myForm.$valid = {{myForm.$valid}}
+ myForm.$error.required = {{!!myForm.$error.required}}
+
+
+ + it('should initialize to model', function() { + expect(binding('names')).toEqual('["igor","misko","vojta"]'); + expect(binding('myForm.namesInput.$valid')).toEqual('true'); + }); + + it('should be invalid if empty', function() { + input('names').enter(''); + expect(binding('names')).toEqual('[]'); + expect(binding('myForm.namesInput.$valid')).toEqual('false'); + }); + +
+ */ +var ngListDirective = function() { + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + var match = /\/(.*)\//.exec(attr.ngList), + separator = match && new RegExp(match[1]) || attr.ngList || ','; + + var parse = function(viewValue) { + var list = []; + + if (viewValue) { + forEach(viewValue.split(separator), function(value) { + if (value) list.push(trim(value)); + }); + } + + return list; + }; + + ctrl.$parsers.push(parse); + ctrl.$formatters.push(function(value) { + if (isArray(value)) { + return value.join(', '); + } + + return undefined; + }); + } + }; +}; + + +var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/; + +var ngValueDirective = function() { + return { + priority: 100, + compile: function(tpl, tplAttr) { + if (CONSTANT_VALUE_REGEXP.test(tplAttr.ngValue)) { + return function(scope, elm, attr) { + attr.$set('value', scope.$eval(attr.ngValue)); + }; + } else { + return function(scope, elm, attr) { + scope.$watch(attr.ngValue, function(value) { + attr.$set('value', value, false); + }); + }; + } + } + }; +}; + +/** + * @ngdoc directive + * @name ng.directive:ngBind + * + * @description + * The `ngBind` attribute tells Angular to replace the text content of the specified HTML element + * with the value of a given expression, and to update the text content when the value of that + * expression changes. + * + * Typically, you don't use `ngBind` directly, but instead you use the double curly markup like + * `{{ expression }}` which is similar but less verbose. + * + * Once scenario in which the use of `ngBind` is prefered over `{{ expression }}` binding is when + * it's desirable to put bindings into template that is momentarily displayed by the browser in its + * raw state before Angular compiles it. Since `ngBind` is an element attribute, it makes the + * bindings invisible to the user while the page is loading. + * + * An alternative solution to this problem would be using the + * {@link ng.directive:ngCloak ngCloak} directive. + * + * + * @element ANY + * @param {expression} ngBind {@link guide/expression Expression} to evaluate. + * + * @example + * Enter a name in the Live Preview text box; the greeting below the text box changes instantly. + + + +
+ Enter name:
+ Hello ! +
+
+ + it('should check ng-bind', function() { + expect(using('.doc-example-live').binding('name')).toBe('Whirled'); + using('.doc-example-live').input('name').enter('world'); + expect(using('.doc-example-live').binding('name')).toBe('world'); + }); + +
+ */ +var ngBindDirective = ngDirective(function(scope, element, attr) { + element.addClass('ng-binding').data('$binding', attr.ngBind); + scope.$watch(attr.ngBind, function(value) { + element.text(value == undefined ? '' : value); + }); +}); + + +/** + * @ngdoc directive + * @name ng.directive:ngBindTemplate + * + * @description + * The `ngBindTemplate` directive specifies that the element + * text should be replaced with the template in ngBindTemplate. + * Unlike ngBind the ngBindTemplate can contain multiple `{{` `}}` + * expressions. (This is required since some HTML elements + * can not have SPAN elements such as TITLE, or OPTION to name a few.) + * + * @element ANY + * @param {string} ngBindTemplate template of form + * {{ expression }} to eval. + * + * @example + * Try it here: enter text in text box and watch the greeting change. + + + +
+ Salutation:
+ Name:
+

+       
+
+ + it('should check ng-bind', function() { + expect(using('.doc-example-live').binding('salutation')). + toBe('Hello'); + expect(using('.doc-example-live').binding('name')). + toBe('World'); + using('.doc-example-live').input('salutation').enter('Greetings'); + using('.doc-example-live').input('name').enter('user'); + expect(using('.doc-example-live').binding('salutation')). + toBe('Greetings'); + expect(using('.doc-example-live').binding('name')). + toBe('user'); + }); + +
+ */ +var ngBindTemplateDirective = ['$interpolate', function($interpolate) { + return function(scope, element, attr) { + // TODO: move this to scenario runner + var interpolateFn = $interpolate(element.attr(attr.$attr.ngBindTemplate)); + element.addClass('ng-binding').data('$binding', interpolateFn); + attr.$observe('ngBindTemplate', function(value) { + element.text(value); + }); + } +}]; + + +/** + * @ngdoc directive + * @name ng.directive:ngBindHtmlUnsafe + * + * @description + * Creates a binding that will innerHTML the result of evaluating the `expression` into the current + * element. *The innerHTML-ed content will not be sanitized!* You should use this directive only if + * {@link ngSanitize.directive:ngBindHtml ngBindHtml} directive is too + * restrictive and when you absolutely trust the source of the content you are binding to. + * + * See {@link ngSanitize.$sanitize $sanitize} docs for examples. + * + * @element ANY + * @param {expression} ngBindHtmlUnsafe {@link guide/expression Expression} to evaluate. + */ +var ngBindHtmlUnsafeDirective = [function() { + return function(scope, element, attr) { + element.addClass('ng-binding').data('$binding', attr.ngBindHtmlUnsafe); + scope.$watch(attr.ngBindHtmlUnsafe, function(value) { + element.html(value || ''); + }); + }; +}]; + +function classDirective(name, selector) { + name = 'ngClass' + name; + return ngDirective(function(scope, element, attr) { + scope.$watch(attr[name], function(newVal, oldVal) { + if (selector === true || scope.$index % 2 === selector) { + if (oldVal && (newVal !== oldVal)) { + if (isObject(oldVal) && !isArray(oldVal)) + oldVal = map(oldVal, function(v, k) { if (v) return k }); + element.removeClass(isArray(oldVal) ? oldVal.join(' ') : oldVal); + } + if (isObject(newVal) && !isArray(newVal)) + newVal = map(newVal, function(v, k) { if (v) return k }); + if (newVal) element.addClass(isArray(newVal) ? newVal.join(' ') : newVal); } + }, true); + }); +} + +/** + * @ngdoc directive + * @name ng.directive:ngClass + * + * @description + * The `ngClass` allows you to set CSS class on HTML element dynamically by databinding an + * expression that represents all classes to be added. + * + * The directive won't add duplicate classes if a particular class was already set. + * + * When the expression changes, the previously added classes are removed and only then the classes + * new classes are added. + * + * @element ANY + * @param {expression} ngClass {@link guide/expression Expression} to eval. The result + * of the evaluation can be a string representing space delimited class + * names, an array, or a map of class names to boolean values. + * + * @example + + + + +
+ Sample Text +
+ + .my-class { + color: red; + } + + + it('should check ng-class', function() { + expect(element('.doc-example-live span').prop('className')).not(). + toMatch(/my-class/); + + using('.doc-example-live').element(':button:first').click(); + + expect(element('.doc-example-live span').prop('className')). + toMatch(/my-class/); + + using('.doc-example-live').element(':button:last').click(); + + expect(element('.doc-example-live span').prop('className')).not(). + toMatch(/my-class/); + }); + +
+ */ +var ngClassDirective = classDirective('', true); + +/** + * @ngdoc directive + * @name ng.directive:ngClassOdd + * + * @description + * The `ngClassOdd` and `ngClassEven` directives work exactly as + * {@link ng.directive:ngClass ngClass}, except it works in + * conjunction with `ngRepeat` and takes affect only on odd (even) rows. + * + * This directive can be applied only within a scope of an + * {@link ng.directive:ngRepeat ngRepeat}. + * + * @element ANY + * @param {expression} ngClassOdd {@link guide/expression Expression} to eval. The result + * of the evaluation can be a string representing space delimited class names or an array. + * + * @example + + +
    +
  1. + + {{name}} + +
  2. +
+
+ + .odd { + color: red; + } + .even { + color: blue; + } + + + it('should check ng-class-odd and ng-class-even', function() { + expect(element('.doc-example-live li:first span').prop('className')). + toMatch(/odd/); + expect(element('.doc-example-live li:last span').prop('className')). + toMatch(/even/); + }); + +
+ */ +var ngClassOddDirective = classDirective('Odd', 0); + +/** + * @ngdoc directive + * @name ng.directive:ngClassEven + * + * @description + * The `ngClassOdd` and `ngClassEven` works exactly as + * {@link ng.directive:ngClass ngClass}, except it works in + * conjunction with `ngRepeat` and takes affect only on odd (even) rows. + * + * This directive can be applied only within a scope of an + * {@link ng.directive:ngRepeat ngRepeat}. + * + * @element ANY + * @param {expression} ngClassEven {@link guide/expression Expression} to eval. The + * result of the evaluation can be a string representing space delimited class names or an array. + * + * @example + + +
    +
  1. + + {{name}}       + +
  2. +
+
+ + .odd { + color: red; + } + .even { + color: blue; + } + + + it('should check ng-class-odd and ng-class-even', function() { + expect(element('.doc-example-live li:first span').prop('className')). + toMatch(/odd/); + expect(element('.doc-example-live li:last span').prop('className')). + toMatch(/even/); + }); + +
+ */ +var ngClassEvenDirective = classDirective('Even', 1); + +/** + * @ngdoc directive + * @name ng.directive:ngCloak + * + * @description + * The `ngCloak` directive is used to prevent the Angular html template from being briefly + * displayed by the browser in its raw (uncompiled) form while your application is loading. Use this + * directive to avoid the undesirable flicker effect caused by the html template display. + * + * The directive can be applied to the `` element, but typically a fine-grained application is + * prefered in order to benefit from progressive rendering of the browser view. + * + * `ngCloak` works in cooperation with a css rule that is embedded within `angular.js` and + * `angular.min.js` files. Following is the css rule: + * + *
+ * [ng\:cloak], [ng-cloak], .ng-cloak {
+ *   display: none;
+ * }
+ * 
+ * + * When this css rule is loaded by the browser, all html elements (including their children) that + * are tagged with the `ng-cloak` directive are hidden. When Angular comes across this directive + * during the compilation of the template it deletes the `ngCloak` element attribute, which + * makes the compiled element visible. + * + * For the best result, `angular.js` script must be loaded in the head section of the html file; + * alternatively, the css rule (above) must be included in the external stylesheet of the + * application. + * + * Legacy browsers, like IE7, do not provide attribute selector support (added in CSS 2.1) so they + * cannot match the `[ng\:cloak]` selector. To work around this limitation, you must add the css + * class `ngCloak` in addition to `ngCloak` directive as shown in the example below. + * + * @element ANY + * + * @example + + +
{{ 'hello' }}
+
{{ 'hello IE7' }}
+
+ + it('should remove the template directive and css class', function() { + expect(element('.doc-example-live #template1').attr('ng-cloak')). + not().toBeDefined(); + expect(element('.doc-example-live #template2').attr('ng-cloak')). + not().toBeDefined(); + }); + +
+ * + */ +var ngCloakDirective = ngDirective({ + compile: function(element, attr) { + attr.$set('ngCloak', undefined); + element.removeClass('ng-cloak'); + } +}); + +/** + * @ngdoc directive + * @name ng.directive:ngController + * + * @description + * The `ngController` directive assigns behavior to a scope. This is a key aspect of how angular + * supports the principles behind the Model-View-Controller design pattern. + * + * MVC components in angular: + * + * * Model — The Model is data in scope properties; scopes are attached to the DOM. + * * View — The template (HTML with data bindings) is rendered into the View. + * * Controller — The `ngController` directive specifies a Controller class; the class has + * methods that typically express the business logic behind the application. + * + * Note that an alternative way to define controllers is via the `{@link ng.$route}` + * service. + * + * @element ANY + * @scope + * @param {expression} ngController Name of a globally accessible constructor function or an + * {@link guide/expression expression} that on the current scope evaluates to a + * constructor function. + * + * @example + * Here is a simple form for editing user contact information. Adding, removing, clearing, and + * greeting are methods declared on the controller (see source tab). These methods can + * easily be called from the angular markup. Notice that the scope becomes the `this` for the + * controller's instance. This allows for easy access to the view data from the controller. Also + * notice that any changes to the data are automatically reflected in the View without the need + * for a manual update. + + + +
+ Name: + [ greet ]
+ Contact: +
    +
  • + + + [ clear + | X ] +
  • +
  • [ add ]
  • +
+
+
+ + it('should check controller', function() { + expect(element('.doc-example-live div>:input').val()).toBe('John Smith'); + expect(element('.doc-example-live li:nth-child(1) input').val()) + .toBe('408 555 1212'); + expect(element('.doc-example-live li:nth-child(2) input').val()) + .toBe('john.smith@example.org'); + + element('.doc-example-live li:first a:contains("clear")').click(); + expect(element('.doc-example-live li:first input').val()).toBe(''); + + element('.doc-example-live li:last a:contains("add")').click(); + expect(element('.doc-example-live li:nth-child(3) input').val()) + .toBe('yourname@example.org'); + }); + +
+ */ +var ngControllerDirective = [function() { + return { + scope: true, + controller: '@' + }; +}]; + +/** + * @ngdoc directive + * @name ng.directive:ngCsp + * @priority 1000 + * + * @description + * Enables [CSP (Content Security Policy)](https://developer.mozilla.org/en/Security/CSP) support. + * This directive should be used on the root element of the application (typically the `` + * element or other element with the {@link ng.directive:ngApp ngApp} + * directive). + * + * If enabled the performance of template expression evaluator will suffer slightly, so don't enable + * this mode unless you need it. + * + * @element html + */ + +var ngCspDirective = ['$sniffer', function($sniffer) { + return { + priority: 1000, + compile: function() { + $sniffer.csp = true; + } + }; +}]; + +/** + * @ngdoc directive + * @name ng.directive:ngClick + * + * @description + * The ngClick allows you to specify custom behavior when + * element is clicked. + * + * @element ANY + * @param {expression} ngClick {@link guide/expression Expression} to evaluate upon + * click. (Event object is available as `$event`) + * + * @example + + + + count: {{count}} + + + it('should check ng-click', function() { + expect(binding('count')).toBe('0'); + element('.doc-example-live :button').click(); + expect(binding('count')).toBe('1'); + }); + + + */ +/* + * A directive that allows creation of custom onclick handlers that are defined as angular + * expressions and are compiled and executed within the current scope. + * + * Events that are handled via these handler are always configured not to propagate further. + */ +var ngEventDirectives = {}; +forEach( + 'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave'.split(' '), + function(name) { + var directiveName = directiveNormalize('ng-' + name); + ngEventDirectives[directiveName] = ['$parse', function($parse) { + return function(scope, element, attr) { + var fn = $parse(attr[directiveName]); + element.bind(lowercase(name), function(event) { + scope.$apply(function() { + fn(scope, {$event:event}); + }); + }); + }; + }]; + } +); + +/** + * @ngdoc directive + * @name ng.directive:ngDblclick + * + * @description + * The `ngDblclick` directive allows you to specify custom behavior on dblclick event. + * + * @element ANY + * @param {expression} ngDblclick {@link guide/expression Expression} to evaluate upon + * dblclick. (Event object is available as `$event`) + * + * @example + * See {@link ng.directive:ngClick ngClick} + */ + + +/** + * @ngdoc directive + * @name ng.directive:ngMousedown + * + * @description + * The ngMousedown directive allows you to specify custom behavior on mousedown event. + * + * @element ANY + * @param {expression} ngMousedown {@link guide/expression Expression} to evaluate upon + * mousedown. (Event object is available as `$event`) + * + * @example + * See {@link ng.directive:ngClick ngClick} + */ + + +/** + * @ngdoc directive + * @name ng.directive:ngMouseup + * + * @description + * Specify custom behavior on mouseup event. + * + * @element ANY + * @param {expression} ngMouseup {@link guide/expression Expression} to evaluate upon + * mouseup. (Event object is available as `$event`) + * + * @example + * See {@link ng.directive:ngClick ngClick} + */ + +/** + * @ngdoc directive + * @name ng.directive:ngMouseover + * + * @description + * Specify custom behavior on mouseover event. + * + * @element ANY + * @param {expression} ngMouseover {@link guide/expression Expression} to evaluate upon + * mouseover. (Event object is available as `$event`) + * + * @example + * See {@link ng.directive:ngClick ngClick} + */ + + +/** + * @ngdoc directive + * @name ng.directive:ngMouseenter + * + * @description + * Specify custom behavior on mouseenter event. + * + * @element ANY + * @param {expression} ngMouseenter {@link guide/expression Expression} to evaluate upon + * mouseenter. (Event object is available as `$event`) + * + * @example + * See {@link ng.directive:ngClick ngClick} + */ + + +/** + * @ngdoc directive + * @name ng.directive:ngMouseleave + * + * @description + * Specify custom behavior on mouseleave event. + * + * @element ANY + * @param {expression} ngMouseleave {@link guide/expression Expression} to evaluate upon + * mouseleave. (Event object is available as `$event`) + * + * @example + * See {@link ng.directive:ngClick ngClick} + */ + + +/** + * @ngdoc directive + * @name ng.directive:ngMousemove + * + * @description + * Specify custom behavior on mousemove event. + * + * @element ANY + * @param {expression} ngMousemove {@link guide/expression Expression} to evaluate upon + * mousemove. (Event object is available as `$event`) + * + * @example + * See {@link ng.directive:ngClick ngClick} + */ + + +/** + * @ngdoc directive + * @name ng.directive:ngSubmit + * + * @description + * Enables binding angular expressions to onsubmit events. + * + * Additionally it prevents the default action (which for form means sending the request to the + * server and reloading the current page). + * + * @element form + * @param {expression} ngSubmit {@link guide/expression Expression} to eval. + * + * @example + + + +
+ Enter text and hit enter: + + +
list={{list}}
+
+
+ + it('should check ng-submit', function() { + expect(binding('list')).toBe('[]'); + element('.doc-example-live #submit').click(); + expect(binding('list')).toBe('["hello"]'); + expect(input('text').val()).toBe(''); + }); + it('should ignore empty strings', function() { + expect(binding('list')).toBe('[]'); + element('.doc-example-live #submit').click(); + element('.doc-example-live #submit').click(); + expect(binding('list')).toBe('["hello"]'); + }); + +
+ */ +var ngSubmitDirective = ngDirective(function(scope, element, attrs) { + element.bind('submit', function() { + scope.$apply(attrs.ngSubmit); + }); +}); + +/** + * @ngdoc directive + * @name ng.directive:ngInclude + * @restrict ECA + * + * @description + * Fetches, compiles and includes an external HTML fragment. + * + * Keep in mind that Same Origin Policy applies to included resources + * (e.g. ngInclude won't work for cross-domain requests on all browsers and for + * file:// access on some browsers). + * + * @scope + * + * @param {string} ngInclude|src angular expression evaluating to URL. If the source is a string constant, + * make sure you wrap it in quotes, e.g. `src="'myPartialTemplate.html'"`. + * @param {string=} onload Expression to evaluate when a new partial is loaded. + * + * @param {string=} autoscroll Whether `ngInclude` should call {@link ng.$anchorScroll + * $anchorScroll} to scroll the viewport after the content is loaded. + * + * - If the attribute is not set, disable scrolling. + * - If the attribute is set without value, enable scrolling. + * - Otherwise enable scrolling only if the expression evaluates to truthy value. + * + * @example + + +
+ + url of the template: {{template.url}} +
+
+
+
+ + function Ctrl($scope) { + $scope.templates = + [ { name: 'template1.html', url: 'template1.html'} + , { name: 'template2.html', url: 'template2.html'} ]; + $scope.template = $scope.templates[0]; + } + + + Content of template1.html + + + Content of template2.html + + + it('should load template1.html', function() { + expect(element('.doc-example-live [ng-include]').text()). + toMatch(/Content of template1.html/); + }); + it('should load template2.html', function() { + select('template').option('1'); + expect(element('.doc-example-live [ng-include]').text()). + toMatch(/Content of template2.html/); + }); + it('should change to blank', function() { + select('template').option(''); + expect(element('.doc-example-live [ng-include]').text()).toEqual(''); + }); + +
+ */ + + +/** + * @ngdoc event + * @name ng.directive:ngInclude#$includeContentLoaded + * @eventOf ng.directive:ngInclude + * @eventType emit on the current ngInclude scope + * @description + * Emitted every time the ngInclude content is reloaded. + */ +var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile', + function($http, $templateCache, $anchorScroll, $compile) { + return { + restrict: 'ECA', + terminal: true, + compile: function(element, attr) { + var srcExp = attr.ngInclude || attr.src, + onloadExp = attr.onload || '', + autoScrollExp = attr.autoscroll; + + return function(scope, element) { + var changeCounter = 0, + childScope; + + var clearContent = function() { + if (childScope) { + childScope.$destroy(); + childScope = null; + } + + element.html(''); + }; + + scope.$watch(srcExp, function(src) { + var thisChangeId = ++changeCounter; + + if (src) { + $http.get(src, {cache: $templateCache}).success(function(response) { + if (thisChangeId !== changeCounter) return; + + if (childScope) childScope.$destroy(); + childScope = scope.$new(); + + element.html(response); + $compile(element.contents())(childScope); + + if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) { + $anchorScroll(); + } + + childScope.$emit('$includeContentLoaded'); + scope.$eval(onloadExp); + }).error(function() { + if (thisChangeId === changeCounter) clearContent(); + }); + } else clearContent(); + }); + }; + } + }; +}]; + +/** + * @ngdoc directive + * @name ng.directive:ngInit + * + * @description + * The `ngInit` directive specifies initialization tasks to be executed + * before the template enters execution mode during bootstrap. + * + * @element ANY + * @param {expression} ngInit {@link guide/expression Expression} to eval. + * + * @example + + +
+ {{greeting}} {{person}}! +
+
+ + it('should check greeting', function() { + expect(binding('greeting')).toBe('Hello'); + expect(binding('person')).toBe('World'); + }); + +
+ */ +var ngInitDirective = ngDirective({ + compile: function() { + return { + pre: function(scope, element, attrs) { + scope.$eval(attrs.ngInit); + } + } + } +}); + +/** + * @ngdoc directive + * @name ng.directive:ngNonBindable + * @priority 1000 + * + * @description + * Sometimes it is necessary to write code which looks like bindings but which should be left alone + * by angular. Use `ngNonBindable` to make angular ignore a chunk of HTML. + * + * @element ANY + * + * @example + * In this example there are two location where a simple binding (`{{}}`) is present, but the one + * wrapped in `ngNonBindable` is left alone. + * + * @example + + +
Normal: {{1 + 2}}
+
Ignored: {{1 + 2}}
+
+ + it('should check ng-non-bindable', function() { + expect(using('.doc-example-live').binding('1 + 2')).toBe('3'); + expect(using('.doc-example-live').element('div:last').text()). + toMatch(/1 \+ 2/); + }); + +
+ */ +var ngNonBindableDirective = ngDirective({ terminal: true, priority: 1000 }); + +/** + * @ngdoc directive + * @name ng.directive:ngPluralize + * @restrict EA + * + * @description + * # Overview + * `ngPluralize` is a directive that displays messages according to en-US localization rules. + * These rules are bundled with angular.js and the rules can be overridden + * (see {@link guide/i18n Angular i18n} dev guide). You configure ngPluralize directive + * by specifying the mappings between + * {@link http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html + * plural categories} and the strings to be displayed. + * + * # Plural categories and explicit number rules + * There are two + * {@link http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html + * plural categories} in Angular's default en-US locale: "one" and "other". + * + * While a pural category may match many numbers (for example, in en-US locale, "other" can match + * any number that is not 1), an explicit number rule can only match one number. For example, the + * explicit number rule for "3" matches the number 3. You will see the use of plural categories + * and explicit number rules throughout later parts of this documentation. + * + * # Configuring ngPluralize + * You configure ngPluralize by providing 2 attributes: `count` and `when`. + * You can also provide an optional attribute, `offset`. + * + * The value of the `count` attribute can be either a string or an {@link guide/expression + * Angular expression}; these are evaluated on the current scope for its bound value. + * + * The `when` attribute specifies the mappings between plural categories and the actual + * string to be displayed. The value of the attribute should be a JSON object so that Angular + * can interpret it correctly. + * + * The following example shows how to configure ngPluralize: + * + *
+ * 
+ * 
+ *
+ * + * In the example, `"0: Nobody is viewing."` is an explicit number rule. If you did not + * specify this rule, 0 would be matched to the "other" category and "0 people are viewing" + * would be shown instead of "Nobody is viewing". You can specify an explicit number rule for + * other numbers, for example 12, so that instead of showing "12 people are viewing", you can + * show "a dozen people are viewing". + * + * You can use a set of closed braces(`{}`) as a placeholder for the number that you want substituted + * into pluralized strings. In the previous example, Angular will replace `{}` with + * `{{personCount}}`. The closed braces `{}` is a placeholder + * for {{numberExpression}}. + * + * # Configuring ngPluralize with offset + * The `offset` attribute allows further customization of pluralized text, which can result in + * a better user experience. For example, instead of the message "4 people are viewing this document", + * you might display "John, Kate and 2 others are viewing this document". + * The offset attribute allows you to offset a number by any desired value. + * Let's take a look at an example: + * + *
+ * 
+ * 
+ * 
+ * + * Notice that we are still using two plural categories(one, other), but we added + * three explicit number rules 0, 1 and 2. + * When one person, perhaps John, views the document, "John is viewing" will be shown. + * When three people view the document, no explicit number rule is found, so + * an offset of 2 is taken off 3, and Angular uses 1 to decide the plural category. + * In this case, plural category 'one' is matched and "John, Marry and one other person are viewing" + * is shown. + * + * Note that when you specify offsets, you must provide explicit number rules for + * numbers from 0 up to and including the offset. If you use an offset of 3, for example, + * you must provide explicit number rules for 0, 1, 2 and 3. You must also provide plural strings for + * plural categories "one" and "other". + * + * @param {string|expression} count The variable to be bounded to. + * @param {string} when The mapping between plural category to its correspoding strings. + * @param {number=} offset Offset to deduct from the total number. + * + * @example + + + +
+ Person 1:
+ Person 2:
+ Number of People:
+ + + Without Offset: + +
+ + + With Offset(2): + + +
+
+ + it('should show correct pluralized string', function() { + expect(element('.doc-example-live ng-pluralize:first').text()). + toBe('1 person is viewing.'); + expect(element('.doc-example-live ng-pluralize:last').text()). + toBe('Igor is viewing.'); + + using('.doc-example-live').input('personCount').enter('0'); + expect(element('.doc-example-live ng-pluralize:first').text()). + toBe('Nobody is viewing.'); + expect(element('.doc-example-live ng-pluralize:last').text()). + toBe('Nobody is viewing.'); + + using('.doc-example-live').input('personCount').enter('2'); + expect(element('.doc-example-live ng-pluralize:first').text()). + toBe('2 people are viewing.'); + expect(element('.doc-example-live ng-pluralize:last').text()). + toBe('Igor and Misko are viewing.'); + + using('.doc-example-live').input('personCount').enter('3'); + expect(element('.doc-example-live ng-pluralize:first').text()). + toBe('3 people are viewing.'); + expect(element('.doc-example-live ng-pluralize:last').text()). + toBe('Igor, Misko and one other person are viewing.'); + + using('.doc-example-live').input('personCount').enter('4'); + expect(element('.doc-example-live ng-pluralize:first').text()). + toBe('4 people are viewing.'); + expect(element('.doc-example-live ng-pluralize:last').text()). + toBe('Igor, Misko and 2 other people are viewing.'); + }); + + it('should show data-binded names', function() { + using('.doc-example-live').input('personCount').enter('4'); + expect(element('.doc-example-live ng-pluralize:last').text()). + toBe('Igor, Misko and 2 other people are viewing.'); + + using('.doc-example-live').input('person1').enter('Di'); + using('.doc-example-live').input('person2').enter('Vojta'); + expect(element('.doc-example-live ng-pluralize:last').text()). + toBe('Di, Vojta and 2 other people are viewing.'); + }); + +
+ */ +var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interpolate) { + var BRACE = /{}/g; + return { + restrict: 'EA', + link: function(scope, element, attr) { + var numberExp = attr.count, + whenExp = element.attr(attr.$attr.when), // this is because we have {{}} in attrs + offset = attr.offset || 0, + whens = scope.$eval(whenExp), + whensExpFns = {}, + startSymbol = $interpolate.startSymbol(), + endSymbol = $interpolate.endSymbol(); + + forEach(whens, function(expression, key) { + whensExpFns[key] = + $interpolate(expression.replace(BRACE, startSymbol + numberExp + '-' + + offset + endSymbol)); + }); + + scope.$watch(function() { + var value = parseFloat(scope.$eval(numberExp)); + + if (!isNaN(value)) { + //if explicit number rule such as 1, 2, 3... is defined, just use it. Otherwise, + //check it against pluralization rules in $locale service + if (!whens[value]) value = $locale.pluralCat(value - offset); + return whensExpFns[value](scope, element, true); + } else { + return ''; + } + }, function(newVal) { + element.text(newVal); + }); + } + }; +}]; + +/** + * @ngdoc directive + * @name ng.directive:ngRepeat + * + * @description + * The `ngRepeat` directive instantiates a template once per item from a collection. Each template + * instance gets its own scope, where the given loop variable is set to the current collection item, + * and `$index` is set to the item index or key. + * + * Special properties are exposed on the local scope of each template instance, including: + * + * * `$index` – `{number}` – iterator offset of the repeated element (0..length-1) + * * `$first` – `{boolean}` – true if the repeated element is first in the iterator. + * * `$middle` – `{boolean}` – true if the repeated element is between the first and last in the iterator. + * * `$last` – `{boolean}` – true if the repeated element is last in the iterator. + * + * + * @element ANY + * @scope + * @priority 1000 + * @param {repeat_expression} ngRepeat The expression indicating how to enumerate a collection. Two + * formats are currently supported: + * + * * `variable in expression` – where variable is the user defined loop variable and `expression` + * is a scope expression giving the collection to enumerate. + * + * For example: `track in cd.tracks`. + * + * * `(key, value) in expression` – where `key` and `value` can be any user defined identifiers, + * and `expression` is the scope expression giving the collection to enumerate. + * + * For example: `(name, age) in {'adam':10, 'amalie':12}`. + * + * @example + * This example initializes the scope to a list of names and + * then uses `ngRepeat` to display every person: + + +
+ I have {{friends.length}} friends. They are: +
    +
  • + [{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old. +
  • +
+
+
+ + it('should check ng-repeat', function() { + var r = using('.doc-example-live').repeater('ul li'); + expect(r.count()).toBe(2); + expect(r.row(0)).toEqual(["1","John","25"]); + expect(r.row(1)).toEqual(["2","Mary","28"]); + }); + +
+ */ +var ngRepeatDirective = ngDirective({ + transclude: 'element', + priority: 1000, + terminal: true, + compile: function(element, attr, linker) { + return function(scope, iterStartElement, attr){ + var expression = attr.ngRepeat; + var match = expression.match(/^\s*(.+)\s+in\s+(.*)\s*$/), + lhs, rhs, valueIdent, keyIdent; + if (! match) { + throw Error("Expected ngRepeat in form of '_item_ in _collection_' but got '" + + expression + "'."); + } + lhs = match[1]; + rhs = match[2]; + match = lhs.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/); + if (!match) { + throw Error("'item' in 'item in collection' should be identifier or (key, value) but got '" + + lhs + "'."); + } + valueIdent = match[3] || match[1]; + keyIdent = match[2]; + + // Store a list of elements from previous run. This is a hash where key is the item from the + // iterator, and the value is an array of objects with following properties. + // - scope: bound scope + // - element: previous element. + // - index: position + // We need an array of these objects since the same object can be returned from the iterator. + // We expect this to be a rare case. + var lastOrder = new HashQueueMap(); + scope.$watch(function(scope){ + var index, length, + collection = scope.$eval(rhs), + collectionLength = size(collection, true), + childScope, + // Same as lastOrder but it has the current state. It will become the + // lastOrder on the next iteration. + nextOrder = new HashQueueMap(), + key, value, // key/value of iteration + array, last, // last object information {scope, element, index} + cursor = iterStartElement; // current position of the node + + if (!isArray(collection)) { + // if object, extract keys, sort them and use to determine order of iteration over obj props + array = []; + for(key in collection) { + if (collection.hasOwnProperty(key) && key.charAt(0) != '$') { + array.push(key); + } + } + array.sort(); + } else { + array = collection || []; + } + + // we are not using forEach for perf reasons (trying to avoid #call) + for (index = 0, length = array.length; index < length; index++) { + key = (collection === array) ? index : array[index]; + value = collection[key]; + last = lastOrder.shift(value); + if (last) { + // if we have already seen this object, then we need to reuse the + // associated scope/element + childScope = last.scope; + nextOrder.push(value, last); + + if (index === last.index) { + // do nothing + cursor = last.element; + } else { + // existing item which got moved + last.index = index; + // This may be a noop, if the element is next, but I don't know of a good way to + // figure this out, since it would require extra DOM access, so let's just hope that + // the browsers realizes that it is noop, and treats it as such. + cursor.after(last.element); + cursor = last.element; + } + } else { + // new item which we don't know about + childScope = scope.$new(); + } + + childScope[valueIdent] = value; + if (keyIdent) childScope[keyIdent] = key; + childScope.$index = index; + + childScope.$first = (index === 0); + childScope.$last = (index === (collectionLength - 1)); + childScope.$middle = !(childScope.$first || childScope.$last); + + if (!last) { + linker(childScope, function(clone){ + cursor.after(clone); + last = { + scope: childScope, + element: (cursor = clone), + index: index + }; + nextOrder.push(value, last); + }); + } + } + + //shrink children + for (key in lastOrder) { + if (lastOrder.hasOwnProperty(key)) { + array = lastOrder[key]; + while(array.length) { + value = array.pop(); + value.element.remove(); + value.scope.$destroy(); + } + } + } + + lastOrder = nextOrder; + }); + }; + } +}); + +/** + * @ngdoc directive + * @name ng.directive:ngShow + * + * @description + * The `ngShow` and `ngHide` directives show or hide a portion of the DOM tree (HTML) + * conditionally. + * + * @element ANY + * @param {expression} ngShow If the {@link guide/expression expression} is truthy + * then the element is shown or hidden respectively. + * + * @example + + + Click me:
+ Show: I show up when your checkbox is checked.
+ Hide: I hide when your checkbox is checked. +
+ + it('should check ng-show / ng-hide', function() { + expect(element('.doc-example-live span:first:hidden').count()).toEqual(1); + expect(element('.doc-example-live span:last:visible').count()).toEqual(1); + + input('checked').check(); + + expect(element('.doc-example-live span:first:visible').count()).toEqual(1); + expect(element('.doc-example-live span:last:hidden').count()).toEqual(1); + }); + +
+ */ +//TODO(misko): refactor to remove element from the DOM +var ngShowDirective = ngDirective(function(scope, element, attr){ + scope.$watch(attr.ngShow, function(value){ + element.css('display', toBoolean(value) ? '' : 'none'); + }); +}); + + +/** + * @ngdoc directive + * @name ng.directive:ngHide + * + * @description + * The `ngHide` and `ngShow` directives hide or show a portion + * of the HTML conditionally. + * + * @element ANY + * @param {expression} ngHide If the {@link guide/expression expression} truthy then + * the element is shown or hidden respectively. + * + * @example + + + Click me:
+ Show: I show up when you checkbox is checked?
+ Hide: I hide when you checkbox is checked? +
+ + it('should check ng-show / ng-hide', function() { + expect(element('.doc-example-live span:first:hidden').count()).toEqual(1); + expect(element('.doc-example-live span:last:visible').count()).toEqual(1); + + input('checked').check(); + + expect(element('.doc-example-live span:first:visible').count()).toEqual(1); + expect(element('.doc-example-live span:last:hidden').count()).toEqual(1); + }); + +
+ */ +//TODO(misko): refactor to remove element from the DOM +var ngHideDirective = ngDirective(function(scope, element, attr){ + scope.$watch(attr.ngHide, function(value){ + element.css('display', toBoolean(value) ? 'none' : ''); + }); +}); + +/** + * @ngdoc directive + * @name ng.directive:ngStyle + * + * @description + * The `ngStyle` directive allows you to set CSS style on an HTML element conditionally. + * + * @element ANY + * @param {expression} ngStyle {@link guide/expression Expression} which evals to an + * object whose keys are CSS style names and values are corresponding values for those CSS + * keys. + * + * @example + + + + +
+ Sample Text +
myStyle={{myStyle}}
+
+ + span { + color: black; + } + + + it('should check ng-style', function() { + expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)'); + element('.doc-example-live :button[value=set]').click(); + expect(element('.doc-example-live span').css('color')).toBe('rgb(255, 0, 0)'); + element('.doc-example-live :button[value=clear]').click(); + expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)'); + }); + +
+ */ +var ngStyleDirective = ngDirective(function(scope, element, attr) { + scope.$watch(attr.ngStyle, function(newStyles, oldStyles) { + if (oldStyles && (newStyles !== oldStyles)) { + forEach(oldStyles, function(val, style) { element.css(style, '');}); + } + if (newStyles) element.css(newStyles); + }, true); +}); + +/** + * @ngdoc directive + * @name ng.directive:ngSwitch + * @restrict EA + * + * @description + * Conditionally change the DOM structure. + * + * @usageContent + * ... + * ... + * ... + * ... + * + * @scope + * @param {*} ngSwitch|on expression to match against ng-switch-when. + * @paramDescription + * On child elments add: + * + * * `ngSwitchWhen`: the case statement to match against. If match then this + * case will be displayed. + * * `ngSwitchDefault`: the default case when no other casses match. + * + * @example + + + +
+ + selection={{selection}} +
+
+
Settings Div
+ Home Span + default +
+
+
+ + it('should start in settings', function() { + expect(element('.doc-example-live [ng-switch]').text()).toMatch(/Settings Div/); + }); + it('should change to home', function() { + select('selection').option('home'); + expect(element('.doc-example-live [ng-switch]').text()).toMatch(/Home Span/); + }); + it('should select deafault', function() { + select('selection').option('other'); + expect(element('.doc-example-live [ng-switch]').text()).toMatch(/default/); + }); + +
+ */ +var NG_SWITCH = 'ng-switch'; +var ngSwitchDirective = valueFn({ + restrict: 'EA', + compile: function(element, attr) { + var watchExpr = attr.ngSwitch || attr.on, + cases = {}; + + element.data(NG_SWITCH, cases); + return function(scope, element){ + var selectedTransclude, + selectedElement, + selectedScope; + + scope.$watch(watchExpr, function(value) { + if (selectedElement) { + selectedScope.$destroy(); + selectedElement.remove(); + selectedElement = selectedScope = null; + } + if ((selectedTransclude = cases['!' + value] || cases['?'])) { + scope.$eval(attr.change); + selectedScope = scope.$new(); + selectedTransclude(selectedScope, function(caseElement) { + selectedElement = caseElement; + element.append(caseElement); + }); + } + }); + }; + } +}); + +var ngSwitchWhenDirective = ngDirective({ + transclude: 'element', + priority: 500, + compile: function(element, attrs, transclude) { + var cases = element.inheritedData(NG_SWITCH); + assertArg(cases); + cases['!' + attrs.ngSwitchWhen] = transclude; + } +}); + +var ngSwitchDefaultDirective = ngDirective({ + transclude: 'element', + priority: 500, + compile: function(element, attrs, transclude) { + var cases = element.inheritedData(NG_SWITCH); + assertArg(cases); + cases['?'] = transclude; + } +}); + +/** + * @ngdoc directive + * @name ng.directive:ngTransclude + * + * @description + * Insert the transcluded DOM here. + * + * @element ANY + * + * @example + + + +
+
+
+ {{text}} +
+
+ + it('should have transcluded', function() { + input('title').enter('TITLE'); + input('text').enter('TEXT'); + expect(binding('title')).toEqual('TITLE'); + expect(binding('text')).toEqual('TEXT'); + }); + +
+ * + */ +var ngTranscludeDirective = ngDirective({ + controller: ['$transclude', '$element', function($transclude, $element) { + $transclude(function(clone) { + $element.append(clone); + }); + }] +}); + +/** + * @ngdoc directive + * @name ng.directive:ngView + * @restrict ECA + * + * @description + * # Overview + * `ngView` is a directive that complements the {@link ng.$route $route} service by + * including the rendered template of the current route into the main layout (`index.html`) file. + * Every time the current route changes, the included view changes with it according to the + * configuration of the `$route` service. + * + * @scope + * @example + + +
+ Choose: + Moby | + Moby: Ch1 | + Gatsby | + Gatsby: Ch4 | + Scarlet Letter
+ +
+
+ +
$location.path() = {{$location.path()}}
+
$route.current.template = {{$route.current.template}}
+
$route.current.params = {{$route.current.params}}
+
$route.current.scope.name = {{$route.current.scope.name}}
+
$routeParams = {{$routeParams}}
+
+
+ + + controller: {{name}}
+ Book Id: {{params.bookId}}
+
+ + + controller: {{name}}
+ Book Id: {{params.bookId}}
+ Chapter Id: {{params.chapterId}} +
+ + + angular.module('ngView', [], function($routeProvider, $locationProvider) { + $routeProvider.when('/Book/:bookId', { + templateUrl: 'book.html', + controller: BookCntl + }); + $routeProvider.when('/Book/:bookId/ch/:chapterId', { + templateUrl: 'chapter.html', + controller: ChapterCntl + }); + + // configure html5 to get links working on jsfiddle + $locationProvider.html5Mode(true); + }); + + function MainCntl($scope, $route, $routeParams, $location) { + $scope.$route = $route; + $scope.$location = $location; + $scope.$routeParams = $routeParams; + } + + function BookCntl($scope, $routeParams) { + $scope.name = "BookCntl"; + $scope.params = $routeParams; + } + + function ChapterCntl($scope, $routeParams) { + $scope.name = "ChapterCntl"; + $scope.params = $routeParams; + } + + + + it('should load and compile correct template', function() { + element('a:contains("Moby: Ch1")').click(); + var content = element('.doc-example-live [ng-view]').text(); + expect(content).toMatch(/controller\: ChapterCntl/); + expect(content).toMatch(/Book Id\: Moby/); + expect(content).toMatch(/Chapter Id\: 1/); + + element('a:contains("Scarlet")').click(); + content = element('.doc-example-live [ng-view]').text(); + expect(content).toMatch(/controller\: BookCntl/); + expect(content).toMatch(/Book Id\: Scarlet/); + }); + +
+ */ + + +/** + * @ngdoc event + * @name ng.directive:ngView#$viewContentLoaded + * @eventOf ng.directive:ngView + * @eventType emit on the current ngView scope + * @description + * Emitted every time the ngView content is reloaded. + */ +var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$compile', + '$controller', + function($http, $templateCache, $route, $anchorScroll, $compile, + $controller) { + return { + restrict: 'ECA', + terminal: true, + link: function(scope, element, attr) { + var lastScope, + onloadExp = attr.onload || ''; + + scope.$on('$routeChangeSuccess', update); + update(); + + + function destroyLastScope() { + if (lastScope) { + lastScope.$destroy(); + lastScope = null; + } + } + + function clearContent() { + element.html(''); + destroyLastScope(); + } + + function update() { + var locals = $route.current && $route.current.locals, + template = locals && locals.$template; + + if (template) { + element.html(template); + destroyLastScope(); + + var link = $compile(element.contents()), + current = $route.current, + controller; + + lastScope = current.scope = scope.$new(); + if (current.controller) { + locals.$scope = lastScope; + controller = $controller(current.controller, locals); + element.contents().data('$ngControllerController', controller); + } + + link(lastScope); + lastScope.$emit('$viewContentLoaded'); + lastScope.$eval(onloadExp); + + // $anchorScroll might listen on event... + $anchorScroll(); + } else { + clearContent(); + } + } + } + }; +}]; + +/** + * @ngdoc directive + * @name ng.directive:script + * + * @description + * Load content of a script tag, with type `text/ng-template`, into `$templateCache`, so that the + * template can be used by `ngInclude`, `ngView` or directive templates. + * + * @restrict E + * @param {'text/ng-template'} type must be set to `'text/ng-template'` + * + * @example + + + + + Load inlined template +
+
+ + it('should load template defined inside script tag', function() { + element('#tpl-link').click(); + expect(element('#tpl-content').text()).toMatch(/Content of the template/); + }); + +
+ */ +var scriptDirective = ['$templateCache', function($templateCache) { + return { + restrict: 'E', + terminal: true, + compile: function(element, attr) { + if (attr.type == 'text/ng-template') { + var templateUrl = attr.id, + // IE is not consistent, in scripts we have to read .text but in other nodes we have to read .textContent + text = element[0].text; + + $templateCache.put(templateUrl, text); + } + } + }; +}]; + +/** + * @ngdoc directive + * @name ng.directive:select + * @restrict E + * + * @description + * HTML `SELECT` element with angular data-binding. + * + * # `ngOptions` + * + * Optionally `ngOptions` attribute can be used to dynamically generate a list of `