Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit 14c348a

Browse files
committed
added build process and dist folder
1 parent e73f78f commit 14c348a

File tree

7 files changed

+224
-31
lines changed

7 files changed

+224
-31
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ node_modules
1717
bower_components
1818
*.sublime-workspace
1919
# build folder
20-
.grunt
20+
.grunt
21+
.tmp

Gruntfile.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,86 @@ module.exports = function(grunt) {
1818
base: 'src'
1919
},
2020
src: ['**']
21+
},
22+
clean: {
23+
build: ['.tmp/**/*', 'dist/**/*']
24+
},
25+
copy: {
26+
build: {
27+
files: [
28+
{
29+
expand: true,
30+
cwd: 'src/',
31+
src: ['directives/formly*.*', 'modules/formly*.*', '!.jshintrc'],
32+
dest: '.tmp/'
33+
}
34+
]
35+
},
36+
deploy: {
37+
files: [{
38+
expand: true,
39+
cwd: '.tmp',
40+
src: ['formly.js', 'formly.min.js', 'formly.min.map'],
41+
dest: 'dist/'
42+
}]
43+
}
44+
},
45+
concat: {
46+
build: {
47+
// specifing files so that they are added in this order
48+
src: ['.tmp/modules/formly*.js', '.tmp/directives/formly*.js', '.tmp/formly*.js'],
49+
dest: '.tmp/formly.js'
50+
}
51+
},
52+
uglify: {
53+
build: {
54+
src: '.tmp/formly.js',
55+
dest: '.tmp/formly.min.js'
56+
},
57+
options: {
58+
mangle: true,
59+
sourceMap: true
60+
}
61+
},
62+
ngtemplates: {
63+
build: {
64+
cwd: '.tmp/',
65+
src: [
66+
'**/formly*.html'
67+
],
68+
dest: '.tmp/formly-templates.js',
69+
options: {
70+
module: 'formly.render',
71+
htmlmin: {
72+
collapseBooleanAttributes: true,
73+
collapseWhitespace: true,
74+
removeAttributeQuotes: true,
75+
removeComments: true, // Only if you don't use comment directives!
76+
removeEmptyAttributes: true,
77+
removeRedundantAttributes: true,
78+
removeScriptTypeAttributes: true,
79+
removeStyleLinkTypeAttributes: true
80+
}
81+
}
82+
}
83+
},
84+
ngmin: {
85+
build: {
86+
src: '.tmp/formly.js',
87+
dest: '.tmp/formly.js'
88+
}
2189
}
2290
});
2391

2492
// Load the plugin that provides the "uglify" task.
93+
grunt.loadNpmTasks('grunt-contrib-concat');
2594
grunt.loadNpmTasks('grunt-contrib-connect');
95+
grunt.loadNpmTasks('grunt-contrib-copy');
96+
grunt.loadNpmTasks('grunt-contrib-clean');
97+
grunt.loadNpmTasks('grunt-contrib-uglify');
2698
grunt.loadNpmTasks('grunt-gh-pages');
99+
grunt.loadNpmTasks('grunt-angular-templates');
100+
grunt.loadNpmTasks('grunt-ngmin');
27101

28102
grunt.registerTask('publish', [
29103
'gh-pages'
@@ -32,4 +106,14 @@ module.exports = function(grunt) {
32106
grunt.registerTask('dev', [
33107
'connect:dev'
34108
]);
109+
110+
grunt.registerTask('build', [
111+
'clean:build',
112+
'copy:build',
113+
'ngtemplates:build',
114+
'concat:build',
115+
'ngmin:build',
116+
'uglify:build',
117+
'copy:deploy'
118+
]);
35119
};

dist/formly.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Render module for formly to display forms
2+
angular.module('formly.render', []);
3+
// Main Formly Module
4+
angular.module('formly', ['formly.render']);
5+
'use strict';
6+
angular.module('formly.render').directive('formlyField', [
7+
'$http',
8+
'$compile',
9+
function formlyField($http, $compile) {
10+
var getTemplateUrl = function (type) {
11+
var templateUrl = '';
12+
switch (type) {
13+
case 'textarea':
14+
templateUrl = 'directives/formly-field-textarea.html';
15+
break;
16+
case 'radio':
17+
templateUrl = 'directives/formly-field-radio.html';
18+
break;
19+
case 'select':
20+
templateUrl = 'directives/formly-field-select.html';
21+
break;
22+
case 'number':
23+
templateUrl = 'directives/formly-field-number.html';
24+
break;
25+
case 'checkbox':
26+
templateUrl = 'directives/formly-field-checkbox.html';
27+
break;
28+
case 'password':
29+
templateUrl = 'directives/formly-field-password.html';
30+
break;
31+
case 'hidden':
32+
templateUrl = 'directives/formly-field-hidden.html';
33+
break;
34+
case 'email':
35+
templateUrl = 'directives/formly-field-email.html';
36+
break;
37+
case 'text':
38+
templateUrl = 'directives/formly-field-text.html';
39+
break;
40+
default:
41+
templateUrl = null;
42+
break;
43+
}
44+
return templateUrl;
45+
};
46+
return {
47+
restrict: 'AE',
48+
transclude: true,
49+
scope: {
50+
optionsData: '&options',
51+
formId: '@formId',
52+
index: '@index',
53+
value: '=formValue'
54+
},
55+
link: function fieldLink($scope, $element, $attr) {
56+
var templateUrl = getTemplateUrl($scope.options.type);
57+
if (templateUrl) {
58+
$http.get(templateUrl).success(function (data) {
59+
//template data returned
60+
$element.html(data);
61+
$compile($element.contents())($scope);
62+
});
63+
} else {
64+
console.log('Formly Error: template type \'' + $scope.options.type + '\' not supported.');
65+
}
66+
},
67+
controller: [
68+
'$scope',
69+
function fieldController($scope) {
70+
$scope.options = $scope.optionsData();
71+
if ($scope.options.default) {
72+
$scope.value = $scope.options.default;
73+
}
74+
// set field id to link labels and fields
75+
$scope.id = $scope.formId + $scope.options.type + $scope.index;
76+
}
77+
]
78+
};
79+
}
80+
]);
81+
'use strict';
82+
angular.module('formly.render').directive('formlyForm', function formlyForm() {
83+
return {
84+
restrict: 'AE',
85+
templateUrl: 'directives/formly-form.html',
86+
replace: true,
87+
scope: {
88+
formId: '@formId',
89+
fields: '=fields',
90+
options: '=options',
91+
result: '=result'
92+
},
93+
controller: [
94+
'$scope',
95+
'$element',
96+
function formController($scope, $element) {
97+
$scope.populateResult = function () {
98+
var formChildren = $element.children();
99+
var fieldScope;
100+
angular.forEach(formChildren, function (field, key) {
101+
// grab fields isolate scope
102+
fieldScope = angular.element(field).scope();
103+
$scope.result[fieldScope.$index] = fieldScope.value;
104+
});
105+
};
106+
}
107+
]
108+
};
109+
});
110+
angular.module('formly.render').run([
111+
'$templateCache',
112+
function ($templateCache) {
113+
'use strict';
114+
$templateCache.put('directives/formly-field-checkbox.html', '<div class=checkbox><label><input type=checkbox ng-required=options.required ng-disabled=options.disabled ng-model=value>{{options.label || \'Checkbox\'}} {{options.required ? \'*\' : \'\'}}</label></div>');
115+
$templateCache.put('directives/formly-field-email.html', '<div class=form-group><label for={{id}}>{{options.label || \'Email\'}} {{options.required ? \'*\' : \'\'}}</label><input type=email class=form-control id={{id}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled ng-model=value></div>');
116+
$templateCache.put('directives/formly-field-hidden.html', '<input type=hidden ng-model=value>');
117+
$templateCache.put('directives/formly-field-number.html', '<div class=form-group><label for={{id}}>{{options.label || \'Number\'}} {{options.required ? \'*\' : \'\'}}</label><input type=number class=form-control id={{id}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled min={{options.min}} max={{options.max}} ng-minlength={{options.minlength}} ng-maxlength={{options.maxlength}} ng-model=value></div>');
118+
$templateCache.put('directives/formly-field-password.html', '<div class=form-group><label for={{id}}>{{options.label || \'Password\'}} {{options.required ? \'*\' : \'\'}}</label><input type=password class=form-control id={{id}} ng-required=options.required ng-disabled=options.disabled ng-model=value></div>');
119+
$templateCache.put('directives/formly-field-radio.html', '<div class=radio-group><label class=control-label>{{options.label}} {{options.required ? \'*\' : \'\'}}</label><div class=radio ng-repeat="(key, option) in options.options"><label><input type=radio name={{id}} id="{{id + \'_\'+ $index}}" ng-value=option.value ng-model=$parent.value>{{option.name}}</label></div></div>');
120+
$templateCache.put('directives/formly-field-select.html', '<div class=form-group><label for={{id}}>{{options.label || \'Select\'}} {{options.required ? \'*\' : \'\'}}</label><select class=form-control id={{id}} ng-model=value ng-required=options.required ng-disabled=options.disabled ng-options="option.name group by option.group for option in options.options"></select></div>');
121+
$templateCache.put('directives/formly-field-text.html', '<div class=form-group><label for={{id}}>{{options.label || \'Text\'}} {{options.required ? \'*\' : \'\'}}</label><input class=form-control id={{id}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled ng-model=value></div>');
122+
$templateCache.put('directives/formly-field-textarea.html', '<div class=form-group><label for={{id}}>{{options.label || \'Text\'}} {{options.required ? \'*\' : \'\'}}</label><textarea type=text class=form-control id={{id}} rows={{options.lines}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled ng-model=value>\n' + '\t</textarea></div>');
123+
$templateCache.put('directives/formly-field.html', '');
124+
$templateCache.put('directives/formly-form.html', '<form class=formly role=form name={{options.uniqueFormId}}><formly-field ng-repeat="field in fields" options=field form-value=value form-id={{options.uniqueFormId}} index={{$index}}></formly-field><button type=submit ng-click=populateResult()>{{options.submitCopy || "Submit"}}</button></form>');
125+
}
126+
]);

dist/formly.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/formly.min.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,18 @@
22
"name": "angular-formly",
33
"version": "0.0.1",
44
"build": 0,
5-
"scripts": {
6-
"start": "node server.js"
7-
},
8-
"engines": {
9-
"node": "0.10.x",
10-
"npm": "1.3.x"
11-
},
12-
"dependencies": {
5+
"devDependencies": {
6+
"grunt-gh-pages": "~0.9.0",
137
"bower": "1.2.7",
148
"grunt": "~0.4.1",
159
"grunt-bower-task": "~0.3.4",
1610
"grunt-cli": "~0.1.11",
17-
"grunt-nodemon": "~0.2.0",
18-
"express": "~3.4.8",
19-
"grunt-contrib-connect": "~0.6.0"
20-
},
21-
"devDependencies": {
22-
"grunt-gh-pages": "~0.9.0"
11+
"grunt-contrib-connect": "~0.6.0",
12+
"grunt-contrib-concat": "~0.3.0",
13+
"grunt-angular-templates": "~0.5.1",
14+
"grunt-ngmin": "0.0.3",
15+
"grunt-contrib-copy": "~0.5.0",
16+
"grunt-contrib-clean": "~0.5.0",
17+
"grunt-contrib-uglify": "~0.3.2"
2318
}
2419
}

server.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)