Skip to content

Commit

Permalink
feat(module): new module loader
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Jan 11, 2012
1 parent afd2544 commit 5143e7b
Show file tree
Hide file tree
Showing 211 changed files with 1,051 additions and 1,242 deletions.
23 changes: 23 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ task :compile => [:init, :compile_scenario, :compile_jstd_scenario_adapter] do
--js_output_file #{path_to('angular.min.js')})

FileUtils.cp_r 'i18n/locale', path_to('i18n')

File.open(path_to('angular-loader.js'), 'w') do |f|
concat = 'cat ' + [
'src/loader.prefix',
'src/loader.js',
'src/loader.suffix'].flatten.join(' ')

content = %x{#{concat}}.
gsub('"NG_VERSION_FULL"', NG_VERSION.full).
gsub(/^\s*['"]use strict['"];?\s*$/, '') # remove all file-specific strict mode flags

f.write(content)
end

%x(java -jar lib/closure-compiler/compiler.jar \
--compilation_level SIMPLE_OPTIMIZATIONS \
--language_in ECMASCRIPT5_STRICT \
--js #{path_to('angular-loader.js')} \
--js_output_file #{path_to('angular-loader.min.js')})


end


Expand All @@ -134,7 +155,9 @@ task :package => [:clean, :compile, :docs] do

['src/angular-mocks.js',
path_to('angular.js'),
path_to('angular-loader.js'),
path_to('angular.min.js'),
path_to('angular-loader.min.js'),
path_to('angular-scenario.js'),
path_to('jstd-scenario-adapter.js'),
path_to('jstd-scenario-adapter-config.js'),
Expand Down
1 change: 1 addition & 0 deletions angularFiles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
angularFiles = {
'angularSrc': [
'src/Angular.js',
'src/loader.js',
'src/AngularPublic.js',
'src/JSON.js',
'src/Injector.js',
Expand Down
54 changes: 0 additions & 54 deletions docs/content/api/angular.module.ngdoc

This file was deleted.

91 changes: 18 additions & 73 deletions docs/content/guide/dev_guide.bootstrap.auto_bootstrap.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,88 +2,33 @@
@name Developer Guide: Initializing Angular: Automatic Initialization
@description

Angular initializes automatically when you load the angular script into your page, specifying
angular's `ng:autobind` attribute with no arguments:

<script src="angular.js" ng:autobind>
Angular initializes automatically when you load the angular script into your page that contains an element
with `ng:app` directive:

<html ng:app>
<head>
<script src="angular.js"></script>
</head>
<body>
I can add: {{ 1+2 }}.
</body>
</html>

From a high-level view, this is what happens during angular's automatic initialization process:

1. The browser loads the page, and then runs the angular script.

The `ng:autobind` attribute tells angular to compile and manage the whole HTML document. The
compilation phase is initiated in the page's `onLoad()` handler. Angular doesn't begin processing
the page until after the page load is complete.

2. Angular finds the root of the HTML document and creates the global variable `angular` in the
global namespace. Everything that angular subsequently creates is bound to fields in this global
object.

3. Angular walks the DOM looking for angular widgets, directives, and markup (such as `ng:init` or
`ng:repeat`). As angular encounters these, it creates child scopes as necessary and attaches them
to the DOM, registers listeners on those scopes, associates any controller functions with their
data and their part of the view, and ultimately constructs a runnable application. The resulting
app features two-way data-binding and a nice separation between data, presentation, and business
logic.
1. The browser loads the page, and then runs the angular script. Angular waits for the
`DOMContentLoaded` (or 'Load') event to attempt to bootstrap.

4. For the duration of the application session (while the page is loaded), angular monitors the
state of the application, and updates the view and the data model whenever the state of either one
changes.

For details on how the compiler works, see {@link dev_guide.compiler Angular HTML Compiler}.
2. Angular looks for the `ng:app` directive. If found it then proceeds to compile the DOM element and its children.
Optionally the `ng:app` may specify a {@link api/angular.module module} to load before the compilation. For details on
how the compiler works, see {@link dev_guide.compiler Angular HTML Compiler}.


## Initialization Options

The reason why `ng:autobind` exists is because angular should not assume that the entire HTML
The reason why `ng:app` exists is because angular should not assume that the entire HTML
document should be processed just because the `angular.js` script is included. In order to compile
only a part of the document, specify the ID of the element you want to use for angular's root
element as the value of the `ng:autobind` attribute:

ng:autobind="angularContent"


## Auto-bootstrap with `#autobind`

In some rare cases you can't define the `ng:` prefix before the script tag's attribute (for
example, in some CMS systems). In those situations it is possible to auto-bootstrap angular by
appending `#autobind` to the `<script src=...>` URL, like in this snippet:

<pre>
<!doctype html>
<html>
<head>
<script src="http://code.angularjs.org/angular.js#autobind"></script>
</head>
<body>
<div xmlns:ng="http://angularjs.org">
Hello {{'world'}}!
</div>
</body>
</html>
</pre>

As with `ng:autobind`, you can specify an element id that should be exclusively targeted for
compilation as the value of the `#autobind`, for example: `#autobind=angularContent`.

If angular.js file is being combined with other scripts into a single script file, then all of the
config options above apply to this processed script as well. That means if the contents of
`angular.js` were appended to `all-my-scripts.js`, then the app can be bootstrapped as:

<pre>
<!doctype html>
<html xmlns:ng="http://angularjs.org">
<head>
<script src="http://myapp.com/all-my-scripts.js" ng:autobind></script>
</head>
<body>
<div>
Hello {{'world'}}!
</div>
</body>
</html>
</pre>

only a part of the document set the `ng:app` on the root element of this portion.

## Global Angular Object

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ angular, but advanced users who want more control over the initialization proces
the manual bootstrapping method instead.

The best way to get started with manual bootstrapping is to look at the what happens when you use
{@link api/angular.directive.ng:autobind ng:autobind}, by showing each step of the process
{@link api/angular.directive.ng:app ng:app}, by showing each step of the process
explicitly.

<pre>
Expand Down
8 changes: 4 additions & 4 deletions docs/content/guide/dev_guide.bootstrap.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ angular should process and manage the page. To initialize angular you do the fol

* Specify the angular namespace in the `<html>` page
* Choose which flavor of angular script to load (debug or production)
* Specify whether or not angular should process and manage the page automatically (`ng:autobind`)
* Specify whether or not angular should process and manage the page automatically (`ng:app`)

The simplest way to initialize angular is to load the angular script and tell angular to compile
and manage the whole page. You do this as follows:

<pre>
<!doctype html>
<html xmlns:ng="http://angularjs.org">
<html xmlns:ng="http://angularjs.org" ng:app>
<head>
...
</head>
<body>
...
<script src="angular.js" ng:autobind>
<script src="angular.js">
</body>
</pre>

Expand All @@ -31,7 +31,7 @@ and manage the whole page. You do this as follows:

You need to declare the angular namespace declaration in the following cases:

* For all types of browser if you are using XHTML.
* For all browsers if you are using XHTML.
* For Internet Explorer older than version 9 (because older versions of IE do not render widgets
properly for either HTML or XHTML).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Every {@link api/angular.widget widget}, {@link api/angular.directive directive}
dev_guide.compiler.markup markup} is defined with a compile function, which the angular compiler
executes on each widget or directive it encounters. The compile function optionally returns a link
function. This compilation process happens automatically when the page is loaded when you specify
`ng:autobind` in the script tag from which you load the angular script file. (See {@link
dev_guide.bootstrap Initializing Angular}.)
`ng:app` on the root element of the application. (See {@link dev_guide.bootstrap Initializing Angular}.)

The compile and link functions are related as follows:

Expand Down
2 changes: 1 addition & 1 deletion docs/content/guide/dev_guide.di.understanding_di.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ events:
In the illustration above, the dependency injection sequence proceeds as follows:

1. Service factory functions are registered with angular's service factory repository.
2. `ng:autobind` triggers angular's bootstrap sequence, during which angular compiles the template,
2. `ng:app` triggers angular's bootstrap sequence, during which angular compiles the template,
creates the root scope, and creates the dependency injector.
3. The `ng:controller` directive implicitly creates a new child scope, augmented by the application
of the `PhoneListCtrl` controller function.
Expand Down
4 changes: 2 additions & 2 deletions docs/content/guide/dev_guide.di.using_di_controllers.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ controller from the HTML template, as follows:

<pre>
<!doctype html>
<html xmlns:ng="http://angularjs.org" ng:controller="MyController">
<script src="http://code.angularjs.org/angular.min.js" ng:autobind></script>
<html xmlns:ng="http://angularjs.org" ng:controller="MyController" ng:app>
<script src="http://code.angularjs.org/angular.min.js"></script>
<body>
...
</body>
Expand Down
14 changes: 6 additions & 8 deletions docs/content/guide/dev_guide.forms.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,8 @@ function LoginController() {
}

describe('LoginController', function() {
it('should disable login button when form is invalid', function() {
var scope = angular.module.ng.$rootScope.Scope();
var loginController = scope.$new(LoginController);
it('should disable login button when form is invalid', inject(function($rootScope) {
var loginController = $rootScope.$new(LoginController);

// In production the 'loginForm' form instance gets set from the view,
// but in unit-test we have to set it manually.
Expand All @@ -533,7 +532,7 @@ describe('LoginController', function() {
// Now simulate a valid form
loginController.loginForm.$emit('$valid', 'MyReason');
expect(loginController.disableLogin()).toBe(false);
});
}));
});
</pre>

Expand Down Expand Up @@ -569,9 +568,8 @@ function LoginController(){
}

describe('LoginController', function() {
it('should disable login button when form is invalid', function() {
var scope = angular.module.ng.$rootScope.Scope();
var loginController = scope.$new(LoginController);
it('should disable login button when form is invalid', inject(function($rootScope) {
var loginController = $rootScope.$new(LoginController);
var input = angular.element('<input>');

// In production the 'loginForm' form instance gets set from the view,
Expand Down Expand Up @@ -609,7 +607,7 @@ describe('LoginController', function() {
loginController.password = 'abcdef'; // should be valid
scope.$digest();
expect(loginController.loginForm.password.$valid).toBe(true);
});
}));
});
</pre>

Expand Down
4 changes: 2 additions & 2 deletions docs/content/guide/dev_guide.i18n.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ You can also include the locale specific js file in the index.html page. For exa
requires German locale, you would serve index_de-ge.html which will look something like this:

<pre>
<html>
<html ng:app>
<head>
….
<script src="angular.js" ng:autobind></script>
<script src="angular.js"></script>
<script src="i18n/angular-locale_de-ge.js"></script>
….
</head>
Expand Down
20 changes: 8 additions & 12 deletions docs/content/guide/dev_guide.overview.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,18 @@ easier a web developer's life can if they're using angular:
Try out the Live Preview above, and then let's walk through the example and describe what's going
on.

In the `<html>` tag, we add an attribute to let the browser know about the angular namespace:
In the `<html>` tag, we add an attribute to let the browser know about the angular namespace.
This ensures angular runs nicely in all major browsers. We also specify that it is an angular
application with the `ng:app` directive. The `ng:app' will cause the angular to {@link
dev_guide.bootstrap auto initialize} your application.

<html xmlns:ng="http://angularjs.org">
<html xmlns:ng="http://angularjs.org" ng:app>

This ensures angular runs nicely in all major browsers.
We load the angular using the `<script>` tag:

In the `<script>` tag we do two angular setup tasks:
`<script src="http://code.angularjs.org/0.9.15/angular-0.9.15.min.js"></script>`

1. We load `angular.js`.
2. The angular {@link api/angular.directive.ng:autobind ng:autobind} directive tells angular to
{@link dev_guide.compiler compile} and manage the whole HTML document.

`<script src="http://code.angularjs.org/0.9.15/angular-0.9.15.min.js"
ng:autobind></script>`

From the `name` attribute of the `<input>` tags, angular automatically sets up two-way data
From the `ng:model` attribute of the `<input>` tags, angular automatically sets up two-way data
binding, and we also demonstrate some easy input validation:

Quantity: <input type="integer" min="0" ng:model="qty" required >
Expand Down
4 changes: 2 additions & 2 deletions docs/content/guide/dev_guide.templates.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ angular {@link dev_guide.compiler.directives directives}, {@link dev_guide.compi
and {@link dev_guide.expressions expressions}:

<pre>
<html>
<html ng:app>
<!-- Body tag augmented with ng:controller directive -->
<body ng:controller="MyController">
<input ng:model="foo" value="bar">
<!-- Button tag with ng:click directive, and
string expression 'buttonText'
wrapped in "{{ }}" markup -->
<button ng:click="changeFoo()">{{buttonText}}</button>
<script src="angular.js" ng:autobind>
<script src="angular.js">
</body>
</html>
</pre>
Expand Down
4 changes: 2 additions & 2 deletions docs/content/misc/downloading.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ example points to (non-minified) version 0.9.12:

<pre>
<!doctype html>
<html xmlns:ng="http://angularjs.org">
<html xmlns:ng="http://angularjs.org" ng:app>
<head>
<title>My Angular App</title>
<script src="http://code.angularjs.org/angular-0.9.12.js" ng:autobind></script>
<script src="http://code.angularjs.org/angular-0.9.12.js"></script>
</head>
<body>
</body>
Expand Down
Loading

0 comments on commit 5143e7b

Please sign in to comment.