effective_posts 2.0.0 → 2.0.4

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: 850461d12290e86cc451412a56caaac5fccfc469c58d8a8a716f8b1efc1a0d40
4
- data.tar.gz: 44069bc3c8563a6e91f467a7a9f1458d1cd0e6a3f79eb039abae1be473b76e7f
3
+ metadata.gz: 5b14ecbfb59bf639f5a0950fac43873d6cf2ca7c30aa1a1c69d71250bebf769d
4
+ data.tar.gz: 901c1ceca8dfa718866150dab53c7e5d76b59aa29fa9bd3003b81b1b1cd153af
5
5
  SHA512:
6
- metadata.gz: 8cac1f40075ce9ad990c53ba9f4b0feb2bb887fe9a3b4931e0ed15b5ee574593537b1da261f728e84c08b588e0a2f68ad51a366f4949a93afd037f36b717ff15
7
- data.tar.gz: fd63bde9093980a4f7e41660d6a11f7e317a52fe9ddaaace0b5addda9f6016138ff8feec88771f52ccf76c497b9b2a7715099714ef66ca7c4f8207b30e13930c
6
+ metadata.gz: 4543b3fcfc8068dd7eeb13002d6d793b200c74065efa960e13ce86f787eb3d2635b4d0e33a359227c5da41d4f9eea9438a147603a0329105b2efff08407d390d
7
+ data.tar.gz: d51323feaf466cdda3dff70816929228f8875df491af0c7054db1fb682e72816f4910773f79e0f9ceb6a4bef4cfba19259ad33f9d2dc309d459b2d963cb6f67f
data/README.md CHANGED
@@ -85,54 +85,7 @@ The per_page for posts may be configured via the `/app/config/initializers/effec
85
85
 
86
86
  ## Authorization
87
87
 
88
- All authorization checks are handled via the config.authorization_method found in the `app/config/initializers/effective_posts.rb` file.
89
-
90
- It is intended for flow through to CanCan or Pundit, but neither of those gems are required.
91
-
92
- This method is called by all controller actions with the appropriate action and resource
93
-
94
- Action will be one of [:index, :show, :new, :create, :edit, :update, :destroy]
95
-
96
- Resource will the appropriate Effective::Post object or class
97
-
98
- The authorization method is defined in the initializer file:
99
-
100
- ```ruby
101
- # As a Proc (with CanCan)
102
- config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) }
103
- ```
104
-
105
- ```ruby
106
- # As a Custom Method
107
- config.authorization_method = :my_authorization_method
108
- ```
109
-
110
- and then in your application_controller.rb:
111
-
112
- ```ruby
113
- def my_authorization_method(action, resource)
114
- current_user.is?(:admin) || EffectivePunditPolicy.new(current_user, resource).send('#{action}?')
115
- end
116
- ```
117
-
118
- or disabled entirely:
119
-
120
- ```ruby
121
- config.authorization_method = false
122
- ```
123
-
124
- If the method or proc returns false (user is not authorized) an Effective::AccessDenied exception will be raised
125
-
126
- You can rescue from this exception by adding the following to your application_controller.rb:
127
-
128
- ```ruby
129
- rescue_from Effective::AccessDenied do |exception|
130
- respond_to do |format|
131
- format.html { render 'static_pages/access_denied', :status => 403 }
132
- format.any { render :text => 'Access Denied', :status => 403 }
133
- end
134
- end
135
- ```
88
+ All authorization checks are handled via the effective_resources gem found in the `config/initializers/effective_resources.rb` file.
136
89
 
137
90
  ### Permissions
138
91
 
@@ -155,7 +108,6 @@ There are some obvious additional features that have yet to be implemented:
155
108
  - Some kind of helper for displaying a sidebar for the categories
156
109
  - Post archives and date filtering
157
110
 
158
-
159
111
  ## License
160
112
 
161
113
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
@@ -10,6 +10,7 @@ module Admin
10
10
  end
11
11
 
12
12
  submit :save, 'Save'
13
+ submit :save, 'Save and Add New', redirect: :new
13
14
  submit :save, 'Save and View', redirect: -> { effective_posts.post_path(resource) }
14
15
  submit :save, 'Duplicate', redirect: -> { effective_posts.new_admin_post_path(duplicate_id: resource.id) }
15
16
 
@@ -3,14 +3,14 @@ require 'cgi'
3
3
  module EffectivePostsHelper
4
4
 
5
5
  def effective_posts_header_tags
6
- return unless @post && @post.kind_of?(Effective::Post) && @post.persisted?
6
+ return unless @post && @post.kind_of?(Effective::Post) && @post.persisted? && @post.published?
7
7
 
8
8
  @effective_pages_og_type = 'article'
9
9
 
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: 'datePublised', content: @post.published_at.strftime('%FT%T%:z')),
13
+ tag(:meta, itemprop: 'datePublished', content: (@post.published_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),
65
- ("on #{post.published_at.strftime('%B %d, %Y at %l:%M %p')}" if datetime),
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),
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
@@ -74,7 +74,7 @@ module EffectivePostsHelper
74
74
  if post.draft?
75
75
  content_tag(:span, 'DRAFT', class: 'badge badge-info')
76
76
  elsif post.published? == false
77
- content_tag(:span, "TO BE PUBLISHED AT #{post.published_at.strftime('%F %H:%M')}", class: 'badge badge-info')
77
+ content_tag(:span, "TO BE PUBLISHED AT #{post.published_at&.strftime('%F %H:%M') || 'LATER'}", class: 'badge badge-info')
78
78
  end
79
79
  end
80
80
 
@@ -47,7 +47,7 @@ module Effective
47
47
  validates :title, presence: true, length: { maximum: 255 }
48
48
  validates :description, presence: true, length: { maximum: 150 }
49
49
  validates :category, presence: true
50
- validates :published_at, presence: true
50
+ validates :published_at, presence: true, unless: -> { draft? }
51
51
 
52
52
  validates :start_at, presence: true, if: -> { category == 'events' }
53
53
 
@@ -107,7 +107,7 @@ module Effective
107
107
  end
108
108
 
109
109
  def send_post_submitted_to_admin!
110
- deliver_method = EffectivePosts.mailer[:deliver_method] || raise('expected an EffectivePosts.deliver_method')
110
+ deliver_method = EffectivePosts.mailer[:deliver_method] || EffectiveResources.deliver_method
111
111
  Effective::PostsMailer.post_submitted_to_admin(to_param).send(deliver_method)
112
112
  end
113
113
 
@@ -118,9 +118,8 @@ module Effective
118
118
  post.slug = post.slug + '-copy'
119
119
  post.draft = true
120
120
 
121
- regions.each do |region|
122
- post.regions.build(region.attributes.except('id', 'updated_at', 'created_at'))
123
- end
121
+ post.body = body
122
+ post.excerpt = excerpt
124
123
  end
125
124
  end
126
125
 
@@ -4,17 +4,17 @@
4
4
  - if f.object.persisted? || f.object.errors.include?(:slug)
5
5
  - current_url = effective_posts.post_path(f.object)
6
6
 
7
- = f.rich_text_area :excerpt, hint: 'Will be used for the post excerpt on index pages.'
7
+ = f.text_field :slug, required: f.object.persisted?,
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
8
9
 
9
- = f.text_field :slug, required: f.object.persisted?,
10
- 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
10
+ = f.rich_text_area :excerpt, hint: 'Will be used for the post excerpt on index pages.'
11
11
 
12
12
  = f.text_field :description, hint: 'The content of the post meta tags.', maxlength: 150
13
13
 
14
14
  - if Array(EffectivePosts.categories).length > 1
15
15
  = f.select :category, EffectivePosts.categories
16
16
  - else
17
- = f.hidden_field :category, (EffectivePosts.categories.first || 'posts')
17
+ = f.hidden_field :category, value: (EffectivePosts.categories.first || 'posts')
18
18
 
19
19
  - if EffectivePosts.use_active_storage
20
20
  = f.file_field :image, hint: 'An image for your post'
@@ -32,8 +32,6 @@
32
32
 
33
33
  = f.submit do
34
34
  = f.save 'Save'
35
-
36
35
  = f.save 'Save and View', class: 'btn btn-secondary'
37
-
38
36
  - if f.object.persisted?
39
37
  = f.save 'Duplicate', class: 'btn btn-info'
@@ -13,7 +13,7 @@
13
13
  - if EffectivePosts.use_active_storage
14
14
  = f.file_field :image, hint: 'An image for your post'
15
15
 
16
- = f.ck_editor :excerpt, hint: 'Will be used for the post excerpt on index pages.'
16
+ = f.rich_text_area :excerpt, hint: 'Will be used for the post excerpt on index pages.'
17
17
  = f.text_field :description, hint: 'The content of the post meta tags.', maxlength: 150
18
18
 
19
19
  = render partial: '/effective/posts/additional_fields', locals: { post: post, form: f, f: f }
@@ -22,7 +22,6 @@
22
22
 
23
23
  = f.check_box :draft, hint: 'Save this post as a draft. It will not be accessible on the website.'
24
24
 
25
- - unless EffectivePosts.use_fullscreen_editor
26
- = f.ck_editor :body, hint: 'The content of your post.'
25
+ = f.rich_text_area :body, hint: 'The main body of your post'
27
26
 
28
27
  = f.submit 'Save'
@@ -35,9 +35,6 @@ EffectivePosts.setup do |config|
35
35
  # Display the effective roles 'choose roles' input when an admin creates a new post
36
36
  config.use_effective_roles = false
37
37
 
38
- # Hides the Save and Edit Content links from admin. They can just use the textarea input.
39
- config.use_fullscreen_editor = true
40
-
41
38
  # Display a file upload field when the admin creates a new post to collect a post.image
42
39
  config.use_active_storage = true
43
40
 
data/config/routes.rb CHANGED
@@ -1,38 +1,35 @@
1
1
  EffectivePosts::Engine.routes.draw do
2
2
  namespace :admin do
3
3
  resources :posts, except: [:show] do
4
- if EffectivePosts.submissions_enabled && EffectivePosts.submissions_require_approval
5
- post :approve, on: :member
6
- end
4
+ post :approve, on: :member
7
5
  end
8
-
9
- match 'posts/excerpts', to: 'posts#excerpts', via: :get
10
6
  end
11
7
 
12
8
  scope module: 'effective' do
13
- categories = Array(EffectivePosts.categories).map { |cat| cat.to_s unless cat == 'posts'}.compact
14
- onlies = ([:index, :show] unless EffectivePosts.submissions_enabled)
9
+ # Post Routes
10
+ resources :posts
15
11
 
16
- if EffectivePosts.use_blog_routes
17
- categories.each do |category|
18
- match "blog/category/#{category}", to: 'posts#index', via: :get, defaults: { category: category }
19
- end
12
+ # Blog Routes
13
+ match 'blog/category/:category', to: 'posts#index', via: :get, constraints: lambda { |req|
14
+ EffectivePosts.use_blog_routes && EffectivePosts.categories.include?(req.params['category'].to_sym)
15
+ }
20
16
 
21
- resources :posts, only: onlies, path: 'blog'
22
- elsif EffectivePosts.use_category_routes
23
- categories.each do |category|
24
- match category, to: 'posts#index', via: :get, defaults: { category: category }
25
- match "#{category}/:id", to: 'posts#show', via: :get, defaults: { category: category }
26
- end
17
+ resources :posts, only: [:index, :show], path: 'blog', constraints: lambda { |req|
18
+ EffectivePosts.use_blog_routes
19
+ }
27
20
 
28
- resources :posts, only: onlies
29
- else
30
- resources :posts, only: onlies
31
- end
21
+ # Category routes
22
+ match ':category', to: 'posts#index', via: :get, constraints: lambda { |req|
23
+ EffectivePosts.use_category_routes && EffectivePosts.categories.include?(req.params['category'].to_sym)
24
+ }
25
+
26
+ match ":category/:id", to: 'posts#show', via: :get, constraints: lambda { |req|
27
+ EffectivePosts.use_category_routes && EffectivePosts.categories.include?(req.params['category'].to_sym)
28
+ }
32
29
  end
33
30
 
34
31
  end
35
32
 
36
33
  Rails.application.routes.draw do
37
- mount EffectivePosts::Engine => '/', :as => 'effective_posts'
34
+ mount EffectivePosts::Engine => '/', as: 'effective_posts'
38
35
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePosts
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.0.4'.freeze
3
3
  end
@@ -1,4 +1,3 @@
1
- require 'effective_datatables'
2
1
  require 'effective_resources'
3
2
  require 'effective_posts/engine'
4
3
  require 'effective_posts/version'
@@ -9,7 +8,7 @@ module EffectivePosts
9
8
  [
10
9
  :posts_table_name, :layout, :categories,
11
10
  :use_category_routes, :use_blog_routes,
12
- :use_effective_roles, :use_fullscreen_editor, :use_active_storage,
11
+ :use_effective_roles, :use_active_storage,
13
12
  :per_page, :post_meta_author,
14
13
  :submissions_enabled, :submissions_require_current_user,
15
14
  :submissions_require_approval, :submissions_note,
@@ -20,7 +19,7 @@ module EffectivePosts
20
19
  include EffectiveGem
21
20
 
22
21
  def self.permitted_params
23
- [
22
+ @permitted_params ||= [
24
23
  :title, :excerpt, :description, :draft, :category, :slug, :published_at, :body, :tags, :extra,
25
24
  :image, :start_at, :end_at, :location, :website_name, :website_href, roles: []
26
25
  ]
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.0
4
+ version: 2.0.4
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: 2021-02-22 00:00:00.000000000 Z
11
+ date: 2022-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails