carrierwave-data-uri 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +14 -0
- data/README.md +3 -2
- data/Rakefile +4 -0
- data/carrierwave-data-uri.gemspec +1 -0
- data/lib/carrierwave_data_uri/mount.rb +2 -2
- data/lib/carrierwave_data_uri/parser.rb +1 -0
- data/lib/carrierwave_data_uri/tempfile.rb +7 -2
- data/lib/carrierwave_data_uri/version.rb +1 -1
- data/spec/integration_spec.rb +59 -0
- data/spec/parser_spec.rb +1 -3
- data/spec/tempfile_spec.rb +24 -0
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6763b9e42a19e7766f8eb11e610dedc2849e5e49
|
4
|
+
data.tar.gz: 8499f9d8ad15cd880ed7bfba07b03a58d1cfe0f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4319d0ed174376671fa844abd7092ba414198db1ca2d0f3be136db969cfc9526e7e607247c70091e13163aa988ba2f4019bb58661257e3c72c71fc78b3bfae38
|
7
|
+
data.tar.gz: df9963c6c0dc6f793df5ffb5fa3a97870b8ff7b8f75e2984d276a97684d16fb9730d1e83f0864ffefc1d085f2106480c82cde8bb52d575f3c57fb3c471abcbcd
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# CarrierWave::DataUri
|
1
|
+
# CarrierWave::DataUri [![Build Status](https://travis-ci.org/timsly/carrierwave-data-uri.svg)](https://travis-ci.org/timsly/carrierwave-data-uri)
|
2
2
|
|
3
3
|
Carrierwave plugin that allows create image from data uri
|
4
4
|
|
@@ -34,11 +34,12 @@ user.avatar_data_uri = 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///y
|
|
34
34
|
user.save
|
35
35
|
```
|
36
36
|
|
37
|
-
Optionally, to customize the file name, specify the `#{column}_data_filename`
|
37
|
+
Optionally, to customize the file name, specify the `#{column}_data_filename` and `#{column}_data_mimetype` attributes before the `#{column}_data_uri` attribute.
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
user = User.find 123
|
41
41
|
user.avatar_data_filename = 'somefile.jpg'
|
42
|
+
user.avatar_data_mimetype = 'image/jpeg'
|
42
43
|
user.avatar_data_uri = 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
|
43
44
|
user.save
|
44
45
|
```
|
data/Rakefile
CHANGED
@@ -8,10 +8,10 @@ module CarrierWave
|
|
8
8
|
super
|
9
9
|
|
10
10
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
11
|
-
attr_accessor :#{column}_data_filename
|
11
|
+
attr_accessor :#{column}_data_filename, :#{column}_data_mimetype
|
12
12
|
|
13
13
|
def #{column}_data_uri=(data)
|
14
|
-
self.#{column} = Parser.new(data).to_file original_filename: self.#{column}_data_filename
|
14
|
+
self.#{column} = Parser.new(data).to_file original_filename: self.#{column}_data_filename, content_type: self.#{column}_data_mimetype
|
15
15
|
end
|
16
16
|
RUBY
|
17
17
|
end
|
@@ -3,11 +3,16 @@ require 'tempfile'
|
|
3
3
|
module CarrierWave
|
4
4
|
module DataUri
|
5
5
|
class Tempfile < ::Tempfile
|
6
|
-
attr_writer :original_filename
|
6
|
+
attr_writer :original_filename, :content_type
|
7
7
|
|
8
8
|
def original_filename
|
9
|
-
@original_filename || File.basename(
|
9
|
+
@original_filename || File.basename(path)
|
10
10
|
end
|
11
|
+
|
12
|
+
def content_type
|
13
|
+
@content_type || MIME::Types.type_for(original_filename).first.content_type
|
14
|
+
end
|
15
|
+
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
RSpec.describe 'Integration' do
|
2
|
+
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
|
3
|
+
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
4
|
+
ActiveRecord::Migration.verbose = false
|
5
|
+
|
6
|
+
class TestMigration < ActiveRecord::Migration
|
7
|
+
def self.up
|
8
|
+
create_table :images, :force => true do |t|
|
9
|
+
t.column :src, :string
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :images
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ImageUploader < CarrierWave::Uploader::Base; end
|
19
|
+
|
20
|
+
class Image < ActiveRecord::Base
|
21
|
+
mount_uploader :src, ImageUploader
|
22
|
+
end
|
23
|
+
|
24
|
+
before(:all) { TestMigration.up }
|
25
|
+
after(:all) { TestMigration.down }
|
26
|
+
after { Image.destroy_all }
|
27
|
+
|
28
|
+
let(:gif_data_uri) do
|
29
|
+
'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
|
30
|
+
end
|
31
|
+
let(:jpeg_data_uri) do
|
32
|
+
'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QAWRXhpZgAASUkqAAgAAAAAAAAAAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAr/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AL+AAf/Z'
|
33
|
+
end
|
34
|
+
let(:image) { Image.new }
|
35
|
+
|
36
|
+
it 'should save image with data_uri' do
|
37
|
+
image.src_data_uri = gif_data_uri
|
38
|
+
image.save!
|
39
|
+
|
40
|
+
expect(image[:src]).to be_present
|
41
|
+
expect(image.src.file.filename).to end_with '.gif'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should create image with data_uri' do
|
45
|
+
new_image = Image.create! src_data_uri: gif_data_uri
|
46
|
+
|
47
|
+
expect(new_image[:src]).to be_present
|
48
|
+
expect(new_image.src.file.filename).to end_with '.gif'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should update image with data_uri' do
|
52
|
+
image.src_data_uri = gif_data_uri
|
53
|
+
image.save!
|
54
|
+
|
55
|
+
image.update src_data_uri: jpeg_data_uri
|
56
|
+
|
57
|
+
expect(image.src.file.filename).to end_with '.jpeg'
|
58
|
+
end
|
59
|
+
end
|
data/spec/parser_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
RSpec.describe CarrierWave::DataUri::Parser do
|
4
2
|
let(:data_uri) do
|
5
3
|
'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
|
@@ -7,7 +5,7 @@ RSpec.describe CarrierWave::DataUri::Parser do
|
|
7
5
|
|
8
6
|
describe 'initialization' do
|
9
7
|
it 'should raise error when data is invalid' do
|
10
|
-
expect { CarrierWave::DataUri::Parser.new 'invadli_data' }.to raise_error
|
8
|
+
expect { CarrierWave::DataUri::Parser.new 'invadli_data' }.to raise_error ArgumentError
|
11
9
|
end
|
12
10
|
|
13
11
|
it 'should parse data on init' do
|
@@ -0,0 +1,24 @@
|
|
1
|
+
RSpec.describe CarrierWave::DataUri::Tempfile do
|
2
|
+
let(:options) { {} }
|
3
|
+
let(:data_uri) do
|
4
|
+
'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
|
5
|
+
end
|
6
|
+
|
7
|
+
let(:tempfile) do
|
8
|
+
CarrierWave::DataUri::Parser.new(data_uri).to_file(options)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
describe '#content_type' do
|
13
|
+
subject(:content_type) { tempfile.content_type }
|
14
|
+
|
15
|
+
describe 'without a content_type supplied' do
|
16
|
+
specify { expect(content_type).to eq 'image/gif' }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'with a specified content_type' do
|
20
|
+
let(:options) { { content_type: 'image/jpeg' } }
|
21
|
+
specify { expect(content_type).to eq 'image/jpeg' }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
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.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tima Maslyuchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Carrierwave plugin that allows create image from data uri
|
84
98
|
email:
|
85
99
|
- insside@gmail.com
|
@@ -88,6 +102,8 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
91
107
|
- Gemfile
|
92
108
|
- LICENSE.txt
|
93
109
|
- README.md
|
@@ -98,8 +114,10 @@ files:
|
|
98
114
|
- lib/carrierwave_data_uri/parser.rb
|
99
115
|
- lib/carrierwave_data_uri/tempfile.rb
|
100
116
|
- lib/carrierwave_data_uri/version.rb
|
117
|
+
- spec/integration_spec.rb
|
101
118
|
- spec/parser_spec.rb
|
102
119
|
- spec/spec_helper.rb
|
120
|
+
- spec/tempfile_spec.rb
|
103
121
|
homepage: https://github.com/timsly/carrierwave-data-uri
|
104
122
|
licenses:
|
105
123
|
- MIT
|
@@ -120,10 +138,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
138
|
version: '0'
|
121
139
|
requirements: []
|
122
140
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.5.2
|
124
142
|
signing_key:
|
125
143
|
specification_version: 4
|
126
144
|
summary: Carrierwave plugin that allows create image from data uri
|
127
145
|
test_files:
|
146
|
+
- spec/integration_spec.rb
|
128
147
|
- spec/parser_spec.rb
|
129
148
|
- spec/spec_helper.rb
|
149
|
+
- spec/tempfile_spec.rb
|