filesaverjs-rails 1.1.20150716

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 986afed5b09f344771bdf59da21fcc11c0102b74
4
+ data.tar.gz: 28fcadb691aea4519d3a582e74f99f4898e3cfe0
5
+ SHA512:
6
+ metadata.gz: 077fa1f97f4f393ca1b09c405a0d66af6ea88b5216046aca184dbf917ca891dea276eee5f0b07aa03d7f29b0d7339c20c8844ba76b038498b5dc971f9d7439ec
7
+ data.tar.gz: 09797b26460bfa7bf6205f5592465f94963dde2dda4fa881d5f5d185f465e70033666b0a2765663b69f3ed4fe5aec8fea6de21cd1c8e33e29503430a4650cbda
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Dinesh Sawant
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Filesaverjs::Rails
2
+
3
+ filesaverjs-rails is a simple gem to add FileSaver.js vendor file to Rails asset pipeline.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'filesaverjs-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install filesaverjs-rails
20
+
21
+ ## Usage
22
+
23
+ Add this to application.js:
24
+
25
+ //= require FileSaver
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dinsaw/filesaverjs-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,8 @@
1
+ require "filesaverjs/rails/version"
2
+
3
+ module Filesaverjs
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Filesaverjs
2
+ module Rails
3
+ VERSION = "1.1.20150716"
4
+ end
5
+ end
@@ -0,0 +1,256 @@
1
+ /* FileSaver.js
2
+ * A saveAs() FileSaver implementation.
3
+ * 1.1.20150716
4
+ *
5
+ * By Eli Grey, http://eligrey.com
6
+ * License: X11/MIT
7
+ * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
8
+ */
9
+
10
+ /*global self */
11
+ /*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
12
+
13
+ /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
14
+
15
+ var saveAs = saveAs || (function(view) {
16
+ "use strict";
17
+ // IE <10 is explicitly unsupported
18
+ if (typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
19
+ return;
20
+ }
21
+ var
22
+ doc = view.document
23
+ // only get URL when necessary in case Blob.js hasn't overridden it yet
24
+ , get_URL = function() {
25
+ return view.URL || view.webkitURL || view;
26
+ }
27
+ , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
28
+ , can_use_save_link = "download" in save_link
29
+ , click = function(node) {
30
+ var event = new MouseEvent("click");
31
+ node.dispatchEvent(event);
32
+ }
33
+ , webkit_req_fs = view.webkitRequestFileSystem
34
+ , req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
35
+ , throw_outside = function(ex) {
36
+ (view.setImmediate || view.setTimeout)(function() {
37
+ throw ex;
38
+ }, 0);
39
+ }
40
+ , force_saveable_type = "application/octet-stream"
41
+ , fs_min_size = 0
42
+ // See https://code.google.com/p/chromium/issues/detail?id=375297#c7 and
43
+ // https://github.com/eligrey/FileSaver.js/commit/485930a#commitcomment-8768047
44
+ // for the reasoning behind the timeout and revocation flow
45
+ , arbitrary_revoke_timeout = 500 // in ms
46
+ , revoke = function(file) {
47
+ var revoker = function() {
48
+ if (typeof file === "string") { // file is an object URL
49
+ get_URL().revokeObjectURL(file);
50
+ } else { // file is a File
51
+ file.remove();
52
+ }
53
+ };
54
+ if (view.chrome) {
55
+ revoker();
56
+ } else {
57
+ setTimeout(revoker, arbitrary_revoke_timeout);
58
+ }
59
+ }
60
+ , dispatch = function(filesaver, event_types, event) {
61
+ event_types = [].concat(event_types);
62
+ var i = event_types.length;
63
+ while (i--) {
64
+ var listener = filesaver["on" + event_types[i]];
65
+ if (typeof listener === "function") {
66
+ try {
67
+ listener.call(filesaver, event || filesaver);
68
+ } catch (ex) {
69
+ throw_outside(ex);
70
+ }
71
+ }
72
+ }
73
+ }
74
+ , auto_bom = function(blob) {
75
+ // prepend BOM for UTF-8 XML and text/* types (including HTML)
76
+ if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
77
+ return new Blob(["\ufeff", blob], {type: blob.type});
78
+ }
79
+ return blob;
80
+ }
81
+ , FileSaver = function(blob, name, no_auto_bom) {
82
+ if (!no_auto_bom) {
83
+ blob = auto_bom(blob);
84
+ }
85
+ // First try a.download, then web filesystem, then object URLs
86
+ var
87
+ filesaver = this
88
+ , type = blob.type
89
+ , blob_changed = false
90
+ , object_url
91
+ , target_view
92
+ , dispatch_all = function() {
93
+ dispatch(filesaver, "writestart progress write writeend".split(" "));
94
+ }
95
+ // on any filesys errors revert to saving with object URLs
96
+ , fs_error = function() {
97
+ // don't create more object URLs than needed
98
+ if (blob_changed || !object_url) {
99
+ object_url = get_URL().createObjectURL(blob);
100
+ }
101
+ if (target_view) {
102
+ target_view.location.href = object_url;
103
+ } else {
104
+ var new_tab = view.open(object_url, "_blank");
105
+ if (new_tab == undefined && typeof safari !== "undefined") {
106
+ //Apple do not allow window.open, see http://bit.ly/1kZffRI
107
+ view.location.href = object_url
108
+ }
109
+ }
110
+ filesaver.readyState = filesaver.DONE;
111
+ dispatch_all();
112
+ revoke(object_url);
113
+ }
114
+ , abortable = function(func) {
115
+ return function() {
116
+ if (filesaver.readyState !== filesaver.DONE) {
117
+ return func.apply(this, arguments);
118
+ }
119
+ };
120
+ }
121
+ , create_if_not_found = {create: true, exclusive: false}
122
+ , slice
123
+ ;
124
+ filesaver.readyState = filesaver.INIT;
125
+ if (!name) {
126
+ name = "download";
127
+ }
128
+ if (can_use_save_link) {
129
+ object_url = get_URL().createObjectURL(blob);
130
+ save_link.href = object_url;
131
+ save_link.download = name;
132
+ setTimeout(function() {
133
+ click(save_link);
134
+ dispatch_all();
135
+ revoke(object_url);
136
+ filesaver.readyState = filesaver.DONE;
137
+ });
138
+ return;
139
+ }
140
+ // Object and web filesystem URLs have a problem saving in Google Chrome when
141
+ // viewed in a tab, so I force save with application/octet-stream
142
+ // http://code.google.com/p/chromium/issues/detail?id=91158
143
+ // Update: Google errantly closed 91158, I submitted it again:
144
+ // https://code.google.com/p/chromium/issues/detail?id=389642
145
+ if (view.chrome && type && type !== force_saveable_type) {
146
+ slice = blob.slice || blob.webkitSlice;
147
+ blob = slice.call(blob, 0, blob.size, force_saveable_type);
148
+ blob_changed = true;
149
+ }
150
+ // Since I can't be sure that the guessed media type will trigger a download
151
+ // in WebKit, I append .download to the filename.
152
+ // https://bugs.webkit.org/show_bug.cgi?id=65440
153
+ if (webkit_req_fs && name !== "download") {
154
+ name += ".download";
155
+ }
156
+ if (type === force_saveable_type || webkit_req_fs) {
157
+ target_view = view;
158
+ }
159
+ if (!req_fs) {
160
+ fs_error();
161
+ return;
162
+ }
163
+ fs_min_size += blob.size;
164
+ req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
165
+ fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
166
+ var save = function() {
167
+ dir.getFile(name, create_if_not_found, abortable(function(file) {
168
+ file.createWriter(abortable(function(writer) {
169
+ writer.onwriteend = function(event) {
170
+ target_view.location.href = file.toURL();
171
+ filesaver.readyState = filesaver.DONE;
172
+ dispatch(filesaver, "writeend", event);
173
+ revoke(file);
174
+ };
175
+ writer.onerror = function() {
176
+ var error = writer.error;
177
+ if (error.code !== error.ABORT_ERR) {
178
+ fs_error();
179
+ }
180
+ };
181
+ "writestart progress write abort".split(" ").forEach(function(event) {
182
+ writer["on" + event] = filesaver["on" + event];
183
+ });
184
+ writer.write(blob);
185
+ filesaver.abort = function() {
186
+ writer.abort();
187
+ filesaver.readyState = filesaver.DONE;
188
+ };
189
+ filesaver.readyState = filesaver.WRITING;
190
+ }), fs_error);
191
+ }), fs_error);
192
+ };
193
+ dir.getFile(name, {create: false}, abortable(function(file) {
194
+ // delete file if it already exists
195
+ file.remove();
196
+ save();
197
+ }), abortable(function(ex) {
198
+ if (ex.code === ex.NOT_FOUND_ERR) {
199
+ save();
200
+ } else {
201
+ fs_error();
202
+ }
203
+ }));
204
+ }), fs_error);
205
+ }), fs_error);
206
+ }
207
+ , FS_proto = FileSaver.prototype
208
+ , saveAs = function(blob, name, no_auto_bom) {
209
+ return new FileSaver(blob, name, no_auto_bom);
210
+ }
211
+ ;
212
+ // IE 10+ (native saveAs)
213
+ if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
214
+ return function(blob, name, no_auto_bom) {
215
+ if (!no_auto_bom) {
216
+ blob = auto_bom(blob);
217
+ }
218
+ return navigator.msSaveOrOpenBlob(blob, name || "download");
219
+ };
220
+ }
221
+
222
+ FS_proto.abort = function() {
223
+ var filesaver = this;
224
+ filesaver.readyState = filesaver.DONE;
225
+ dispatch(filesaver, "abort");
226
+ };
227
+ FS_proto.readyState = FS_proto.INIT = 0;
228
+ FS_proto.WRITING = 1;
229
+ FS_proto.DONE = 2;
230
+
231
+ FS_proto.error =
232
+ FS_proto.onwritestart =
233
+ FS_proto.onprogress =
234
+ FS_proto.onwrite =
235
+ FS_proto.onabort =
236
+ FS_proto.onerror =
237
+ FS_proto.onwriteend =
238
+ null;
239
+
240
+ return saveAs;
241
+ }(
242
+ typeof self !== "undefined" && self
243
+ || typeof window !== "undefined" && window
244
+ || this.content
245
+ ));
246
+ // `self` is undefined in Firefox for Android content script context
247
+ // while `this` is nsIContentFrameMessageManager
248
+ // with an attribute `content` that corresponds to the window
249
+
250
+ if (typeof module !== "undefined" && module.exports) {
251
+ module.exports.saveAs = saveAs;
252
+ } else if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) {
253
+ define([], function() {
254
+ return saveAs;
255
+ });
256
+ }
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filesaverjs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.20150716
5
+ platform: ruby
6
+ authors:
7
+ - Dinesh Sawant
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - dineshs@idfy.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - README.md
64
+ - lib/filesaverjs/rails.rb
65
+ - lib/filesaverjs/rails/version.rb
66
+ - vendor/assets/javascripts/FileSaver.js
67
+ homepage: https://github.com/dinsaw/filesaverjs-rails
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.5
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: filesaverjs-rails is a simple gem to add FileSaver.js vendor file to Rails
91
+ asset pipeline.
92
+ test_files: []