Skip to content

Commit

Permalink
Bake templates into modules
Browse files Browse the repository at this point in the history
  • Loading branch information
enykeev committed Mar 30, 2016
1 parent 6258d4e commit 4376e7e
Show file tree
Hide file tree
Showing 62 changed files with 237 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ npm-debug.log
node_modules
components
css
js
build
dist

.htmlhintrc

Expand Down
4 changes: 3 additions & 1 deletion apps/st2-actions/actions.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict';

var template = require('./template.html');

module.exports = function st2ActionsConfig($stateProvider) {
$stateProvider
.state('actions', {
abstract: true,
url: '/actions',
icon: 'st2-icon__actions',
controller: 'st2ActionsCtrl',
templateUrl: 'apps/st2-actions/template.html',
templateUrl: template,
title: 'Actions',
position: 2
})
Expand Down
9 changes: 5 additions & 4 deletions apps/st2-actions/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

var mod = module.exports = angular.module('main.apps.st2Actions', [

]);

var controller = require('./actions.controller.js');
var config = require('./actions.config.js');

module.exports = angular
.module('main.apps.st2Actions', [

])
mod
.config(config)
.controller(controller.name, controller)
;
4 changes: 3 additions & 1 deletion apps/st2-history/history.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var template = require('./template.html');

module.exports = function st2HistoryConfig($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/history');

Expand All @@ -9,7 +11,7 @@ module.exports = function st2HistoryConfig($stateProvider, $urlRouterProvider) {
url: '/history',
icon: 'st2-icon__history',
controller: 'st2HistoryCtrl',
templateUrl: 'apps/st2-history/template.html',
templateUrl: template,
title: 'History',
position: 1
})
Expand Down
9 changes: 5 additions & 4 deletions apps/st2-history/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';

var mod = module.exports = angular.module('main.apps.st2History', [

]);

var controller = require('./history.controller.js');
var config = require('./history.config.js');
var fmtParam = require('./fmt-param.filter.js');
var isExpandable = require('./is-expandable.filter.js');

module.exports = angular
.module('main.apps.st2History', [

])
mod
.config(config)
.controller(controller.name, controller)
.filter(fmtParam.name, fmtParam)
Expand Down
9 changes: 5 additions & 4 deletions apps/st2-login/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';

var mod = module.exports = angular.module('main.apps.st2Login', [

]);

var controller = require('./login.controller.js');
var config = require('./login.config.js');
var run = require('./login.run.js');

module.exports = angular
.module('main.apps.st2Login', [

])
mod
.config(config)
.controller(controller.name, controller)
.run(run)
Expand Down
4 changes: 3 additions & 1 deletion apps/st2-login/login.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict';

var template = require('./template.html');

module.exports = function st2LoginConfig($stateProvider, $urlRouterProvider) {

$stateProvider
.state('login', {
controller: 'st2LoginCtrl',
templateUrl: 'apps/st2-login/template.html'
templateUrl: template
})
;

Expand Down
9 changes: 5 additions & 4 deletions apps/st2-rules/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';

var mod = module.exports = angular.module('main.apps.st2Rules', [

]);

var controller = require('./rules.controller.js');
var config = require('./rules.config.js');
var run = require('./rules.run.js');

module.exports = angular
.module('main.apps.st2Rules', [

])
mod
.config(config)
.controller(controller.name, controller)
.run(run)
Expand Down
4 changes: 3 additions & 1 deletion apps/st2-rules/rules.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var template = require('./template.html');

module.exports = function st2RulesConfig($stateProvider) {

$stateProvider
Expand All @@ -8,7 +10,7 @@ module.exports = function st2RulesConfig($stateProvider) {
url: '/rules',
icon: 'st2-icon__rules',
controller: 'st2RulesCtrl',
templateUrl: 'apps/st2-rules/template.html',
templateUrl: template,
title: 'Rules',
position: 3
})
Expand Down
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function bundle() {
b
.transform(require('ngify'), {
moduleTemplate: ';',
htmlTemplate: 'module.exports = __dirname + \'/\' + \'{htmlName}\'; angular.module(require(\'.\').name).run([\'$templateCache\', function($templateCache){$templateCache.put(module.exports,\'{html}\')}]); var ignore = { module: {} }; ignore.',
jsTemplates: {
provider: 'module.exports.$inject = [ {inject} ];',
factory: 'module.exports.$inject = [ {inject} ];',
Expand Down Expand Up @@ -123,7 +124,7 @@ function bundle() {
.pipe(header('/* ' + buildHeader() + ' */'))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist/'))
.pipe(gulp.dest('js/'))
.pipe(size({
showFiles: true
}))
Expand Down
6 changes: 1 addition & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@
</script>
<!-- end:reamaze -->

<!-- build:components -->
<script src="node_modules/angular/angular.js"></script>
<!-- endbuild -->
<!-- build:modules -->
<script src="dist/main.js"></script>
<!-- endbuild -->
<script src="js/main.js"></script>
<!-- build:templates -->
<!-- endbuild -->
<script src="config.js"></script>
Expand Down
14 changes: 4 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ angular
require('angular-ui-router'),
require('angular-moment') && 'angularMoment',
require('angular-sanitize'),
require('angular-busy') && 'cgBusy',
require('angular-ui-notification'),
// modules
require('./modules/st2-action-reporter').name,
Expand All @@ -21,20 +20,22 @@ angular
require('./modules/st2-history-child').name,
require('./modules/st2-label').name,
require('./modules/st2-menu').name,
require('./modules/st2-panel').name,
require('./modules/st2-proportional').name,
require('./modules/st2-remote-form').name,
require('./modules/st2-report').name,
require('./modules/st2-scroll-into-view').name,
require('./modules/st2-select-on-click').name,
require('./modules/st2-value-format').name,
require('./modules/st2-view').name,

// apps
require('./apps/st2-actions').name,
require('./apps/st2-history').name,
require('./apps/st2-login').name,
require('./apps/st2-rules').name
]);

])
angular.module('main')
.config(function ($urlRouterProvider) {

// Remove tailing slash from url before looking for state
Expand All @@ -53,13 +54,6 @@ angular

});

angular.module('main')
.value('cgBusyDefaults',{
backdrop: false,
delay: 1000,
templateUrl: 'modules/st2-panel/loader.html'
});

angular.module('main')
.controller('MainCtrl', function ($rootScope, $state, st2FlexTableService) {

Expand Down
25 changes: 3 additions & 22 deletions modules/st2-action-reporter/action-reporter.directive.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
'use strict';

var reporters = require('./reporters');

module.exports =
function st2ActionReporter() {
var reporters = {
'run-local': 'run-local',
'local-shell-cmd': 'run-local',
'run-remote': 'run-remote',
'remote-shell-cmd': 'run-remote',
// 'action-chain': 'action-chain',
// 'workflow': 'action-chain',
// 'mistral-v1': 'action-chain',
// 'mistral-v2': 'action-chain',
'run-local-script': 'run-local',
'local-shell-script': 'run-local',
'run-remote-script': 'run-remote',
'remote-shell-script': 'run-remote',
'run-python': 'run-python',
'python-shell': 'run-python',
// 'http-runner': 'http'
'cloudslang': 'run-local'
};

var linker = function (scope) {
// Partial router
scope.getReporter = function (runner) {
var template = 'modules/st2-action-reporter/reporters/{{ name }}.html';

return template.split('{{ name }}').join(reporters[runner] || 'debug');
return reporters[runner] || reporters['debug'];
};

scope.getTraceback = function (result) {
Expand Down
4 changes: 3 additions & 1 deletion modules/st2-action-reporter/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

var mod = module.exports = angular.module('main.modules.st2ActionReporter', []);

var directive = require('./action-reporter.directive.js');

module.exports = angular.module('main.modules.st2ActionReporter', [])
mod
.directive(directive.name, directive)
;
25 changes: 25 additions & 0 deletions modules/st2-action-reporter/reporters/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

module.exports = {
name: require('..').name
};

module.exports = {
'debug': require('./debug.html'),
'run-local': require('./run-local.html'),
'local-shell-cmd': require('./run-local.html'),
'run-remote': require('./run-remote.html'),
'remote-shell-cmd': require('./run-remote.html'),
// 'action-chain': 'action-chain',
// 'workflow': 'action-chain',
// 'mistral-v1': 'action-chain',
// 'mistral-v2': 'action-chain',
'run-local-script': require('./run-local.html'),
'local-shell-script': require('./run-local.html'),
'run-remote-script': require('./run-remote.html'),
'remote-shell-script': require('./run-remote.html'),
'run-python': require('./run-python.html'),
'python-shell': require('./run-python.html'),
// 'http-runner': 'http'
'cloudslang': require('./run-local.html')
};
4 changes: 3 additions & 1 deletion modules/st2-api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

var mod = module.exports = angular.module('main.modules.st2api', []);

var service = require('./api.service.js');

module.exports = angular.module('main.modules.st2api', [])
mod
.service(service.name, service)
;
4 changes: 3 additions & 1 deletion modules/st2-auto-form/auto-form.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
var _ = require('lodash')
;

var template = require('./template.html');

module.exports =
function st2AutoForm($templateRequest, $compile) {
// TODO: figure out what other fields do we need.
Expand All @@ -25,7 +27,7 @@ module.exports =
}[type];
};

var pTemplate = $templateRequest('modules/st2-auto-form/template.html');
var pTemplate = $templateRequest(template);

return {
restrict: 'C',
Expand Down
23 changes: 12 additions & 11 deletions modules/st2-auto-form/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
'use strict';

var mod = module.exports = angular.module('main.modules.st2AutoForm', [
require('./modules/st2-form-array').name,
require('./modules/st2-form-checkbox').name,
require('./modules/st2-form-combobox').name,
require('./modules/st2-form-input').name,
require('./modules/st2-form-object').name,
require('./modules/st2-form-select').name,
require('./modules/st2-form-text').name,
require('./modules/st2-form-text-field').name
]);

var directive = require('./auto-form.directive.js');

module.exports = angular
.module('main.modules.st2AutoForm', [
require('./modules/st2-form-array').name,
require('./modules/st2-form-checkbox').name,
require('./modules/st2-form-combobox').name,
require('./modules/st2-form-input').name,
require('./modules/st2-form-object').name,
require('./modules/st2-form-select').name,
require('./modules/st2-form-text').name,
require('./modules/st2-form-text-field').name
])
mod
.directive(directive.name, directive)
;
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var template = require('./template.html');

module.exports =
function st2FormArray() {
return {
Expand All @@ -11,7 +13,7 @@ module.exports =
'ngModel': '=',
'disabled': '='
},
templateUrl: 'modules/st2-auto-form/modules/st2-form-array/template.html',
templateUrl: template,
link: function (scope, element, attrs, ctrl) {
scope.name = ctrl.$name;
}
Expand Down
4 changes: 3 additions & 1 deletion modules/st2-auto-form/modules/st2-form-array/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

var mod = module.exports = angular.module('main.modules.st2AutoForm.st2FormArray', []);

var directive = require('./form-array.directive.js');

module.exports = angular.module('main.modules.st2AutoForm.st2FormArray', [])
mod
.directive(directive.name, directive)
;
Loading

0 comments on commit 4376e7e

Please sign in to comment.