mosaico 1.1.1 → 2.0.0

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
- SHA1:
3
- metadata.gz: eb08eed391dc9fdea93dfd8112abada6639bc06a
4
- data.tar.gz: c26b82633c819545823c7572b3005e54b7156af1
2
+ SHA256:
3
+ metadata.gz: 9f24bd21927feca6f9b818cb92fb1824b4a51c346bb9d7b516e6abc366e981b6
4
+ data.tar.gz: e0b8659be267714ed2357fc522559ea0a303d90b4e2f35c91e6c80fa4aa54723
5
5
  SHA512:
6
- metadata.gz: f5e720c0531c1e0a8274fe4ec630382994b76b08d769c17d4bbb5772e0ef7e4bfef9a57c29ef9123377fe13c60d56e6b63daedc93afd8e5a7e15d2b6547d7ba8
7
- data.tar.gz: 6ba2611446a7b050de4f643b9e9cbcf8f78fd9adeb8fd199142f607e1fd592234628a513e21f00a83fc1842abc2b8e13802803fccea4df43c193e7c967bd73ae
6
+ metadata.gz: ea656ff0a7834a5c2e7a32bdf63747747a7f2a4fc9537b24e698394a02c082b955f2e32bd61e33ed21d6f032e31406a29c9ac5791a8b61f61651217206a64399
7
+ data.tar.gz: 1d8d99904cc9150c54e5a57268989d5f943214455870b79f09fdc8af1f4765aac9486003006a90df236a828071198bedf278f0e700e5ea259727e9aacf6ade30
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 2.0.0
2
+ ===
3
+ * Switched to ActiveStorage as the default image backend. Accordingly, mosaico-rails now supports Rails >= 5.2.
4
+
1
5
  1.1.1
2
6
  ===
3
7
  * Fixed asset delivery for custom templates.
data/README.md CHANGED
@@ -48,8 +48,17 @@ You should be able to drag blocks from the list on the left into the center comp
48
48
 
49
49
  Getting up and running is really only the first step. You'll probably want to configure Mosaico to actually send email in a production environment. See the remaining sections for guidance.
50
50
 
51
+ ### Upgrading from version 1 to version 2
52
+
53
+ We've introduced a new default image backend since v2.0.0. If you are upgrading from v1, you will have to add the following code in order to keep your current image backend, i.e. to avoid broken images. Create an initializer in config/initializers/mosaico.rb and add these lines:
54
+
55
+ ```ruby
56
+ Mosaico::Engine.config.placeholder_backend = Mosaico::LocalPlaceholderBackend.new
57
+ Mosaico::Engine.config.image_backend = Mosaico::LocalImageBackend.new
58
+ ```
59
+
51
60
  ### Custom Image Backends
52
- Uploading images within a Mosaico template is easy - just drag and drop from your filesystem onto any image placeholder. Behind the scenes, Mosaico is resizing and storing the images in the configured storage backend. The default storage backend is just your local filesystem. Images are stored in public/mosaico/images. In a production environment, you'll probably want images to be uploaded to a third-party service like Amazon's S3 or Google Cloud Storage. Unfortunately backends for these services aren't included with Mosaico (I'd glady welcome a pull request). Creating a storage backend is easy though - you just have to implement several methods. For example, here's the skeleton for an S3 backend:
61
+ Uploading images within a Mosaico template is easy - just drag and drop from your filesystem onto any image placeholder. Behind the scenes, Mosaico is resizing and storing the images in the configured storage backend. The default storage backend is just your application's ActiveStorage service. Images are stored with mosaico/images/ and mosaico/placeholders/ as path prefix or key prefix. ActiveStorage comes with support for local storage as well as thrid-party service like Amazon's S3 or Google Cloud Storage. You may want to customize how images are to be uploaded and stored. Creating a storage backend is easy though - you just have to implement several methods. For example, here's the skeleton for an custom S3 backend:
53
62
 
54
63
  ```ruby
55
64
  module Mosaico
@@ -178,4 +187,4 @@ Licensed under the GPLv3 license.
178
187
  ### Authors
179
188
 
180
189
  1. This gem: Cameron Dutro [@camertron](http://twitter.com/camertron)
181
- 2. mosaico: Void Labs, it's [on github](https://github.com/voidlabs/mosaico)
190
+ 2. mosaico: Void Labs, it's [on github](https://github.com/voidlabs/mosaico)
@@ -2,6 +2,8 @@ require 'mini_magick'
2
2
 
3
3
  module Mosaico
4
4
  class ImagesController < ::Mosaico::ApplicationController
5
+ before_action :set_active_storage_host
6
+
5
7
  def create
6
8
  files = params[:files].map do |file|
7
9
  dest_file = File.basename(file.tempfile.path)
@@ -138,5 +140,9 @@ module Mosaico
138
140
  def placeholder_seed
139
141
  Mosaico::Engine.root.join('lib', 'mosaico', 'placeholder.png').to_s
140
142
  end
143
+
144
+ def set_active_storage_host
145
+ ActiveStorage::Current.host = request.base_url
146
+ end
141
147
  end
142
148
  end
@@ -0,0 +1,31 @@
1
+ module Mosaico
2
+ class ActiveStorageBackend
3
+ attr_reader :service, :path_prefix
4
+
5
+ def initialize(service, path_prefix)
6
+ @service = service
7
+ @path_prefix = path_prefix
8
+ end
9
+
10
+ def store(source, as:)
11
+ key = "#{path_prefix}/#{as}"
12
+ @service.upload(key, open(source))
13
+ end
14
+
15
+ def retrieve(file)
16
+ key = "#{path_prefix}/#{file}"
17
+ data = @service.download(key)
18
+
19
+ tmp_file = Tempfile.new(file, :encoding => 'ascii-8bit')
20
+ tmp_file.write(data)
21
+ tmp_file.close
22
+
23
+ tmp_file.path
24
+ end
25
+
26
+ def url_to(file)
27
+ key = "#{path_prefix}/#{file}"
28
+ @service.url(key, filename: ActiveStorage::Filename.new(file), expires_in: 1.week, disposition: :inline, content_type: nil)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module Mosaico
2
+ class ActiveStorageImageBackend < ActiveStorageBackend
3
+ def initialize
4
+ super(ActiveStorage::Blob.service, '/mosaico/images')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Mosaico
2
+ class ActiveStoragePlaceholderBackend < ActiveStorageBackend
3
+ def initialize
4
+ super(ActiveStorage::Blob.service, '/mosaico/placeholders')
5
+ end
6
+ end
7
+ end
@@ -92,8 +92,13 @@ module Mosaico
92
92
  )
93
93
  end
94
94
 
95
- Mosaico::Engine.config.placeholder_backend = Mosaico::LocalPlaceholderBackend.new
96
- Mosaico::Engine.config.image_backend = Mosaico::LocalImageBackend.new
95
+ Mosaico::Engine.config.placeholder_backend = nil
96
+ Mosaico::Engine.config.image_backend = nil
97
+
98
+ config.after_initialize do
99
+ Mosaico::Engine.config.placeholder_backend ||= Mosaico::ActiveStoragePlaceholderBackend.new
100
+ Mosaico::Engine.config.image_backend ||= Mosaico::ActiveStorageImageBackend.new
101
+ end
97
102
  end
98
103
  end
99
104
  end
@@ -1,4 +1,4 @@
1
1
  module Mosaico
2
- VERSION = '1.1.1'
2
+ VERSION = '2.0.0'
3
3
  MOSAICO_VERSION = '0.16.0'
4
4
  end
data/lib/mosaico.rb CHANGED
@@ -24,9 +24,12 @@ end
24
24
  module Mosaico
25
25
  DEFAULT_LOCALE = :en
26
26
 
27
- autoload :LocalImageBackend, 'mosaico/local_image_backend'
28
- autoload :LocalPlaceholderBackend, 'mosaico/local_placeholder_backend'
29
- autoload :LocalBackend, 'mosaico/local_backend'
27
+ autoload :LocalImageBackend, 'mosaico/local_image_backend'
28
+ autoload :LocalPlaceholderBackend, 'mosaico/local_placeholder_backend'
29
+ autoload :LocalBackend, 'mosaico/local_backend'
30
+ autoload :ActiveStorageImageBackend, 'mosaico/active_storage_image_backend'
31
+ autoload :ActiveStoragePlaceholderBackend, 'mosaico/active_storage_placeholder_backend'
32
+ autoload :ActiveStorageBackend, 'mosaico/active_storage_backend'
30
33
 
31
34
  class << self
32
35
  include Mosaico::Engine.routes.url_helpers
data/mosaico.gemspec CHANGED
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency 'generated-assets', '~> 2.0'
19
19
  s.add_dependency 'mini_magick'
20
20
  s.add_dependency 'mime-types'
21
- s.add_dependency 'rails', '>= 4.0'
21
+ s.add_dependency 'rails', '>= 5.2'
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mosaico
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-08 00:00:00.000000000 Z
11
+ date: 2022-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: css-rewrite
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '4.0'
75
+ version: '5.2'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '4.0'
82
+ version: '5.2'
83
83
  description: The Mosaico email editor on Rails.
84
84
  email:
85
85
  - cameron@lumoslabs.com
@@ -120,6 +120,9 @@ files:
120
120
  - db/migrate/20170817202255_add_images.rb
121
121
  - db/migrate/20170824233755_add_projects.rb
122
122
  - lib/mosaico.rb
123
+ - lib/mosaico/active_storage_backend.rb
124
+ - lib/mosaico/active_storage_image_backend.rb
125
+ - lib/mosaico/active_storage_placeholder_backend.rb
123
126
  - lib/mosaico/engine.rb
124
127
  - lib/mosaico/local_backend.rb
125
128
  - lib/mosaico/local_image_backend.rb
@@ -517,7 +520,7 @@ files:
517
520
  homepage: https://github.com/lumoslabs/mosaico-rails
518
521
  licenses: []
519
522
  metadata: {}
520
- post_install_message:
523
+ post_install_message:
521
524
  rdoc_options: []
522
525
  require_paths:
523
526
  - lib
@@ -532,9 +535,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
532
535
  - !ruby/object:Gem::Version
533
536
  version: '0'
534
537
  requirements: []
535
- rubyforge_project:
536
- rubygems_version: 2.4.5.5
537
- signing_key:
538
+ rubygems_version: 3.3.19
539
+ signing_key:
538
540
  specification_version: 4
539
541
  summary: The Mosaico email editor on Rails.
540
542
  test_files: []