effective_posts 2.5.0 → 2.6.1

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: fb8b8e024f90c5178e6904396c0f2e565d54e5b4eb0eac92c41e9442089016c3
4
- data.tar.gz: bfe539309dbf2538961d899773af1855a54127864f8fcd98f9e375b1500bd452
3
+ metadata.gz: aaf7679098b16b2853e689c0d78cacf05510f8288c586707434dea3c11b431a5
4
+ data.tar.gz: 1f8c557e1b97598672a56fb49a80ea8c0164382f2e3bc8716ad158359fdcfe38
5
5
  SHA512:
6
- metadata.gz: 821dc29782ba4a54c87425c9fec3f993d1febcd5b43c5b256462df60f700afddde1e07eb2bd803af1508c4b359ffda6f7f4e3c956ce8facd70c751d9b9590ba9
7
- data.tar.gz: bbf9908b09e91896d285496ef14aa59bf1eab7bd07ef479ae7d528a91801a9705b439a5c78365fa78ee648b25118e46dce7488c053c92b346c33b4bd14311474
6
+ metadata.gz: af3804cb3d8b710c4589575401a41647dad5ab90204dc64f04a874f983e230763643ba4f97c455d40aabe63361bc1f7c17da007ae1397dd4b8d8d85b46cc5b46
7
+ data.tar.gz: f072f4473950ffc7c1dc58ae33c94e1cd5cb1b9cd5b8f722d3775a562dd914e393a9a359511bb58821408db076040418d9ddccd5a17248533bd3e6c201595f95
@@ -64,7 +64,7 @@ module Effective
64
64
 
65
65
  # Public user submit a post functionality
66
66
  def new
67
- @post ||= Effective::Post.new(published_at: Time.zone.now)
67
+ @post ||= Effective::Post.new
68
68
  @page_title = 'New Post'
69
69
 
70
70
  EffectiveResources.authorize!(self, :new, @post)
@@ -7,33 +7,27 @@ class EffectivePostsDatatable < Effective::Datatable
7
7
  filters do
8
8
  scope :unarchived, label: 'All'
9
9
  scope :published
10
- scope :unpublished
10
+ scope :draft
11
11
  scope :news
12
12
  scope :events
13
13
  scope :archived
14
14
  end
15
15
 
16
16
  datatable do
17
- order :published_at, :desc
17
+ order :published_start_at, :desc
18
18
 
19
19
  bulk_actions_col
20
20
 
21
- col :published_at
22
21
  col :id, visible: false
23
22
 
24
23
  col :title
25
24
  col :slug, visible: false
26
25
  col :category, search: { collection: EffectivePosts.categories }
27
26
 
28
- if EffectivePosts.submissions_enabled
29
- col :approved, sql_column: 'NOT(draft)', as: :boolean do |post|
30
- post.draft? ? 'No' : 'Yes'
31
- end
32
-
33
- col :draft, visible: false
34
- else
35
- col :draft
36
- end
27
+ col :draft?, as: :boolean, visible: false
28
+ col :published?, as: :boolean
29
+ col :published_start_at
30
+ col :published_end_at
37
31
 
38
32
  col :archived
39
33
 
@@ -10,7 +10,7 @@ module EffectivePostsHelper
10
10
  tags = [
11
11
  tag(:meta, itemprop: 'author', content: @post.user.to_s),
12
12
  tag(:meta, itemprop: 'publisher', content: @post.user.to_s),
13
- tag(:meta, itemprop: 'datePublished', content: (@post.published_at || Time.zone.now).strftime('%FT%T%:z')),
13
+ tag(:meta, itemprop: 'datePublished', content: (@post.published_start_at || Time.zone.now).strftime('%FT%T%:z')),
14
14
  tag(:meta, itemprop: 'headline', content: @post.title)
15
15
  ].join("\n").html_safe
16
16
  end
@@ -61,8 +61,8 @@ module EffectivePostsHelper
61
61
  def post_meta(post, date: true, datetime: false, category: true, author: true)
62
62
  [
63
63
  'Published',
64
- ("on #{post.published_at.strftime('%B %d, %Y')}" if date && post.published_at),
65
- ("on #{post.published_at.strftime('%B %d, %Y at %l:%M %p')}" if datetime && post.published_at),
64
+ ("on #{post.published_start_at.strftime('%B %d, %Y')}" if date && post.published_start_at),
65
+ ("on #{post.published_start_at.strftime('%B %d, %Y at %l:%M %p')}" if datetime && post.published_start_at),
66
66
  ("to #{link_to_post_category(post.category)}" if category && Array(EffectivePosts.categories).length > 1),
67
67
  ("by #{post.user.to_s.presence || 'Unknown'}" if author && EffectivePosts.post_meta_author && post.user.present?)
68
68
  ].compact.join(' ').html_safe
@@ -76,7 +76,7 @@ module EffectivePostsHelper
76
76
  elsif post.draft?
77
77
  content_tag(:span, 'DRAFT', class: 'badge badge-info')
78
78
  elsif post.published? == false
79
- content_tag(:span, "TO BE PUBLISHED AT #{post.published_at&.strftime('%F %H:%M') || 'LATER'}", class: 'badge badge-info')
79
+ content_tag(:span, "TO BE PUBLISHED AT #{post.published_start_at&.strftime('%F %H:%M') || 'LATER'}", class: 'badge badge-info')
80
80
  end
81
81
  end
82
82
 
@@ -1,5 +1,7 @@
1
1
  module Effective
2
2
  class Post < ActiveRecord::Base
3
+ self.table_name = (EffectivePosts.posts_table_name || :posts).to_s
4
+
3
5
  if defined?(PgSearch)
4
6
  include PgSearch::Model
5
7
 
@@ -8,22 +10,20 @@ module Effective
8
10
 
9
11
  attr_accessor :current_user
10
12
 
13
+ belongs_to :user, polymorphic: true, optional: true
14
+
15
+ acts_as_role_restricted if respond_to?(:acts_as_role_restricted)
11
16
  acts_as_archived
17
+ acts_as_published
12
18
  acts_as_slugged
13
-
14
- log_changes if respond_to?(:log_changes)
15
19
  acts_as_tagged if respond_to?(:acts_as_tagged)
16
- acts_as_role_restricted if respond_to?(:acts_as_role_restricted)
20
+ log_changes if respond_to?(:log_changes)
17
21
 
18
22
  has_one_attached :image
19
23
 
20
24
  has_rich_text :excerpt
21
25
  has_rich_text :body
22
26
 
23
- self.table_name = (EffectivePosts.posts_table_name || :posts).to_s
24
-
25
- belongs_to :user, polymorphic: true, optional: true
26
-
27
27
  effective_resource do
28
28
  title :string
29
29
  description :string
@@ -31,8 +31,10 @@ module Effective
31
31
  category :string
32
32
  slug :string
33
33
 
34
- draft :boolean
35
- published_at :datetime
34
+ published_start_at :datetime
35
+ published_end_at :datetime
36
+ legacy_draft :boolean # No longer used. To be removed.
37
+
36
38
  tags :text
37
39
 
38
40
  roles_mask :integer
@@ -56,15 +58,12 @@ module Effective
56
58
  validates :title, presence: true, length: { maximum: 255 }
57
59
  validates :description, presence: true, length: { maximum: 150 }
58
60
  validates :category, presence: true
59
- validates :published_at, presence: true, unless: -> { draft? }
60
61
  validates :start_at, presence: true, if: -> { category == 'events' }
61
62
 
62
63
  scope :unarchived, -> { where(archived: false) }
63
64
  scope :archived, -> { where(archived: true) }
64
65
 
65
- scope :drafts, -> { unarchived.where(draft: true) }
66
- scope :published, -> { unarchived.where(draft: false).where("published_at < ?", Time.zone.now) }
67
- scope :unpublished, -> { unarchived.where(draft: true).or(where("published_at > ?", Time.zone.now)) }
66
+ scope :for_sitemap, -> { published.unarchived }
68
67
 
69
68
  # Kind of a meta category
70
69
  scope :news, -> { unarchived.where(category: EffectivePosts.news_categories) }
@@ -86,7 +85,7 @@ module Effective
86
85
  }
87
86
 
88
87
  scope :posts, -> (user: nil, category: nil, unpublished: false, archived: false) {
89
- scope = all.deep.order(published_at: :desc)
88
+ scope = all.deep.order(Arel.sql("published_start_at DESC NULLS LAST"))
90
89
 
91
90
  if defined?(EffectiveRoles) && EffectivePosts.use_effective_roles
92
91
  if user.present? && user.respond_to?(:roles)
@@ -113,12 +112,8 @@ module Effective
113
112
  title.presence || 'New Post'
114
113
  end
115
114
 
116
- def published?
117
- !draft? && published_at.present? && published_at < Time.zone.now
118
- end
119
-
120
115
  def approved?
121
- draft == false
116
+ published?
122
117
  end
123
118
 
124
119
  def event?
@@ -145,11 +140,12 @@ module Effective
145
140
  post.assign_attributes(
146
141
  title: post.title + ' (Copy)',
147
142
  slug: post.slug + '-copy',
148
- draft: true,
149
143
  body: body,
150
144
  excerpt: excerpt
151
145
  )
152
146
 
147
+ post.assign_attributes(published_start_at: nil, published_end_at: nil)
148
+
153
149
  post
154
150
  end
155
151
 
@@ -158,7 +154,7 @@ module Effective
158
154
  end
159
155
 
160
156
  def approve!
161
- update!(draft: false)
157
+ update!(published_start_at: Time.zone.now)
162
158
  end
163
159
 
164
160
  end
@@ -1,6 +1,20 @@
1
1
  = effective_form_with(model: [:admin, post], engine: true) do |f|
2
2
  = f.text_field :title, hint: 'The title of your post.'
3
3
 
4
+ -# acts_as_published
5
+ = f.hide_if(:save_as_draft, true) do
6
+ .row
7
+ .col-md-6
8
+ = f.datetime_field :published_start_at, hint: 'The page will be available starting on this date and time.'
9
+ .col-md-6
10
+ = f.datetime_field :published_end_at, hint: 'The page will no longer be available after this date and time. Leave blank for no end date.', date_linked: false
11
+
12
+ = f.check_box :save_as_draft, label: "Save as a draft. It will not appear on the website and can only be accessed by admin users."
13
+
14
+ = f.text_field :description,
15
+ hint: "150 character summary. Appears on Google search results underneath the post title. ",
16
+ input_html: { maxlength: 150 }
17
+
4
18
  - if f.object.persisted? || f.object.errors.include?(:slug)
5
19
  - current_url = effective_posts.post_path(f.object)
6
20
 
@@ -12,8 +26,6 @@
12
26
  - else
13
27
  = f.rich_text_area :excerpt, hint: 'Will be used for the post excerpt on index pages.'
14
28
 
15
- = f.text_field :description, hint: 'The content of the post meta tags.', maxlength: 150
16
-
17
29
  - if Array(EffectivePosts.categories).length > 1
18
30
  = f.select :category, EffectivePosts.categories
19
31
  - else
@@ -32,10 +44,6 @@
32
44
 
33
45
  = render partial: '/effective/posts/additional_fields', locals: { post: post, form: f, f: f }
34
46
 
35
- = f.datetime_field :published_at, label: 'Publish date', hint: 'When should this be displayed on the website.'
36
-
37
- = f.check_box :draft, hint: 'Save this post as a draft. It will not be accessible on the website.'
38
-
39
47
  = f.check_box :archived, label: 'Yes, this post is archived. It will not be displayed.'
40
48
 
41
49
  - if EffectivePosts.use_effective_roles
@@ -22,10 +22,6 @@
22
22
 
23
23
  = render partial: '/effective/posts/additional_fields', locals: { post: post, form: f, f: f }
24
24
 
25
- = f.datetime_field :published_at, label: 'Publish date', hint: 'When should this be displayed on the website.'
26
-
27
- = f.check_box :draft, hint: 'Save this post as a draft. It will not be accessible on the website.'
28
-
29
25
  - if defined?(EffectiveArticleEditor)
30
26
  = f.article_editor :body, hint: 'The main body of your post'
31
27
  - else
@@ -10,8 +10,9 @@ class CreateEffectivePosts < ActiveRecord::Migration[6.0]
10
10
  t.string :category
11
11
  t.string :slug
12
12
 
13
- t.boolean :draft, default: false
14
- t.datetime :published_at
13
+ t.datetime :published_start_at
14
+ t.datetime :published_end_at
15
+ t.boolean :legacy_draft, default: false
15
16
 
16
17
  t.text :tags
17
18
 
@@ -1,3 +1,3 @@
1
1
  module EffectivePosts
2
- VERSION = '2.5.0'.freeze
2
+ VERSION = '2.6.1'.freeze
3
3
  end
@@ -25,7 +25,7 @@ module EffectivePosts
25
25
 
26
26
  def self.permitted_params
27
27
  @permitted_params ||= [
28
- :title, :excerpt, :description, :draft, :category, :slug, :published_at, :body, :tags, :extra,
28
+ :title, :excerpt, :description, :save_as_draft, :category, :slug, :published_start_at, :published_end_at, :body, :tags, :extra,
29
29
  :image, :start_at, :end_at, :location, :website_name, :website_href, roles: []
30
30
  ]
31
31
  end
@@ -13,8 +13,6 @@ class EffectivePostsMailerPreview < ActionMailer::Preview
13
13
  post = Effective::Post.new(
14
14
  title: 'An example post',
15
15
  category: EffectivePosts.categories.first.presence || 'posts',
16
- published_at: Time.zone.now,
17
- draft: true,
18
16
  body: 'This is a new post that has been submitted by a public user.'
19
17
  )
20
18
  end
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.5.0
4
+ version: 2.6.1
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: 2024-06-12 00:00:00.000000000 Z
11
+ date: 2024-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails