effective_posts 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b14ecbfb59bf639f5a0950fac43873d6cf2ca7c30aa1a1c69d71250bebf769d
4
- data.tar.gz: 901c1ceca8dfa718866150dab53c7e5d76b59aa29fa9bd3003b81b1b1cd153af
3
+ metadata.gz: 64936be0ce130f2c9b5d5fe918d217cf01e77648adfd28440e288d24f45da34e
4
+ data.tar.gz: cf67a0e59a0f7d11b6d6083d83a8d561009f12716ad249fb7a3072dde2f72232
5
5
  SHA512:
6
- metadata.gz: 4543b3fcfc8068dd7eeb13002d6d793b200c74065efa960e13ce86f787eb3d2635b4d0e33a359227c5da41d4f9eea9438a147603a0329105b2efff08407d390d
7
- data.tar.gz: d51323feaf466cdda3dff70816929228f8875df491af0c7054db1fb682e72816f4910773f79e0f9ceb6a4bef4cfba19259ad33f9d2dc309d459b2d963cb6f67f
6
+ metadata.gz: 519ffb8e746373b2473129b55b9fe471fa824e4ed06b89bfca95f34a3908f029526d7d07654ce444bda2175106ae6c5233e200cf747129b086951070e322a94d
7
+ data.tar.gz: 271fc10da03adfe19b837b8bd0c72e5e8ccc074ecce114a098cde2979411ea0149b1583c999c440d4c303679df6229a3abd3f1dec840d526dab0465fd19ffcae
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts .js
2
+ //= link_directory ../stylesheets .css
@@ -5,10 +5,6 @@ module Admin
5
5
 
6
6
  include Effective::CrudController
7
7
 
8
- if (config = EffectivePosts.layout)
9
- layout(config.kind_of?(Hash) ? config[:admin] : config)
10
- end
11
-
12
8
  submit :save, 'Save'
13
9
  submit :save, 'Save and Add New', redirect: :new
14
10
  submit :save, 'Save and View', redirect: -> { effective_posts.post_path(resource) }
@@ -7,10 +7,6 @@ module Effective
7
7
 
8
8
  include Effective::CrudController
9
9
 
10
- if (config = EffectivePosts.layout)
11
- layout(config.kind_of?(Hash) ? (config[:application] || config[:posts]) : config)
12
- end
13
-
14
10
  def index
15
11
  @posts ||= Effective::Post.posts(
16
12
  user: current_user,
@@ -79,7 +75,7 @@ module Effective
79
75
  flash.now[:success] = 'Successfully submitted post'
80
76
 
81
77
  if EffectivePosts.submissions_require_approval
82
- @post.send_post_submitted_to_admin!
78
+ @post.send_post_submitted!
83
79
  end
84
80
 
85
81
  render :submitted
@@ -104,12 +100,12 @@ module Effective
104
100
 
105
101
  EffectiveResources.authorize!(self, :update, @post)
106
102
 
107
- if @post.update_attributes(post_params)
103
+ if @post.update(post_params)
108
104
  @page_title ||= 'Post Submitted'
109
105
  flash.now[:success] = 'Successfully re-submitted post'
110
106
 
111
107
  if EffectivePosts.submissions_require_approval && draft_was != true
112
- @post.send_post_submitted_to_admin!
108
+ @post.send_post_submitted!
113
109
  end
114
110
 
115
111
  render :submitted
@@ -1,35 +1,18 @@
1
1
  module Effective
2
- class PostsMailer < ActionMailer::Base
3
- helper EffectivePostsHelper
4
-
5
- layout EffectivePosts.mailer[:layout].presence || 'effective_posts_mailer_layout'
2
+ class PostsMailer < EffectivePosts.parent_mailer_class
3
+ include EffectiveMailer
6
4
 
7
- def post_submitted_to_admin(post_param)
8
- @post = (post_param.kind_of?(Effective::Post) ? post_param : Effective::Post.find(post_param))
9
-
10
- mail(
11
- to: EffectivePosts.mailer[:admin_email],
12
- from: EffectivePosts.mailer[:default_from],
13
- subject: subject_for_post_submitted_to_admin(@post),
14
- tenant: (Tenant.current if defined?(Tenant))
15
- )
16
- end
17
-
18
- private
5
+ helper EffectivePostsHelper
19
6
 
20
- def subject_for_post_submitted_to_admin(post)
21
- string_or_callable = EffectivePosts.mailer[:subject_for_post_submitted_to_admin]
7
+ def post_submitted(resource, opts = {})
8
+ raise('expected an Effective::Post') unless resource.kind_of?(Effective::Post)
22
9
 
23
- if string_or_callable.respond_to?(:call) # This is a Proc or a function, not a string
24
- string_or_callable = self.instance_exec(post, &string_or_callable)
25
- end
10
+ @post = resource
11
+ subject = subject_for(__method__, 'Post Submitted', resource, opts)
12
+ headers = headers_for(resource, opts)
26
13
 
27
- prefix_subject(string_or_callable.presence || "A new post has been submitted that needs approval")
14
+ mail(to: mailer_admin, subject: subject, **headers)
28
15
  end
29
16
 
30
- def prefix_subject(text)
31
- prefix = (EffectivePosts.mailer[:subject_prefix].to_s rescue '')
32
- prefix.present? ? (prefix.chomp(' ') + ' ' + text) : text
33
- end
34
17
  end
35
18
  end
@@ -106,9 +106,8 @@ module Effective
106
106
  (regions.to_a.sum { |region| (region.content || '').scan(/\w+/).size } / reading_speed).seconds
107
107
  end
108
108
 
109
- def send_post_submitted_to_admin!
110
- deliver_method = EffectivePosts.mailer[:deliver_method] || EffectiveResources.deliver_method
111
- Effective::PostsMailer.post_submitted_to_admin(to_param).send(deliver_method)
109
+ def send_post_submitted!
110
+ EffectivePosts.send_email(:post_submitted, self)
112
111
  end
113
112
 
114
113
  # Returns a duplicated post object, or throws an exception
@@ -8,7 +8,7 @@
8
8
  - if Array(EffectivePosts.categories).length > 1
9
9
  = f.select :category, EffectivePosts.categories
10
10
  - else
11
- = f.hidden_field :category, (EffectivePosts.categories.first || 'posts')
11
+ = f.hidden_field :category, value: (EffectivePosts.categories.first || 'posts')
12
12
 
13
13
  - if EffectivePosts.use_active_storage
14
14
  = f.file_field :image, hint: 'An image for your post'
@@ -7,4 +7,4 @@
7
7
 
8
8
  %hr
9
9
 
10
- = render file: '/effective/posts/show'
10
+ = render template: 'effective/posts/show'
@@ -1,6 +1,6 @@
1
1
  %p A new post has been submitted and needs your approval before it may be displayed on the website:
2
2
 
3
- %p= link_to 'Approve Post', effective_posts.admin_approve_post_path(@post)
3
+ %p= link_to 'Approve Post', effective_posts.approve_admin_post_url(@post)
4
4
 
5
5
  %hr
6
6
 
@@ -19,4 +19,4 @@
19
19
 
20
20
  %hr
21
21
 
22
- %p= link_to 'Approve Post', effective_posts.admin_approve_post_path(@post)
22
+ %p= link_to 'Approve Post', effective_posts.approve_admin_post_url(@post)
@@ -3,7 +3,7 @@ EffectivePosts.setup do |config|
3
3
 
4
4
  # Every post must belong to one or more category.
5
5
  # Don't use the category :posts
6
- config.categories = [:news, :events]
6
+ config.categories = [:news]
7
7
 
8
8
  # Create top level routes for each category
9
9
  # Should each of the above categories have a top level route created for it
@@ -49,31 +49,20 @@ EffectivePosts.setup do |config|
49
49
  config.submissions_require_approval = true
50
50
 
51
51
  # The Thank you message when they submit a post
52
- config.submissions_note = "News & Event submitted! A confirmation email has been sent to the website owner. When approved, your submission will appear on the website."
52
+ config.submissions_note = "Post submitted! A confirmation email has been sent to the website owner. When approved, your submission will appear on the website."
53
53
 
54
54
  # Mailer Settings
55
- # effective_posts will send the admin an email when a post is submitted
56
- # For all the emails, the same :subject_prefix will be prefixed. Leave as nil / empty string if you don't want any prefix
55
+ # Please see config/initializers/effective_resources.rb for default effective_* gem mailer settings
57
56
  #
58
- # The subject_for_post_submitted_to_admin can be one of:
59
- # - nil / empty string to use the built in defaults
60
- # - A string with the full subject line for this email
61
- # - A Proc to create the subject line based on the email
62
- # In all three of these cases, the subject_prefix will still be used.
63
-
64
- # The Procs are the same for admin & buyer receipt, the seller Proc is different
65
- # subject_for_post_submitted_to_admin: Proc.new { |post| "Post needs approval"}
66
-
67
- config.mailer = {
68
- subject_prefix: '[example]',
69
- subject_for_post_submitted_to_admin: '',
70
-
71
- layout: 'effective_posts_mailer_layout',
72
-
73
- default_from: 'info@example.com',
74
- admin_email: 'admin@example.com',
75
-
76
- deliver_method: :deliver_now
77
- }
78
-
57
+ # Configure the class responsible to send e-mails.
58
+ # config.mailer = 'Effective::PostsMailer'
59
+ #
60
+ # Override effective_resource mailer defaults
61
+ #
62
+ # config.parent_mailer = nil # The parent class responsible for sending emails
63
+ # config.deliver_method = nil # The deliver method, deliver_later or deliver_now
64
+ # config.mailer_layout = nil # Default mailer layout
65
+ # config.mailer_sender = nil # Default From value
66
+ # config.mailer_admin = nil # Default To value for Admin correspondence
67
+ # config.mailer_subject = nil # Proc.new method used to customize Subject
79
68
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePosts
2
- VERSION = '2.0.4'.freeze
2
+ VERSION = '2.0.5'.freeze
3
3
  end
@@ -7,17 +7,21 @@ module EffectivePosts
7
7
  def self.config_keys
8
8
  [
9
9
  :posts_table_name, :layout, :categories,
10
+ :mailer, :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject,
10
11
  :use_category_routes, :use_blog_routes,
11
12
  :use_effective_roles, :use_active_storage,
12
13
  :per_page, :post_meta_author,
13
14
  :submissions_enabled, :submissions_require_current_user,
14
- :submissions_require_approval, :submissions_note,
15
- :mailer
15
+ :submissions_require_approval, :submissions_note
16
16
  ]
17
17
  end
18
18
 
19
19
  include EffectiveGem
20
20
 
21
+ def self.mailer_class
22
+ mailer&.constantize || Effective::PostsMailer
23
+ end
24
+
21
25
  def self.permitted_params
22
26
  @permitted_params ||= [
23
27
  :title, :excerpt, :description, :draft, :category, :slug, :published_at, :body, :tags, :extra,
@@ -3,8 +3,8 @@
3
3
  # to see a preview of the following 3 emails:
4
4
 
5
5
  class EffectivePostsMailerPreview < ActionMailer::Preview
6
- def post_submitted_to_admin
7
- Effective::PostsMailer.post_submitted_to_admin(build_preview_post)
6
+ def post_submitted
7
+ EffectivePosts.mailer_class.post_submitted(build_preview_post)
8
8
  end
9
9
 
10
10
  protected
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_posts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-03 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -90,6 +90,7 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - MIT-LICENSE
92
92
  - README.md
93
+ - app/assets/config/effective_posts_manifest.js
93
94
  - app/assets/javascripts/effective_posts.js
94
95
  - app/assets/javascripts/effective_posts/additional_fields.js.coffee
95
96
  - app/assets/stylesheets/effective_posts.scss
@@ -118,8 +119,7 @@ files:
118
119
  - app/views/effective/posts/new.html.haml
119
120
  - app/views/effective/posts/show.html.haml
120
121
  - app/views/effective/posts/submitted.html.haml
121
- - app/views/effective/posts_mailer/post_submitted_to_admin.html.haml
122
- - app/views/layouts/effective_posts_mailer_layout.html.haml
122
+ - app/views/effective/posts_mailer/post_submitted.html.haml
123
123
  - config/effective_posts.rb
124
124
  - config/routes.rb
125
125
  - db/migrate/01_create_effective_posts.rb.erb
@@ -1,7 +0,0 @@
1
- !!!
2
- %html{style: 'background: #fff;'}
3
- %head
4
- %meta{:content => 'text/html; charset=UTF-8', 'http-equiv' => 'Content-Type'}
5
-
6
- %body{style: 'background: #fff;'}
7
- = yield