Skip to content

Commit 04685e9

Browse files
committed
Remove templates needing compiling with gulp
Template dependencies are now loaded through webpack also
1 parent d95d8a2 commit 04685e9

23 files changed

+424
-233
lines changed

dist/angular-schema-form-bootstrap.js

Lines changed: 264 additions & 126 deletions
Large diffs are not rendered by default.

examples/bootstrap-example.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ <h3>Schema</h3>
220220
<script type="text/javascript" src="../bower_components/angular-ui-ace/ui-ace.js"></script>
221221
<script type="text/javascript" src="../bower_components/pickadate/lib/picker.js"></script>
222222
<script type="text/javascript" src="../bower_components/pickadate/lib/picker.date.js"></script>
223-
<script type="text/javascript" src="../bower_components/pickadate/lib/translations/nl_NL.js"></script>
224223

225224
<script type="text/javascript" src="../bower_components/spectrum/spectrum.js"></script>
226225
<script type="text/javascript" src="../bower_components/spectrum/i18n/jquery.spectrum-sv.js"></script>

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
"description": "Bootstrap 3 decorator for Angular Schema Form",
55
"main": "dist/bootstrap-decorator.js",
66
"scripts": {
7-
"templates": "gulp templates",
87
"dist": "npm run build && npm run minify",
98
"build": "webpack",
109
"watch": "webpack --watch",
11-
"minify": "uglifyjs dist/angular-schema-form-material.js --comments --output=dist/angular-schema-form-material.min.js",
10+
"minify": "uglifyjs dist/angular-schema-form-bootstrap.js --comments --output=dist/angular-schema-form-bootstrap.min.js",
1211
"test": "echo \"Error: no test specified\" && exit 1",
1312
"test-not-yet-done": "karma start --single-run --browsers PhantomJS karma.conf.js --log-level info"
1413
},
@@ -41,6 +40,9 @@
4140
"gulp-uglify": "^1.2.0",
4241
"gulp-watch": "^4.2.4",
4342
"gulp-webserver": "^0.9.1",
43+
"html": "^1.0.0",
44+
"html-loader": "^0.4.4",
45+
"html-webpack-plugin": "^2.22.0",
4446
"karma": "^0.13.22",
4547
"karma-chai-sinon": "^0.1.5",
4648
"karma-coverage": "^1.0.0",
@@ -51,6 +53,7 @@
5153
"mocha": "^2.5.3",
5254
"mocha-lcov-reporter": "0.0.1",
5355
"ng-cache-loader": "0.0.16",
56+
"ngtemplate-loader": "^1.3.1",
5457
"protractor": "^2.5.1",
5558
"sinon": "^1.17.4",
5659
"sinon-chai": "^2.8.0",

src/bootstrap-decorator.js

Lines changed: 115 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,131 @@
1-
(function(angular, undefined) {'use strict';
2-
angular
3-
.module('schemaForm')
4-
.config(bootstrapDecoratorConfig)
5-
.filter('sfCamelKey', sfCamelKeyFilter);
1+
// angular-templatecache-loader
2+
let textareaTemplate = require('./bootstrap/textarea.html');
3+
let fieldsetTemplate = require('./bootstrap/fieldset.html');
4+
let arrayTemplate = require('./bootstrap/array.html');
5+
let tabarrayTemplate = require('./bootstrap/tabarray.html');
6+
let tabsTemplate = require('./bootstrap/tabs.html');
7+
let sectionTemplate = require('./bootstrap/section.html');
8+
let actionsTemplate = require('./bootstrap/actions.html');
9+
let selectTemplate = require('./bootstrap/select.html');
10+
let checkboxTemplate = require('./bootstrap/checkbox.html');
11+
let checkboxesTemplate = require('./bootstrap/checkboxes.html');
12+
let submitTemplate = require('./bootstrap/submit.html');
13+
let radiosTemplate = require('./bootstrap/radios.html');
14+
let radiosInlineTemplate = require('./bootstrap/radios-inline.html');
15+
let radiobuttonsTemplate = require('./bootstrap/radio-buttons.html');
16+
let helpTemplate = require('./bootstrap/help.html');
17+
let defaultTemplate = require('./bootstrap/default.html');
618

7-
bootstrapDecoratorConfig.$inject = [
8-
'schemaFormProvider', 'schemaFormDecoratorsProvider', 'sfBuilderProvider', 'sfPathProvider', '$injector'
9-
];
19+
angular
20+
.module('schemaForm')
21+
.config(bootstrapDecoratorConfig)
22+
.filter('sfCamelKey', sfCamelKeyFilter);
1023

11-
function bootstrapDecoratorConfig(
12-
schemaFormProvider, decoratorsProvider, sfBuilderProvider, sfPathProvider, $injector) {
13-
var base = 'decorators/bootstrap/';
24+
bootstrapDecoratorConfig.$inject = [
25+
'schemaFormProvider', 'schemaFormDecoratorsProvider', 'sfBuilderProvider', 'sfPathProvider', '$injector'
26+
];
1427

15-
var simpleTransclusion = sfBuilderProvider.builders.simpleTransclusion;
16-
var ngModelOptions = sfBuilderProvider.builders.ngModelOptions;
17-
var ngModel = sfBuilderProvider.builders.ngModel;
18-
var sfField = sfBuilderProvider.builders.sfField;
19-
var condition = sfBuilderProvider.builders.condition;
20-
var array = sfBuilderProvider.builders.array;
21-
var numeric = sfBuilderProvider.builders.numeric;
28+
function bootstrapDecoratorConfig(
29+
schemaFormProvider, decoratorsProvider, sfBuilderProvider, sfPathProvider, $injector) {
30+
var base = 'decorators/bootstrap/';
2231

23-
// Tabs is so bootstrap specific that it stays here.
24-
var tabs = function(args) {
25-
if (args.form.tabs && args.form.tabs.length > 0) {
26-
var tabContent = args.fieldFrag.querySelector('.tab-content');
32+
var simpleTransclusion = sfBuilderProvider.builders.simpleTransclusion;
33+
var ngModelOptions = sfBuilderProvider.builders.ngModelOptions;
34+
var ngModel = sfBuilderProvider.builders.ngModel;
35+
var sfField = sfBuilderProvider.builders.sfField;
36+
var condition = sfBuilderProvider.builders.condition;
37+
var array = sfBuilderProvider.builders.array;
38+
var numeric = sfBuilderProvider.builders.numeric;
2739

28-
args.form.tabs.forEach(function(tab, index) {
29-
var div = document.createElement('div');
30-
div.className = 'tab-pane';
31-
div.setAttribute('ng-disabled', 'form.readonly');
32-
div.setAttribute('ng-show', 'selected.tab === ' + index);
33-
div.setAttribute('ng-class', '{active: selected.tab === ' + index + '}');
40+
// Tabs is so bootstrap specific that it stays here.
41+
var tabs = function(args) {
42+
if (args.form.tabs && args.form.tabs.length > 0) {
43+
var tabContent = args.fieldFrag.querySelector('.tab-content');
3444

35-
var childFrag = args.build(tab.items, args.path + '.tabs[' + index + '].items', args.state);
36-
div.appendChild(childFrag);
37-
tabContent.appendChild(div);
38-
});
39-
}
40-
};
45+
args.form.tabs.forEach(function(tab, index) {
46+
var evalExpr = '(evalExpr(' + args.path + '.tabs[' + index + ']' +
47+
'.condition, { model: model, "arrayIndex": $index}))';
48+
var div = document.createElement('div');
49+
div.className = 'tab-pane';
50+
div.setAttribute('ng-disabled', 'form.readonly');
51+
div.setAttribute('ng-show', 'selected.tab === ' + index);
52+
div.setAttribute('ng-class', '{active: selected.tab === ' + index + '}');
53+
if(!!tab.condition) {
54+
div.setAttribute('ng-if', evalExpr);
55+
};
4156

42-
var selectPlaceholder = function(args) {
43-
if (args.form.placeholder) {
44-
var selectBox = args.fieldFrag.querySelector('select');
45-
var option = document.createElement('option');
46-
option.setAttribute('value', '');
47-
48-
/* We only want the placeholder to show when we do not have a value on the model.
49-
* We make ngModel builder replace all so we can use $$value$$.
50-
*/
51-
option.setAttribute('sf-field-model', 'replaceAll');
57+
var childFrag = args.build(tab.items, args.path + '.tabs[' + index + '].items', args.state);
58+
div.appendChild(childFrag);
59+
tabContent.appendChild(div);
60+
});
61+
}
62+
};
5263

53-
/* https://github.com/angular/angular.js/issues/12190#issuecomment-115277040
54-
* angular > 1.4 does a emptyOption.attr('selected', true)
55-
* which does not like the ng-if comment.
56-
*/
57-
if (angular.version.major === 1 && angular.version.minor < 4) {
58-
option.setAttribute('ng-if', '$$value$$ === undefined');
59-
} else {
60-
option.setAttribute('ng-show', '$$value$$ === undefined');
61-
}
64+
var selectPlaceholder = function(args) {
65+
if (args.form.placeholder) {
66+
var selectBox = args.fieldFrag.querySelector('select');
67+
var option = document.createElement('option');
68+
option.setAttribute('value', '');
6269

63-
option.textContent = args.form.placeholder;
70+
/* We only want the placeholder to show when we do not have a value on the model.
71+
* We make ngModel builder replace all so we can use $$value$$.
72+
*/
73+
option.setAttribute('sf-field-model', 'replaceAll');
6474

65-
selectBox.appendChild(option);
75+
/* https://github.com/angular/angular.js/issues/12190#issuecomment-115277040
76+
* angular > 1.4 does a emptyOption.attr('selected', true)
77+
* which does not like the ng-if comment.
78+
*/
79+
if (angular.version.major === 1 && angular.version.minor < 4) {
80+
option.setAttribute('ng-if', '$$value$$ === undefined');
81+
} else {
82+
option.setAttribute('ng-show', '$$value$$ === undefined');
6683
}
67-
};
6884

69-
var defaults = [sfField, ngModel, ngModelOptions, condition];
70-
decoratorsProvider.defineDecorator('bootstrapDecorator', {
71-
textarea: {template: base + 'textarea.html', builder: defaults},
72-
fieldset: {template: base + 'fieldset.html', builder: [sfField, simpleTransclusion, condition]},
73-
array: {template: base + 'array.html', builder: [sfField, ngModelOptions, ngModel, array, condition]},
74-
tabarray: {template: base + 'tabarray.html', builder: [sfField, ngModelOptions, ngModel, array, condition]},
75-
tabs: {template: base + 'tabs.html', builder: [sfField, ngModelOptions, tabs, condition]},
76-
section: {template: base + 'section.html', builder: [sfField, simpleTransclusion, condition]},
77-
conditional: {template: base + 'section.html', builder: [sfField, simpleTransclusion, condition]},
78-
actions: {template: base + 'actions.html', builder: defaults},
79-
select: {template: base + 'select.html', builder: defaults.concat(selectPlaceholder)},
80-
checkbox: {template: base + 'checkbox.html', builder: defaults},
81-
checkboxes: {template: base + 'checkboxes.html', builder: [sfField, ngModelOptions, ngModel, array, condition]},
82-
number: {template: base + 'default.html', builder: defaults.concat(numeric)},
83-
password: {template: base + 'default.html', builder: defaults},
84-
submit: {template: base + 'submit.html', builder: defaults},
85-
button: {template: base + 'submit.html', builder: defaults},
86-
radios: {template: base + 'radios.html', builder: defaults},
87-
'radios-inline': {template: base + 'radios-inline.html', builder: defaults},
88-
radiobuttons: {template: base + 'radio-buttons.html', builder: defaults},
89-
help: {template: base + 'help.html', builder: defaults},
90-
'default': {template: base + 'default.html', builder: defaults}
91-
}, []);
85+
option.textContent = args.form.placeholder;
86+
87+
selectBox.appendChild(option);
88+
}
9289
};
9390

94-
/**
95-
* sfCamelKey Filter
96-
*/
97-
function sfCamelKeyFilter() {
98-
return function(formKey) {
99-
if (!formKey) { return ''; };
100-
var part, i, key;
101-
key = formKey.slice();
102-
for (i = 0; i < key.length; i++) {
103-
part = key[i].toLowerCase().split('');
104-
if (i && part.length) { part[0] = part[0].toUpperCase(); };
105-
key[i] = part.join('');
106-
};
107-
return key.join('');
91+
var defaults = [sfField, ngModel, ngModelOptions, condition];
92+
decoratorsProvider.defineDecorator('bootstrapDecorator', {
93+
textarea: {template: textareaTemplate, builder: defaults},
94+
fieldset: {template: fieldsetTemplate, builder: [sfField, simpleTransclusion, condition]},
95+
array: {template: arrayTemplate, builder: [sfField, ngModelOptions, ngModel, array, condition]},
96+
tabarray: {template: tabarrayTemplate, builder: [sfField, ngModelOptions, ngModel, array, condition]},
97+
tabs: {template: tabsTemplate, builder: [sfField, ngModelOptions, tabs, condition]},
98+
section: {template: sectionTemplate, builder: [sfField, simpleTransclusion, condition]},
99+
conditional: {template: sectionTemplate, builder: [sfField, simpleTransclusion, condition]},
100+
actions: {template: actionsTemplate, builder: defaults},
101+
select: {template: selectTemplate, builder: defaults.concat(selectPlaceholder)},
102+
checkbox: {template: checkboxTemplate, builder: defaults},
103+
checkboxes: {template: checkboxesTemplate, builder: [sfField, ngModelOptions, ngModel, array, condition]},
104+
number: {template: defaultTemplate, builder: defaults.concat(numeric)},
105+
password: {template: defaultTemplate, builder: defaults},
106+
submit: {template: submitTemplate, builder: defaults},
107+
button: {template: submitTemplate, builder: defaults},
108+
radios: {template: radiosTemplate, builder: defaults},
109+
'radios-inline': {template: radiosInlineTemplate, builder: defaults},
110+
radiobuttons: {template: radiobuttonsTemplate, builder: defaults},
111+
help: {template: helpTemplate, builder: defaults},
112+
'default': {template: defaultTemplate, builder: defaults}
113+
}, []);
114+
};
115+
116+
/**
117+
* sfCamelKey Filter
118+
*/
119+
function sfCamelKeyFilter() {
120+
return function(formKey) {
121+
if (!formKey) { return ''; };
122+
var part, i, key;
123+
key = formKey.slice();
124+
for (i = 0; i < key.length; i++) {
125+
part = key[i].toLowerCase().split('');
126+
if (i && part.length) { part[0] = part[0].toUpperCase(); };
127+
key[i] = part.join('');
108128
};
129+
return key.join('');
109130
};
110-
111-
})(angular, undefined);
131+
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/tabs.html renamed to src/bootstrap/tabs.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<li ng-repeat="tab in form.tabs"
44
ng-disabled="form.readonly"
55
ng-click="$event.preventDefault() || (selected.tab = $index)"
6-
ng-class="{active: selected.tab === $index}">
6+
ng-class="{active: selected.tab === $index}"
7+
ng-if="(!tab.condition || evalExpr(tab.condition, { model: model, arrayIndex: $index}))">
78
<a href="#">{{ tab.title }}</a>
89
</li>
910
</ul>
File renamed without changes.

src/module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
require('../node_modules/angular-schema-form/dist/schema-form.js');
2-
require('./angular-schema-form-bootstrap-templates.js');
2+
//require('./angular-schema-form-bootstrap-templates.js');
33
//require('./type-parser.js');
4-
require('./bootstrap-decorator.js');
4+
require('bootstrap-decorator.js');

webpack.config.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,62 @@
11
/* global __dirname */
2-
var webpack = require('webpack');
3-
var path = require('path');
4-
var pjson = require('./package.json');
2+
const webpack = require('webpack');
3+
const path = require('path');
4+
//const ngAnnotatePlugin = require('ng-annotate-webpack-plugin');
5+
const HtmlWebpackPlugin = require('html-webpack-plugin');
6+
//const ExtractTextPlugin = require('extract-text-webpack-plugin');
7+
const getPath = (pathToFile) => path.resolve(__dirname, pathToFile);
8+
const pjson = require('./package.json');
59
console.log('Angular Schema Form Bootstrap v' + pjson.version);
610

711
module.exports = {
812
entry: './src/module.js',
13+
// entry: {
14+
// schema_form_decorators: [
15+
// getPath('./src/bootstrap-decorator.js'),
16+
// ]
17+
// // ,
18+
// // app: [
19+
// // getPath('./src/app.js'),
20+
// // getPath('./src/config/dev.config.js')
21+
// // ]
22+
// },
923
output: {
10-
path: path.join(__dirname, 'dist'),
24+
path: getPath('./dist'),
1125
filename: 'angular-schema-form-bootstrap.js',
26+
sourceMapFilename: '[name].map',
1227
libraryTarget: 'umd'
1328
},
14-
resolve: { extensions: [ '', '.js', '.html' ] },
29+
resolve: {
30+
modulesDirectories: [
31+
'node_modules', 'src'
32+
],
33+
extensions: [ '', '.js', '.html' ]
34+
},
1535
module: {
1636
loaders: [
1737
{
1838
test: /\.js$/,
1939
include: [ path.join(__dirname, 'src') ],
40+
exclude: /(node_modules)/,
2041
loader: 'babel',
2142
},
22-
{ test: /\.html$/, loader: "ng-cache?prefix=decorators/bootstrap" }
43+
{
44+
test: /\.html$/,
45+
loader: 'ngtemplate?relativeTo=' + path.join(__dirname, 'src') + '/!html',
46+
exclude: /(index)/
47+
}
2348
]
2449
},
2550
externals: {
2651
'angular': 'var angular',
2752
'tv4': 'var tv4',
2853
},
2954
plugins: [
55+
new webpack.optimize.AggressiveMergingPlugin({}),
56+
new webpack.optimize.OccurenceOrderPlugin(true),
57+
// new HtmlWebpackPlugin({
58+
// template: 'html!./src/index.html'
59+
// }),
3060
new webpack.BannerPlugin(
3161
'angular-schema-form-bootstrap\n' +
3262
'@version ' +

0 commit comments

Comments
 (0)