carrierwave-data-uri 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa3d5a03d7edf266f896a6afdd0f317f2d0a7ec9
4
- data.tar.gz: b15c3fe7e2de41d8284c0687b11df54b109296f4
3
+ metadata.gz: c2ebf035e2038b806c9c5853d1739a0409d139c5
4
+ data.tar.gz: f4c1f3c293d142b8de10a1dd2508a822a00496a4
5
5
  SHA512:
6
- metadata.gz: 35c09177516f69431a0ee0e626633bc824b1fdaf9eb12dc8f7574630d975ee1b0b39b5870be10f8cc159a6d1fd59f0c6b1108e69f46018e6a568dda0cdb851a7
7
- data.tar.gz: 685aa5e960aa3fdeb61404bd25bdfe47121fc90019aea710c9f48ce949fa4a5582b11fd552b378ab928bd02e1492eeb76062a7afd950eef07db5860205df5590
6
+ metadata.gz: 49ed5dace03485cacb061532bea538cbc100d5a17d2ad882ef104b6e81163120daad724ea21e771a1313889579f0a4f07688473ff14564cdc56dd80ea10d5580
7
+ data.tar.gz: 5057e986f1bfe8731dafc14a04581a63fb47dfbfdcfaefa3dae72d667eaa5cd427a9530adb648152c23691b971b803087c80bd39f257fa5015b0f93412954f08
data/README.md CHANGED
@@ -30,9 +30,19 @@ Then we can create image from data
30
30
 
31
31
  ```
32
32
  user = User.find 123
33
- user.image_data_uri = 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
33
+ user.avatar_data_uri = 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
34
34
  user.save
35
35
  ```
36
+
37
+ Optionally, to customize the file name, specify the `#{column}_data_filename` attribute before the `#{column}_data_uri` attribute.
38
+
39
+ ```ruby
40
+ user = User.find 123
41
+ user.avatar_data_filename = 'somefile.jpg'
42
+ user.avatar_data_uri = 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
43
+ user.save
44
+ ```
45
+
36
46
  ## Contributing
37
47
 
38
48
  1. Fork it ( https://github.com/[my-github-username]/carrierwave-data-uri/fork )
@@ -40,3 +50,7 @@ user.save
40
50
  3. Commit your changes (`git commit -am 'Add some feature'`)
41
51
  4. Push to the branch (`git push origin my-new-feature`)
42
52
  5. Create a new Pull Request
53
+
54
+ ## Credits
55
+
56
+ * http://www.davehulihan.com/uploading-data-uris-in-carrierwave/
@@ -1,5 +1,6 @@
1
1
  require 'carrierwave'
2
2
  require 'carrierwave/orm/activerecord'
3
+ require 'carrierwave_data_uri/tempfile'
3
4
  require 'carrierwave_data_uri/parser'
4
5
  require 'carrierwave_data_uri/version'
5
6
  require 'carrierwave_data_uri/mount'
@@ -8,8 +8,10 @@ module CarrierWave
8
8
  super
9
9
 
10
10
  class_eval <<-RUBY, __FILE__, __LINE__+1
11
+ attr_accessor :#{column}_data_filename
12
+
11
13
  def #{column}_data_uri=(data)
12
- self.#{column} = Parser.new(data).to_file
14
+ self.#{column} = Parser.new(data).to_file original_filename: self.#{column}_data_filename
13
15
  end
14
16
  RUBY
15
17
  end
@@ -1,4 +1,3 @@
1
- require 'tempfile'
2
1
  require 'base64'
3
2
 
4
3
  module CarrierWave
@@ -21,12 +20,13 @@ module CarrierWave
21
20
  @binary_data ||= Base64.decode64 data
22
21
  end
23
22
 
24
- def to_file
23
+ def to_file(options = {})
25
24
  @file ||= begin
26
25
  file = Tempfile.new ['data_uri_upload', ".#{extension}"]
27
26
  file.binmode
28
27
  file << binary_data
29
28
  file.rewind
29
+ file.original_filename = options[:original_filename]
30
30
  file
31
31
  end
32
32
  end
@@ -0,0 +1,13 @@
1
+ require 'tempfile'
2
+
3
+ module CarrierWave
4
+ module DataUri
5
+ class Tempfile < ::Tempfile
6
+ attr_writer :original_filename
7
+
8
+ def original_filename
9
+ @original_filename || File.basename(@tmpname)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,7 +1,7 @@
1
1
  module Carrierwave
2
2
  module Data
3
3
  module Uri
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
6
6
  end
7
7
  end
data/spec/parser_spec.rb CHANGED
@@ -22,7 +22,7 @@ RSpec.describe CarrierWave::DataUri::Parser do
22
22
  parsed = CarrierWave::DataUri::Parser.new data_uri
23
23
  file = parsed.to_file
24
24
 
25
- expect(file).to be_a_kind_of Tempfile
25
+ expect(file).to be_a_kind_of CarrierWave::DataUri::Tempfile
26
26
  end
27
27
  end
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-data-uri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tima Maslyuchenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-06 00:00:00.000000000 Z
11
+ date: 2015-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -96,6 +96,7 @@ files:
96
96
  - lib/carrierwave-data-uri.rb
97
97
  - lib/carrierwave_data_uri/mount.rb
98
98
  - lib/carrierwave_data_uri/parser.rb
99
+ - lib/carrierwave_data_uri/tempfile.rb
99
100
  - lib/carrierwave_data_uri/version.rb
100
101
  - spec/parser_spec.rb
101
102
  - spec/spec_helper.rb
@@ -126,4 +127,3 @@ summary: Carrierwave plugin that allows create image from data uri
126
127
  test_files:
127
128
  - spec/parser_spec.rb
128
129
  - spec/spec_helper.rb
129
- has_rdoc: