effective_posts 2.0.4 → 2.1.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
2
  SHA256:
3
- metadata.gz: 5b14ecbfb59bf639f5a0950fac43873d6cf2ca7c30aa1a1c69d71250bebf769d
4
- data.tar.gz: 901c1ceca8dfa718866150dab53c7e5d76b59aa29fa9bd3003b81b1b1cd153af
3
+ metadata.gz: 1ceb1f23b04e83df1d9e2f1392dc541e9f80631bd503b95fd787fd0a41608e06
4
+ data.tar.gz: 6171ca2f46ba3c5124b804fc06ddb6b27b405be2a2669fed7fc19fae095af9a5
5
5
  SHA512:
6
- metadata.gz: 4543b3fcfc8068dd7eeb13002d6d793b200c74065efa960e13ce86f787eb3d2635b4d0e33a359227c5da41d4f9eea9438a147603a0329105b2efff08407d390d
7
- data.tar.gz: d51323feaf466cdda3dff70816929228f8875df491af0c7054db1fb682e72816f4910773f79e0f9ceb6a4bef4cfba19259ad33f9d2dc309d459b2d963cb6f67f
6
+ metadata.gz: 1565992dbf8ab2e6b25ab0772bdcbc05193fb42591091cc40a05f847515e5d18416f14aa6c42afbb3afce19d4eb0fb7d9fe63514ca03c6ae0d4d22a3f4519a91
7
+ data.tar.gz: 9425f6f6c6ea39f60d89392dfbcf3e50d132e25da4b670d5e09851c88538eb89140e63b4d6741fb98143a8fbf21f458857f99fd6e0caac2b91b2f788949f23ed
@@ -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
@@ -7,7 +7,10 @@
7
7
  = f.text_field :slug, required: f.object.persisted?,
8
8
  hint: "The slug controls this post's internet address. Be careful, changing the slug will break links that other websites may have to the old address.<br>#{('This post is currently reachable via ' + link_to(current_url.gsub(f.object.slug, '<strong>' + f.object.slug + '</strong>').html_safe, current_url)) if current_url && f.object.slug.present? }".html_safe
9
9
 
10
- = f.rich_text_area :excerpt, hint: 'Will be used for the post excerpt on index pages.'
10
+ - if defined?(EffectiveArticleEditor)
11
+ = f.article_editor :excerpt, hint: 'Will be used for the post excerpt on index pages.'
12
+ - else
13
+ = f.rich_text_area :excerpt, hint: 'Will be used for the post excerpt on index pages.'
11
14
 
12
15
  = f.text_field :description, hint: 'The content of the post meta tags.', maxlength: 150
13
16
 
@@ -19,7 +22,10 @@
19
22
  - if EffectivePosts.use_active_storage
20
23
  = f.file_field :image, hint: 'An image for your post'
21
24
 
22
- = f.rich_text_area :body, hint: 'The main body of your post'
25
+ - if defined?(EffectiveArticleEditor)
26
+ = f.article_editor :body, hint: 'The main body of your post'
27
+ - else
28
+ = f.rich_text_area :body, hint: 'The main body of your post'
23
29
 
24
30
  = render partial: '/effective/posts/additional_fields', locals: { post: post, form: f, f: f }
25
31
 
@@ -8,12 +8,16 @@
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'
15
15
 
16
- = f.rich_text_area :excerpt, hint: 'Will be used for the post excerpt on index pages.'
16
+ - if defined?(EffectiveArticleEditor)
17
+ = f.article_editor :excerpt, hint: 'Will be used for the post excerpt on index pages.'
18
+ - else
19
+ = f.rich_text_area :excerpt, hint: 'Will be used for the post excerpt on index pages.'
20
+
17
21
  = f.text_field :description, hint: 'The content of the post meta tags.', maxlength: 150
18
22
 
19
23
  = render partial: '/effective/posts/additional_fields', locals: { post: post, form: f, f: f }
@@ -22,6 +26,9 @@
22
26
 
23
27
  = f.check_box :draft, hint: 'Save this post as a draft. It will not be accessible on the website.'
24
28
 
25
- = f.rich_text_area :body, hint: 'The main body of your post'
29
+ - if defined?(EffectiveArticleEditor)
30
+ = f.article_editor :body, hint: 'The main body of your post'
31
+ - else
32
+ = f.rich_text_area :body, hint: 'The main body of your post'
26
33
 
27
34
  = f.submit 'Save'
@@ -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
@@ -4,8 +4,10 @@ module EffectivePosts
4
4
 
5
5
  # Include Helpers to base application
6
6
  initializer 'effective_posts.action_controller' do |app|
7
- ActiveSupport.on_load :action_controller_base do
8
- helper EffectivePostsHelper
7
+ app.config.to_prepare do
8
+ ActiveSupport.on_load :action_controller_base do
9
+ helper EffectivePostsHelper
10
+ end
9
11
  end
10
12
  end
11
13
 
@@ -1,3 +1,3 @@
1
1
  module EffectivePosts
2
- VERSION = '2.0.4'.freeze
2
+ VERSION = '2.1.0'.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.1.0
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-08-24 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