pitr/angular-rails-templates — pull request #35 by whitehat101 (2014-04-24 03:27:32+00:00)
Title: One Module Declairation, More Conventional Behavior, and Tighter Templates

In 0.0.7 every rendered template contains this preamble:

window.AngularRailsTemplates || (window.AngularRailsTemplates = angular.module(#{module_name}, []));

I don't like that because it pollutes the global environment, and it adds ~100 characters of unnecessary un-compressible code per template.

---

My pull adds a `angular-rails-templates.js` to the asset pipeline that declares the templates module:

```javascript
// Angular Rails Templates 0.0.7
//
// Ignore Prefix: ignored_namespace/

angular.module("templates", []);
```

I also added comments that can be seen in development and will be removed when compiled for production.

The templates now render as follows:

```javascript
// Angular Rails Templates
// source: app/assets/javascripts/haml_template.nghaml

angular.module("templates").run(["$templateCache",function($templateCache) {
$templateCache.put("haml_template.html", "

I am ast template

\n")
}]);
```

---

My use of the new require reduces the filesize of the asset bundle.

Issue #33 just modified the readme (and incorrectly so). There is no asset named `angular-rails-templates` in version 0.0.7 of the gem. Having a javascript require that is the same name as the gem is highly conventional in Rails asset-related gems.

Having `//= require angular-rails-templates` also prevents the error in issue #28. As long as the user adds the require to their application.js, they can depend on the module in their angular app without errors or having to have a template somewhere in the pipeline. The previous behavior was confusing. Even if everything was setup correctly (except having templates) they would get errors.

There was a typo in the Engine's autoloading code (`:Version => :VERSION`). Since I wanted to display the version in the module declaration asset, I stumbled upon and fixed this bug.

I updated the readme with the new require, and I also provided some more detailed examples to help new users understand what their templateUrls should be.

Since this pull breaks the api (the js manifest require is now mandatory), I recommend a minor version bump (`0.1.0`). I did not touch the version number.