Skip to content

Commit

Permalink
Initial version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Gurianov committed May 26, 2015
1 parent bbd591d commit 078fc53
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
node_modules
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
enb-ng-techs
==============

[![NPM version](https://img.shields.io/npm/v/enb-ng-techs.svg?style=flat)](https://www.npmjs.org/package/enb-ng-techs)

Useful ENB technologies to build angular projects.

Installation:
----------

```sh
$ npm install --save-dev enb-ng-techs
```

Techs
----------

* `ng-annotate` - adds AngularJS dependency injection annotations using [`ng-annotate`](https://github.com/olov/ng-annotate)
* `ng-templates` - combines `*.tmpl.html` files in single partial which can be loaded and compiled by Angular in runtime

ng-annotate
==========

Takes js file provided by `source` option and writes annotated result to file provided by `target` option.

**Options**

* *String* **source** — file-target to annotate.
* *String* **target** — file-target to write annotated output.

**Example**

```javascript
nodeConfig.addTech(require('enb-ng-techs/techs/ng-annotate'), {
source : '?.pre.js',
target : '?.annotated.js'
});
```

ng-templates
==========

Combines `*.tmpl.html` files by deps wrapping them out with `<script type="text/ng-template">` tag and filename as `id`.
You should fetch this file and compile it in your app using $compile service before any call to templates occurred.

**Опции**

* *String* **target** — Output target. Default — `?.tmpl.html`.

**Example**

```javascript
nodeConfig.addTech(require('enb-ng-techs/techs/ng-templates'));
```

Use this snippet in project based on `ui-router` to fetch and compile templates.

```javascript
angular.module('ngApp')
.run(function($http, $compile, $urlRouter, $rootScope){
// make a chance to load templates before state change
var un = $rootScope.$on('$stateChangeStart', function (event) {
event.preventDefault();
});

// get and compile templates
$http.get('ngapp.tmpl.html')
.then(function(response){
response.data.length &&
$compile(response.data);
// now we can safely set an state
un();
$urlRouter.sync();
});
});
```
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"author": "Alexey Gurianov <[email protected]>",
"description": "Useful ENB technologies to build angular projects",
"name": "enb-ng-techs",
"version": "0.1.0",
"repository": {
"type": "git",
"url": "https://github.com/bem-incubator/enb-ng-techs.git"
},
"homepage": "https://github.com/bem-incubator/enb-ng-techs",
"bugs": {
"url": "https://github.com/bem-incubator/enb-ng-techs/issues"
},
"license": "MIT",
"keywords": [
"enb",
"enb-make",
"angular",
"ng",
"ng-bem",
"bem"
],
"peerDependencies": {
"enb": "^0.15.0"
},
"devDependencies": {
"enb": "^0.15.0",
"ng-annotate": "^0.15.4"
}
}
32 changes: 32 additions & 0 deletions techs/ng-annotate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* ng-annotate
* ==========
*
* Takes js file provided by `source` option and writes annotated result to file provided by `target` option.
*
* **Options**
*
* * *String* **source** — file-target to annotate.
* * *String* **target** — file-target to write annotated output.
*
* **Example**
*
* ```javascript
* nodeConfig.addTech(require('enb-ng-techs/techs/ng-annotate'), {
* source : '?.pre.js',
* target : '?.annotated.js'
* });
* ```
*/

var ngAnnotate = require("ng-annotate");
module.exports = require('enb/lib/build-flow').create()
.name('ng-annotate')
.defineOption('target')
.target('target', '?.js')
.defineRequiredOption('source')
.useSourceText('source')
.builder(function(source){
return ngAnnotate(source, { add : true }).src;
})
.createTech();
50 changes: 50 additions & 0 deletions techs/ng-templates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* ng-templates
* ==========
*
* Combines `*.tmpl.html` files by deps wrapping them out with `<script type="text/ng-template">` tag and filename as `id`.
* You should fetch this file and compile it in your app using $compile service before any call to templates occurred.
*
* **Опции**
*
* * *String* **target** — Output target. Default — `?.tmpl.html`.
*
* **Example**
*
* ```javascript
* nodeConfig.addTech(require('enb-ng-techs/techs/ng-templates'));
* ```
*
* Use this snippet in project based on `ui-router` to fetch and compile templates.
*
* ```javascript
* angular.module('ngApp')
* .run(function($http, $compile, $urlRouter, $rootScope){
* // make a chance to load templates before state change
* var un = $rootScope.$on('$stateChangeStart', function (event) {
* event.preventDefault();
* });
*
* // get and compile templates
* $http.get('ngapp.tmpl.html')
* .then(function(response){
* response.data.length &&
* $compile(response.data);
* // now we can safely set an state
* un();
* $urlRouter.sync();
* });
* });
* ```
*/
var path = require('path');

module.exports = require('enb/lib/build-flow').create()
.name('ng-templates')
.defineOption('target')
.target('target', '?.tmpl.html')
.useFileList(['tmpl.html'])
.justJoinFiles(function (filename, data) {
return '<script type="text/ng-template" id="' + filename.split(path.sep).pop() + '">\n' + data + '\n</script>';
})
.createTech();

0 comments on commit 078fc53

Please sign in to comment.