-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexey Gurianov
committed
May 26, 2015
1 parent
bbd591d
commit 078fc53
Showing
5 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
enb-ng-techs | ||
============== | ||
|
||
[](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(); | ||
}); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |