Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
esvit committed Oct 27, 2013
0 parents commit 763d0fd
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"directory": "bower_components",
"json": "bower.json"
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.temp
.idea
node_modules
bower_components
out
48 changes: 48 additions & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
path = require 'path'

# Build configurations.
module.exports = (grunt) ->
grunt.initConfig
cmpnt: grunt.file.readJSON('bower.json'),
banner: '/*! ngTableExport v<%= cmpnt.version %> by Vitalii Savchuk([email protected]) - ' +
'https://github.com/esvit/ng-table-export - New BSD License */\n',

# Deletes built file and temp directories.
clean:
working:
src: [
'ng-table.*'
'./.temp/views'
'./.temp/'
]

uglify:
# concat js files before minification
js:
src: ['ng-table-export.src.js']
dest: 'ng-table-export.js'
options:
banner: '<%= banner %>'
sourceMap: (fileName) ->
fileName.replace /\.js$/, '.map'
concat:
# concat js files before minification
js:
src: [
'src/scripts/*.js'
]
dest: 'ng-table-export.src.js'

grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-contrib-copy'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-contrib-concat'

grunt.registerTask 'dev', [
'clean'
'concat'
]
grunt.registerTask 'default', [
'dev'
'uglify'
]
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Copyright (c) 2013, esvit.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the esvit nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Export to CSV format for table
==============================

Code licensed under New BSD License.

## Installing via Bower
```
bower install ng-table-export
```

## Example

* [ngTable export to CSV](http://bazalt-cms.com/ng-table/example/15)
13 changes: 13 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "ng-table-export",
"version": "0.1.0",
"main": [
"ng-table-export.js"
],
"ignore": [
"src"
],
"dependencies": {
"angular": ">=1.2.0-rc.2"
}
}
3 changes: 3 additions & 0 deletions ng-table-export.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ng-table-export.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions ng-table-export.src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
angular.module('ngTableExport', [])
.directive('exportCsv', function ($parse) {
return {
restrict: 'A',
scope: false,
link: function(scope, element, attrs) {
var data = '';
var csv = {
stringify: function(str) {
return '"' +
str.replace(/^\s\s*/, '').replace(/\s*\s$/, '') // trim spaces
.replace(/"/g,'""') + // replace quotes with double quotes
'"';
},
generate: function() {
data = '';
var rows = element.find('tr');
angular.forEach(rows, function(row, i) {
var tr = angular.element(row),
tds = tr.find('th'),
rowData = '';
if (tr.hasClass('ng-table-filters')) {
return;
}
if (tds.length == 0) {
tds = tr.find('td');
}
if (i != 1) {
angular.forEach(tds, function(td, i) {
rowData += csv.stringify(angular.element(td).text()) + ';';
});
rowData = rowData.slice(0, rowData.length - 1); //remove last semicolon
}
data += rowData + "\n";
});
},
link: function() {
return 'data:text/csv;charset=UTF-8,' + encodeURIComponent(data);
}
};
$parse(attrs.exportCsv).assign(scope.$parent, csv);
}
};
});
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "ng-table-export",
"version": "0.1.0",
"author": "Vitalii Savchuk <[email protected]>",
"license": "BSD",
"repository": {
"type": "git",
"url": "git://github.com/esvit/ng-table-export.git"
},
"devDependencies": {
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-requirejs": "~0.4.0",
"grunt-contrib-uglify": "~0.2.1",
"grunt": "~0.4.1"
}
}
44 changes: 44 additions & 0 deletions src/scripts/00-directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
angular.module('ngTableExport', [])
.directive('exportCsv', function ($parse) {
return {
restrict: 'A',
scope: false,
link: function(scope, element, attrs) {
var data = '';
var csv = {
stringify: function(str) {
return '"' +
str.replace(/^\s\s*/, '').replace(/\s*\s$/, '') // trim spaces
.replace(/"/g,'""') + // replace quotes with double quotes
'"';
},
generate: function() {
data = '';
var rows = element.find('tr');
angular.forEach(rows, function(row, i) {
var tr = angular.element(row),
tds = tr.find('th'),
rowData = '';
if (tr.hasClass('ng-table-filters')) {
return;
}
if (tds.length == 0) {
tds = tr.find('td');
}
if (i != 1) {
angular.forEach(tds, function(td, i) {
rowData += csv.stringify(angular.element(td).text()) + ';';
});
rowData = rowData.slice(0, rowData.length - 1); //remove last semicolon
}
data += rowData + "\n";
});
},
link: function() {
return 'data:text/csv;charset=UTF-8,' + encodeURIComponent(data);
}
};
$parse(attrs.exportCsv).assign(scope.$parent, csv);
}
};
});

0 comments on commit 763d0fd

Please sign in to comment.