spree_pages 1.0.4 → 1.0.5

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
  SHA256:
3
- metadata.gz: 9573f9b763c23a7b6114698dd3513b0b1919d851b8f2f2e039a53a1c345f12b4
4
- data.tar.gz: a5a91903024705297a92b17463aea167adc9601cb4ae62ac0e58ee7225202496
3
+ metadata.gz: 36860d74722446853f99843db547644c0a1eee5121a15b983e04acfb36a9f027
4
+ data.tar.gz: 0fa3f1b57b66718b77fc7d0cbaccfbc0652e28b531681b54fc3b7ea388ef7c64
5
5
  SHA512:
6
- metadata.gz: 809b58b27f0a7d4055f1aad6ec1cf998cddfa03b656087c35023e1c8bab178da1a9e70b63a458fb74015a25fbd7c11098f62f48439579d7de3882b6263a838f3
7
- data.tar.gz: 1bef45e14a3b632d429a5047bf87092d738104a80f07d9cebff5bdfcc3374f2850450543a116becdccfca7f3399f732f88980f455951b28ffde21e6d3d8aafc3
6
+ metadata.gz: dcab36168904ec85c71007839f6676d548e984bb3334110742b5611bb405312bed0c11041010db396be76b023172205996874d29dfb81ae00acf7fabac13041d
7
+ data.tar.gz: f993d8b3018c1afb2cfd5d83c66f1945e809c3a5440de61e10c1ce79d048fe9adff2207afbe2d51009ad6b9b213da61052ba5392eccf96e7c1e922886843ea94
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class Page < ApplicationRecord
3
- has_one :meta_image, as: :viewable, dependent: :destroy, class_name: 'Spree::Image'
3
+ has_one :meta_image, as: :viewable, dependent: :destroy, class_name: 'Spree::PageMetaImage'
4
4
 
5
5
  validates :title, :slug, :content, presence: true
6
6
  validates :slug, uniqueness: true
@@ -0,0 +1,37 @@
1
+ module Spree
2
+ class PageMetaImage < Asset
3
+ module Configuration
4
+ module ActiveStorage
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ validate :check_attachment_content_type
9
+
10
+ has_one_attached :attachment
11
+
12
+ def self.styles
13
+ @styles ||= {
14
+ large: '1200x630>',
15
+ medium: '600x315>',
16
+ small: '200x200>'
17
+ }
18
+ end
19
+
20
+ def default_style
21
+ :large
22
+ end
23
+
24
+ def accepted_image_types
25
+ %w[image/jpeg image/jpg image/png]
26
+ end
27
+
28
+ def check_attachment_content_type
29
+ return if !attachment.attached? || !attachment.content_type.in?(accepted_image_types)
30
+
31
+ errors.add(:attachment, :not_allowed_content_type)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ module Spree
2
+ class PageMetaImage < Asset
3
+ module Configuration
4
+ module Paperclip
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ has_attached_file :attachment,
9
+ styles: {
10
+ large: '1200x630>',
11
+ medium: '600x315>',
12
+ small: '200x200>'
13
+ },
14
+ default_style: :large
15
+
16
+ validates_attachment_content_type :attachment, content_type: %r{\Aimage\/.*\z}
17
+
18
+ delegate :url, to: :attachment
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ class PageMetaImage < Asset
3
+ include Rails.application.config.use_paperclip ? Configuration::Paperclip : Configuration::ActiveStorage
4
+ end
5
+ end
@@ -10,7 +10,7 @@ module SpreePages
10
10
  module VERSION
11
11
  MAJOR = 1
12
12
  MINOR = 0
13
- TINY = 4
13
+ TINY = 5
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
16
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kozaev Artem
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2018-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paperclip
@@ -243,6 +243,9 @@ files:
243
243
  - app/controllers/spree/admin/pages_controller.rb
244
244
  - app/controllers/spree/pages_controller.rb
245
245
  - app/models/spree/page.rb
246
+ - app/models/spree/page_meta_image.rb
247
+ - app/models/spree/page_meta_image/configuration/activestorage.rb
248
+ - app/models/spree/page_meta_image/configuration/paperclip.rb
246
249
  - app/overrides/spree/admin/menu/add_pages_to_admin_sidebar.rb
247
250
  - app/views/spree/admin/pages/_form.html.erb
248
251
  - app/views/spree/admin/pages/edit.html.erb