administrate-field-paperclip 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee16d28996faaddc47f31c7a8c5f817d46dd114a
4
- data.tar.gz: 44f9346ebf5c4e3684c84aa057ddc36d084af810
3
+ metadata.gz: 8454ba2fb10fe33dfecd1f5696574581b6440996
4
+ data.tar.gz: 5421b704c17d70e9cfb983a547c184bfc2e6d4ea
5
5
  SHA512:
6
- metadata.gz: 7db40f29e4215404bf99062c401e1c23c76c1649f50cfbf83f3967476a65660631bd6948afd028119dbb76507c2b93a3dcf3670458fa5742fae69f4ec8919826
7
- data.tar.gz: 5bc6bc633197f93dae28a596574d7d58d6028be0e37cd005d4f74ae91307e0b9b83a199b3299b3421c7b3301898b7a4e2597b35c1d059dade0c5215397f06c4e
6
+ metadata.gz: 7005ebcfd36fc037ecc5a546ac331c110f33f79a4d952e8abf71c64e22bec5bb8aa41446b8024e748c01fbd477b5d1f19b9f4f9796a2d92012d554afac6c3d68
7
+ data.tar.gz: e9bbd9339a6224f7a5a018d52b272ad181340282678fcaf47f3bc33e23323cd7487437e13a2a30fd5bdc80421bf90b0459e9e6b6898631ba9cd59847af0e0625
data/.gitignore CHANGED
@@ -1,10 +1,12 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /*.gem
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
11
+ /spec/processed_images/
12
+ /.byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,19 @@
1
+ Rails:
2
+ Enabled: true
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Documentation:
8
+ Enabled: false
9
+
10
+ Style/FrozenStringLiteralComment:
11
+ Enabled: false
12
+
13
+ # specs tend to get long
14
+ Metrics/BlockLength:
15
+ Exclude:
16
+ - 'spec/**/*'
17
+
18
+ Style/TrailingCommaInLiteral:
19
+ EnforcedStyleForMultiline: comma
@@ -0,0 +1,11 @@
1
+ SimpleCov.start 'rails' do
2
+ add_group 'app', 'app'
3
+ add_group 'lib', 'lib'
4
+
5
+ refuse_coverage_drop
6
+
7
+ formatter SimpleCov::Formatter::MultiFormatter.new([
8
+ SimpleCov::Formatter::HTMLFormatter,
9
+ Coveralls::SimpleCov::Formatter
10
+ ])
11
+ end
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.0
4
+ - 2.3.3
5
+ - 2.2.6
6
+ - 2.1.10
7
+ cache: bundler
8
+ install: bundle install
9
+ script:
10
+ - bundle exec rubocop
11
+ - bundle exec rspec
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md CHANGED
@@ -17,9 +17,29 @@ Install:
17
17
  $ bundle install
18
18
  ```
19
19
 
20
+ ## Usage
21
+
20
22
  Follow the [instructions on Paperclip](https://github.com/thoughtbot/paperclip#quick-start) to get started with your models and migrations. Once you've added the Paperclip attribute to your models, edit your Administrate dashboards. If you added 'avatar' to 'User', then you should:
21
23
 
22
- * Add `avatar: Field::Paperclip` to `ATTRIBUTE_TYPES`.
23
- * Add `:avatar` to `FORM_ATTRIBUTES`, `SHOW_PAGE_ATTRIBUTES` and (optionally) `COLLECTION_ATTRIBUTES`.
24
+ ```ruby
25
+ class UserDashboard < Administrate::BaseDashboard
26
+ ATTRIBUTE_TYPES = {
27
+ avatar: Field::Paperclip,
28
+ }
29
+ # ...
30
+ ```
31
+
32
+ Then add `:avatar` to `FORM_ATTRIBUTES`, `SHOW_PAGE_ATTRIBUTES` and (optionally) `COLLECTION_ATTRIBUTES`.
33
+
34
+ You can provide the field with options using `Field::Paperclip.with_options(options)`:
35
+
36
+ * `thumbnail_style` (defaults to `'thumbnail'`) to control what image style is used to display the image in collection views
37
+ * `big_style` (defaults to `'original'`) to control what image style is used to display the image on the show page.
38
+ * `url_only` (defaults to `false`) to show only a URL (as a link) instead of trying to display an image.
39
+
40
+ ## [Contributors](https://github.com/picandocodigo/administrate-field-paperclip/graphs/contributors)
41
+
42
+ * Klas Eskilson - https://github.com/klaseskilson
43
+ * Rich - https://github.com/pedantic-git
24
44
 
25
45
  Based on the [Administrate::Field::Image](https://github.com/thoughtbot/administrate-field-image) template.
data/Rakefile CHANGED
@@ -1,22 +1,21 @@
1
- #!/usr/bin/env rake
2
-
3
- begin
4
- require "bundler/setup"
5
- rescue LoadError
6
- puts "You must `gem install bundler` and `bundle install` to run rake tasks"
7
- end
8
-
9
- require "bundler/gem_tasks"
10
-
11
- ##
12
- # Configure the test suite.
13
- ##
14
- require "rspec/core"
15
- require "rspec/core/rake_task"
16
-
17
- RSpec::Core::RakeTask.new
18
-
19
- ##
20
- # By default, just run the tests.
21
- ##
22
- task default: :spec
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'bundler/gem_tasks'
9
+
10
+ ##
11
+ # Configure the test suite.
12
+ ##
13
+ require 'rspec/core'
14
+ require 'rspec/core/rake_task'
15
+
16
+ RSpec::Core::RakeTask.new
17
+
18
+ ##
19
+ # By default, just run the tests.
20
+ ##
21
+ task default: :spec
@@ -1,21 +1,29 @@
1
- $:.push File.expand_path('../lib', __FILE__)
2
-
3
- Gem::Specification.new do |gem|
4
- gem.name = 'administrate-field-paperclip'
5
- gem.version = '0.0.2'
6
- gem.authors = ['Fernando Briano']
7
- gem.email = ['fernando@picandocodigo.net']
8
- gem.homepage = 'https://github.com/picandocodigo/administrate-field-paperclip'
9
- gem.summary = 'Paperclip field plugin for Administrate'
10
- gem.description = 'Integrates Paperclip as a field for Administrate in Rails apps'
11
- gem.license = 'MIT'
12
-
13
- gem.require_paths = ['lib']
14
- gem.files = `git ls-files`.split("\n")
15
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split('\n')
16
-
17
- gem.add_dependency 'administrate', '~> 0.4'
18
- gem.add_dependency 'rails', '~> 5.0'
19
-
20
- gem.add_development_dependency 'rspec', '~> 3.5'
21
- end
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'administrate-field-paperclip'
5
+ gem.version = '0.0.3'
6
+ gem.authors = ['Fernando Briano']
7
+ gem.email = ['fernando@picandocodigo.net']
8
+ gem.homepage = 'https://github.com/picandocodigo/administrate-field-paperclip'
9
+ gem.summary = 'Paperclip field plugin for Administrate'
10
+ gem.description = 'Integrates Paperclip as a field for Administrate in Rails apps'
11
+ gem.license = 'MIT'
12
+
13
+ gem.require_paths = ['lib']
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split('\n')
16
+
17
+ gem.add_dependency 'administrate', '~> 0.4'
18
+ gem.add_dependency 'rails', '~> 5.0'
19
+
20
+ gem.add_development_dependency 'byebug'
21
+ gem.add_development_dependency 'factory_girl'
22
+ gem.add_development_dependency 'fog'
23
+ gem.add_development_dependency 'paperclip'
24
+ gem.add_development_dependency 'sqlite3'
25
+ gem.add_development_dependency 'coveralls'
26
+ gem.add_development_dependency 'rspec', '~> 3.5'
27
+ gem.add_development_dependency 'rubocop'
28
+ gem.add_development_dependency 'simplecov'
29
+ end
@@ -1 +1,5 @@
1
- <%= image_tag field.thumbnail %>
1
+ <% if field.url_only? -%>
2
+ <%= link_to field.url, field.url if field.url.present? %>
3
+ <% else -%>
4
+ <%= image_tag field.thumbnail %>
5
+ <% end -%>
@@ -1 +1,5 @@
1
- <%= image_tag field.url if field.url.present? %>
1
+ <% if field.url_only? -%>
2
+ <%= link_to field.url, field.url if field.url.present? %>
3
+ <% else -%>
4
+ <%= image_tag field.url if field.url.present? %>
5
+ <% end -%>
@@ -1,22 +1,41 @@
1
- require 'administrate/field/base'
2
- require 'rails'
3
-
4
- module Administrate
5
- module Field
6
- class Paperclip < Administrate::Field::Base
7
- def url
8
- data.url
9
- end
10
-
11
- def thumbnail
12
- data.url(:thumbnail)
13
- end
14
-
15
- def to_s
16
- data
17
- end
18
- class Engine < ::Rails::Engine
19
- end
20
- end
21
- end
22
- end
1
+ require 'administrate/field/base'
2
+ require 'rails'
3
+
4
+ module Administrate
5
+ module Field
6
+ class Paperclip < Administrate::Field::Base
7
+ class Engine < ::Rails::Engine
8
+ end
9
+
10
+ def style(size = big_style)
11
+ data.try(:url, size) || ''
12
+ end
13
+
14
+ delegate :url, to: :data
15
+
16
+ def thumbnail
17
+ style(thumbnail_style)
18
+ end
19
+
20
+ # Just display the URL as a link, rather than trying to make it an image
21
+ def url_only?
22
+ options.fetch(:url_only, false)
23
+ end
24
+
25
+ alias url style
26
+
27
+ private
28
+
29
+ DEFAULT_THUMBNAIL_STYLE = :thumbnail
30
+ DEFAULT_BIG_STYLE = :original
31
+
32
+ def thumbnail_style
33
+ options.fetch(:thumbnail_style, DEFAULT_THUMBNAIL_STYLE)
34
+ end
35
+
36
+ def big_style
37
+ options.fetch(:big_style, DEFAULT_BIG_STYLE)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :post do
3
+ image { File.new(File.join('spec', 'fixtures', 'image.png')) }
4
+ end
5
+ end
Binary file
@@ -0,0 +1,12 @@
1
+ class Post < ActiveRecord::Base
2
+ include Paperclip::Glue
3
+
4
+ has_attached_file :image,
5
+ styles: {
6
+ thumbnail: '4x4#',
7
+ extra: '2x4>',
8
+ }
9
+
10
+ # validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
11
+ do_not_validate_attachment_file_type :image
12
+ end
@@ -1,14 +1,78 @@
1
- require "administrate/field/paperclip"
2
-
3
- describe Administrate::Field::Paperclip do
4
- describe '#to_partial_path' do
5
- it 'returns a partial based on the page being rendered' do
6
- page = :show
7
- field = Administrate::Field::Paperclip.new(:paperclip, '/a.jpg', page)
8
-
9
- path = field.to_partial_path
10
-
11
- expect(path).to eq("/fields/paperclip/#{page}")
12
- end
13
- end
14
- end
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Administrate::Field::Paperclip do
4
+ let(:post) { create(:post) }
5
+ let(:page) { :show }
6
+ let(:field) { described_class.new(:image, post.image, page) }
7
+ let(:empty_field) { described_class.new(:image, nil, page) }
8
+
9
+ require 'administrate/field/paperclip'
10
+
11
+ describe '#to_partial_path' do
12
+ it 'returns a partial based on the page being rendered' do
13
+ expect(empty_field.to_partial_path).to eq("/fields/paperclip/#{page}")
14
+ end
15
+ end
16
+
17
+ PAPECLIP_FIELD_METHODS = %w(style thumbnail url).freeze
18
+ PAPECLIP_FIELD_METHODS.each do |method|
19
+ describe "##{method}" do
20
+ context 'when inner_attribute is not set' do
21
+ it 'should return a non-nil url' do
22
+ expect(field.send(method)).to_not eq ''
23
+ end
24
+ end
25
+
26
+ context 'when image attachment doesn\'t exist' do
27
+ it 'should return empty string' do
28
+ expect(empty_field.send(method)).to eq ''
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#thumbnail' do
35
+ context 'when thumbnail size is provided as an option' do
36
+ let(:field) { described_class.new(:image, post.image, page, thumbnail_style: :extra) }
37
+
38
+ it 'should return a string to the correct image' do
39
+ expect(field.thumbnail).to_not be_nil
40
+ expect(field.thumbnail).to include('extra')
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '#style' do
46
+ context 'when big image style is provided as an option' do
47
+ let(:field) { described_class.new(:image, post.image, page, big_style: :extra) }
48
+
49
+ it 'should return a string to the correct image' do
50
+ expect(field.style).to_not be_nil
51
+ expect(field.style).to include('extra')
52
+ end
53
+ end
54
+
55
+ context 'when image style is provided as a parameter' do
56
+ let(:field) { described_class.new(:image, post.image, page) }
57
+
58
+ it 'should return a string to the correct image' do
59
+ expect(field.style(:extra)).to_not be_nil
60
+ expect(field.style(:extra)).to include('extra')
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#url_only?' do
66
+ context 'with no options' do
67
+ it 'should be false' do
68
+ expect(field.url_only?).to be false
69
+ end
70
+ end
71
+ context 'with url_only option true' do
72
+ let(:field) { described_class.new(:image, post.image, page, url_only: true) }
73
+ it 'should be true' do
74
+ expect(field.url_only?).to be true
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,11 @@
1
+ # make sure we have paperclip here
2
+ require 'paperclip'
3
+
4
+ include Paperclip::Schema
5
+ ActiveRecord::Schema.define do
6
+ self.verbose = false
7
+
8
+ create_table :posts, force: true do |t|
9
+ t.attachment :image
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ # start coverage tracking
2
+ require 'coveralls'
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
6
+ require 'administrate/field/paperclip'
7
+ # config Paperclip for testing purposes
8
+ require 'paperclip'
9
+ require 'fog'
10
+ Paperclip::Attachment.default_options[:storage] = :fog
11
+ Paperclip::Attachment.default_options[:fog_credentials] = {
12
+ provider: 'Local',
13
+ local_root: File.join(__FILE__, '../processed_images'),
14
+ }
15
+ Paperclip::Attachment.default_options[:fog_directory] = ''
16
+ Paperclip::Attachment.default_options[:fog_host] = 'http://localhost:3000'
17
+
18
+ # enable debugging using byebug
19
+ require 'byebug'
20
+
21
+ # start up factory_girl
22
+ require 'factory_girl'
23
+
24
+ # start db and load migrations and everything
25
+ require 'active_record'
26
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
27
+ require_relative 'schema'
28
+ require_relative 'models'
29
+
30
+ # config rspec
31
+ RSpec.configure do |config|
32
+ # configure factory girl
33
+ config.include FactoryGirl::Syntax::Methods
34
+ config.before(:suite) do
35
+ FactoryGirl.find_definitions
36
+ end
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate-field-paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Briano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-14 00:00:00.000000000 Z
11
+ date: 2017-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate
@@ -38,6 +38,90 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
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
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fog
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: paperclip
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'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
41
125
  - !ruby/object:Gem::Dependency
42
126
  name: rspec
43
127
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +136,34 @@ dependencies:
52
136
  - - "~>"
53
137
  - !ruby/object:Gem::Version
54
138
  version: '3.5'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
55
167
  description: Integrates Paperclip as a field for Administrate in Rails apps
56
168
  email:
57
169
  - fernando@picandocodigo.net
@@ -60,6 +172,10 @@ extensions: []
60
172
  extra_rdoc_files: []
61
173
  files:
62
174
  - ".gitignore"
175
+ - ".rspec"
176
+ - ".rubocop.yml"
177
+ - ".simplecov"
178
+ - ".travis.yml"
63
179
  - Gemfile
64
180
  - LICENSE
65
181
  - README.md
@@ -69,7 +185,13 @@ files:
69
185
  - app/views/fields/paperclip/_index.html.erb
70
186
  - app/views/fields/paperclip/_show.html.erb
71
187
  - lib/administrate/field/paperclip.rb
188
+ - spec/factories/posts.rb
189
+ - spec/fixtures/image.png
190
+ - spec/models.rb
72
191
  - spec/paperclip_spec.rb
192
+ - spec/processed_images/.keep
193
+ - spec/schema.rb
194
+ - spec/spec_helper.rb
73
195
  homepage: https://github.com/picandocodigo/administrate-field-paperclip
74
196
  licenses:
75
197
  - MIT