effective_posts 0.5.0 → 0.5.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 +4 -4
- data/app/assets/javascripts/effective_pages/additional_fields.js.coffee +8 -0
- data/app/assets/javascripts/effective_posts.js +1 -0
- data/app/controllers/effective/posts_controller.rb +9 -0
- data/app/helpers/effective_posts_helper.rb +22 -9
- data/app/models/effective/post.rb +27 -9
- data/app/views/admin/posts/excerpts.html.haml +2 -5
- data/app/views/effective/posts/_additional_fields.html.haml +19 -2
- data/app/views/effective/posts/_categories.html.haml +1 -1
- data/app/views/effective/posts/_form.html.haml +3 -3
- data/app/views/effective/posts/_post.html.haml +24 -4
- data/app/views/effective/posts/_upcoming_events.html.haml +5 -0
- data/app/views/effective/posts/show.html.haml +24 -4
- data/config/effective_posts.rb +9 -6
- data/db/migrate/01_create_effective_posts.rb.erb +9 -1
- data/lib/effective_posts.rb +5 -1
- data/lib/effective_posts/version.rb +1 -1
- data/lib/generators/templates/effective_posts_mailer_preview.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be81ac9b127e592c28c261f3853fa5eae6947c14
|
4
|
+
data.tar.gz: 3200a7c2d3b17e51a289a2880473d948a8315a35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8baf180a6ca1485eefc7d68749c5298688af411018665f3a02b3681637787bf44919fd6ddedc0c68a0139aa7d7b3ba09bb2222325dc948aded7ce043026ac653
|
7
|
+
data.tar.gz: 330c929ee5a515492eae9d7624c786906c847c4648db0b68f2b24d8f047748c92f3028549b67182dda14d31329693c81d622cca213ad260528690a72d1784ee8
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Show/hide the Event fields on admin/posts form
|
2
|
+
|
3
|
+
$(document).on 'change', "select[name='effective_post[category]']", (event) ->
|
4
|
+
obj = $(event.currentTarget)
|
5
|
+
|
6
|
+
obj.closest('form').find("[class^='effective-post-category-']").hide()
|
7
|
+
obj.closest('form').find(".effective-post-category-#{obj.val()}").show()
|
8
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require effective_pages/additional_fields
|
@@ -11,6 +11,15 @@ module Effective
|
|
11
11
|
@posts ||= Effective::Post.posts(user: current_user, category: params[:category])
|
12
12
|
@posts = @posts.page(params[:page]).per(EffectivePosts.per_page)
|
13
13
|
|
14
|
+
if params[:category] == 'events'
|
15
|
+
@posts = @posts.reorder(:start_at).where('start_at > ?', Time.zone.now)
|
16
|
+
end
|
17
|
+
|
18
|
+
if params[:search].present?
|
19
|
+
search = params[:search].permit(EffectivePosts.permitted_params).delete_if { |k, v| v.blank? }
|
20
|
+
@posts = @posts.where(search) if search.present?
|
21
|
+
end
|
22
|
+
|
14
23
|
EffectivePosts.authorized?(self, :index, Effective::Post)
|
15
24
|
|
16
25
|
@page_title = (params[:page_title] || params[:category] || params[:defaults].try(:[], :category) || 'Posts').titleize
|
@@ -6,7 +6,7 @@ module EffectivePostsHelper
|
|
6
6
|
opts ||= {}
|
7
7
|
|
8
8
|
if EffectivePosts.use_category_routes
|
9
|
-
|
9
|
+
effective_posts.post_path(post, opts).sub('/posts', "/#{category}")
|
10
10
|
else
|
11
11
|
effective_posts.post_path(post, opts.merge(category: category))
|
12
12
|
end
|
@@ -37,7 +37,7 @@ module EffectivePostsHelper
|
|
37
37
|
read_more = (read_more_link && label.present?) ? readmore_link(post, label: label) : ''
|
38
38
|
|
39
39
|
CGI.unescapeHTML(if divider.present?
|
40
|
-
truncate_html(content, Effective::Snippets::ReadMoreDivider::TOKEN, '') +
|
40
|
+
truncate_html(content, Effective::Snippets::ReadMoreDivider::TOKEN, '') + read_more
|
41
41
|
elsif length.present?
|
42
42
|
truncate_html(content, length, omission) + read_more
|
43
43
|
else
|
@@ -47,7 +47,7 @@ module EffectivePostsHelper
|
|
47
47
|
|
48
48
|
def read_more_link(post, options)
|
49
49
|
content_tag(:p, class: 'post-read-more') do
|
50
|
-
link_to((options.delete(:label) || 'Read more'),
|
50
|
+
link_to((options.delete(:label) || 'Read more'), effective_post_path(post), (options.delete(:class) || {class: 'btn btn-primary'}).reverse_merge(options))
|
51
51
|
end
|
52
52
|
end
|
53
53
|
alias_method :readmore_link, :read_more_link
|
@@ -58,8 +58,8 @@ module EffectivePostsHelper
|
|
58
58
|
categories = EffectivePosts.categories
|
59
59
|
end
|
60
60
|
|
61
|
-
def render_post_categories
|
62
|
-
render(partial: '/effective/posts/categories', locals: { categories: post_categories })
|
61
|
+
def render_post_categories(reverse: false)
|
62
|
+
render(partial: '/effective/posts/categories', locals: { categories: (reverse ? post_categories.reverse : post_categories) })
|
63
63
|
end
|
64
64
|
|
65
65
|
def link_to_post_category(category, options = {})
|
@@ -71,16 +71,29 @@ module EffectivePostsHelper
|
|
71
71
|
|
72
72
|
### Recent Posts
|
73
73
|
|
74
|
-
def recent_posts(user: current_user, category:
|
75
|
-
@recent_posts ||=
|
74
|
+
def recent_posts(user: current_user, category: 'posts', limit: EffectivePosts.per_page)
|
75
|
+
@recent_posts ||= {}
|
76
|
+
@recent_posts[category] ||= Effective::Post.posts(user: user, category: category).limit(limit)
|
76
77
|
end
|
77
78
|
|
78
|
-
def render_recent_posts(user: current_user, category:
|
79
|
+
def render_recent_posts(user: current_user, category: 'posts', limit: EffectivePosts.per_page)
|
79
80
|
posts = recent_posts(user: user, category: category, limit: limit)
|
80
|
-
|
81
81
|
render partial: '/effective/posts/recent_posts', locals: { posts: posts }
|
82
82
|
end
|
83
83
|
|
84
|
+
### Upcoming Events
|
85
|
+
|
86
|
+
def upcoming_events(user: current_user, category: 'events', limit: EffectivePosts.per_page)
|
87
|
+
@upcoming_events ||= {}
|
88
|
+
@upcoming_events[category] ||= Effective::Post.posts(user: user, category: category).limit(limit)
|
89
|
+
.reorder(:start_at).where('start_at > ?', Time.zone.now)
|
90
|
+
end
|
91
|
+
|
92
|
+
def render_upcoming_events(user: current_user, category: 'events', limit: EffectivePosts.per_page)
|
93
|
+
posts = upcoming_events(user: user, category: category, limit: limit)
|
94
|
+
render partial: '/effective/posts/upcoming_events', locals: { posts: posts }
|
95
|
+
end
|
96
|
+
|
84
97
|
### Submitting a Post
|
85
98
|
def link_to_submit_post(label = 'Submit a post', options = {})
|
86
99
|
link_to(label, effective_posts.new_post_path, options)
|
@@ -1,26 +1,36 @@
|
|
1
1
|
module Effective
|
2
2
|
class Post < ActiveRecord::Base
|
3
3
|
acts_as_role_restricted if defined?(EffectiveRoles)
|
4
|
+
acts_as_asset_box :image if defined?(EffectiveAssets)
|
4
5
|
acts_as_regionable
|
5
6
|
|
6
7
|
self.table_name = EffectivePosts.posts_table_name.to_s
|
7
8
|
|
8
9
|
belongs_to :user
|
9
10
|
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
|
18
|
-
#
|
11
|
+
# Attributes
|
12
|
+
# title :string
|
13
|
+
# category :string
|
14
|
+
# draft :boolean
|
15
|
+
# published_at :datetime
|
16
|
+
# tags :text
|
17
|
+
# roles_mask :integer
|
18
|
+
|
19
|
+
# Event Fields
|
20
|
+
# start_at :datetime
|
21
|
+
# end_at :datetime
|
22
|
+
# location :string
|
23
|
+
# website_name :website_name
|
24
|
+
# website_href :website_href
|
25
|
+
|
26
|
+
# timestamps
|
19
27
|
|
20
28
|
validates :title, presence: true, length: { maximum: 255 }
|
21
29
|
validates :category, presence: true
|
22
30
|
validates :published_at, presence: true
|
23
31
|
|
32
|
+
validates :start_at, presence: true, if: -> { category == 'events'}
|
33
|
+
|
24
34
|
scope :drafts, -> { where(draft: true) }
|
25
35
|
scope :published, -> { where(draft: false).where("#{EffectivePosts.posts_table_name}.published_at < ?", Time.zone.now) }
|
26
36
|
scope :with_category, -> (category) { where(category: category.to_s.downcase) }
|
@@ -29,6 +39,10 @@ module Effective
|
|
29
39
|
scope = (Rails::VERSION::MAJOR > 3 ? all : scoped)
|
30
40
|
scope = scope.includes(:regions).order(published_at: :desc)
|
31
41
|
|
42
|
+
if defined?(EffectiveAssets)
|
43
|
+
scope = scope.includes(attachments: :asset)
|
44
|
+
end
|
45
|
+
|
32
46
|
if user.present? && user.respond_to?(:roles) && defined?(EffectiveRoles)
|
33
47
|
scope = scope.for_role(user.roles)
|
34
48
|
end
|
@@ -52,6 +66,10 @@ module Effective
|
|
52
66
|
draft == false
|
53
67
|
end
|
54
68
|
|
69
|
+
def event?
|
70
|
+
category == 'events'
|
71
|
+
end
|
72
|
+
|
55
73
|
def body
|
56
74
|
region(:body).content
|
57
75
|
end
|
@@ -3,13 +3,10 @@
|
|
3
3
|
- @posts.find_each do |post|
|
4
4
|
.row
|
5
5
|
.col-sm-12
|
6
|
-
%h2.post-title
|
7
|
-
%a{:href => effective_post_path(post)}
|
8
|
-
= simple_effective_region post, :title do
|
9
|
-
= post.title
|
6
|
+
%h2.post-title= link_to post, effective_post_path(post)
|
10
7
|
.row
|
11
8
|
.col-sm-6
|
12
|
-
%pre= effective_region(post, :body, :
|
9
|
+
%pre= effective_region(post, :body, editable: false)
|
13
10
|
|
14
11
|
.col-sm-6
|
15
12
|
%pre= post_excerpt(post)
|
@@ -1,2 +1,19 @@
|
|
1
|
-
-#
|
2
|
-
|
1
|
+
-# Adding additional .effective-posts-category-#{category} will correctly show/hide on Posts#new forms
|
2
|
+
|
3
|
+
- # Event specific fields
|
4
|
+
.effective-post-category-events.well{style: ('display: none' unless f.object.category == 'events')}
|
5
|
+
%h4 Event Information
|
6
|
+
= form.input :start_at, as: (:effective_date_time_picker if defined?(EffectiveFormInputs)),
|
7
|
+
required: true,
|
8
|
+
hint: 'Display a start time for this event.'
|
9
|
+
|
10
|
+
= form.input :end_at, as: (:effective_date_time_picker if defined?(EffectiveFormInputs)),
|
11
|
+
hint: 'Display an end time of this event.'
|
12
|
+
|
13
|
+
= form.input :location, hint: 'Display a location where this event is taking place.'
|
14
|
+
|
15
|
+
= form.input :website_name, label: 'External website',
|
16
|
+
placeholder: 'Buy Tickets', hint: 'The label of an external website.'
|
17
|
+
|
18
|
+
= form.input :website_href, label: 'External website address',
|
19
|
+
placeholder: 'http://', hint: 'The address of an external website (start with http:// or https://).'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
= simple_form_for(post, (EffectivePosts.simple_form_options || {}).merge(:
|
1
|
+
= simple_form_for(post, (EffectivePosts.simple_form_options || {}).merge(url: (post.persisted? ? effective_posts.post_path(post.id) : effective_posts.posts_path))) do |f|
|
2
2
|
= f.input :title, hint: 'The title of your post.'
|
3
3
|
|
4
4
|
- if Array(EffectivePosts.categories).length > 0
|
@@ -14,11 +14,11 @@
|
|
14
14
|
= f.input :published_at,
|
15
15
|
as: (defined?(EffectiveFormInputs) ? :effective_date_time_picker : :datetime),
|
16
16
|
label: 'Publish date',
|
17
|
-
hint: 'When
|
17
|
+
hint: 'When should this be displayed on the website.'
|
18
18
|
|
19
19
|
= f.input :body,
|
20
20
|
as: (defined?(EffectiveFormInputs) ? :effective_ckeditor_text_area : :text),
|
21
|
-
hint: 'The body of your post.',
|
21
|
+
hint: 'The body of your post. You can add content here, or with the full screen editor on the next page.',
|
22
22
|
toolbar: 'simple',
|
23
23
|
required: true
|
24
24
|
|
@@ -1,9 +1,29 @@
|
|
1
1
|
.effective-post
|
2
|
-
%h2.post-title
|
3
|
-
%a{:href => effective_post_path(post)}
|
4
|
-
= simple_effective_region post, :title do
|
5
|
-
= post.title
|
2
|
+
%h2.post-title= link_to post, effective_post_path(post)
|
6
3
|
|
7
4
|
%p.post-meta= post_meta(post)
|
8
5
|
|
6
|
+
- if post.category == 'events'
|
7
|
+
%table.table.post-events
|
8
|
+
%tbody
|
9
|
+
- if post.start_at.present?
|
10
|
+
%tr
|
11
|
+
%th Starts
|
12
|
+
%td= post.start_at
|
13
|
+
|
14
|
+
- if post.end_at.present?
|
15
|
+
%tr
|
16
|
+
%th Ends
|
17
|
+
%td= post.start_at
|
18
|
+
|
19
|
+
- if post.location.present?
|
20
|
+
%tr
|
21
|
+
%th Location
|
22
|
+
%td= post.location
|
23
|
+
|
24
|
+
- if post.website_href.present? && post.website_name.present?
|
25
|
+
%tr
|
26
|
+
%th Website
|
27
|
+
%td= link_to post.website_name, post.website_href
|
28
|
+
|
9
29
|
.post-content.post-excerpt= post_excerpt(post)
|
@@ -1,11 +1,31 @@
|
|
1
1
|
.effective-post
|
2
|
-
%h2.post-title
|
3
|
-
%a{href: effective_post_path(@post)}
|
4
|
-
= simple_effective_region @post, :title do
|
5
|
-
= @post.title
|
2
|
+
%h2.post-title= link_to @post, effective_post_path(@post)
|
6
3
|
|
7
4
|
%p.post-meta= post_meta(@post)
|
8
5
|
|
6
|
+
- if post.category == 'events'
|
7
|
+
%table.table.post-events
|
8
|
+
%tbody
|
9
|
+
- if post.start_at.present?
|
10
|
+
%tr
|
11
|
+
%th Starts
|
12
|
+
%td= post.start_at
|
13
|
+
|
14
|
+
- if post.end_at.present?
|
15
|
+
%tr
|
16
|
+
%th Ends
|
17
|
+
%td= post.start_at
|
18
|
+
|
19
|
+
- if post.location.present?
|
20
|
+
%tr
|
21
|
+
%th Location
|
22
|
+
%td= post.location
|
23
|
+
|
24
|
+
- if post.website_href.present? && post.website_name.present?
|
25
|
+
%tr
|
26
|
+
%th Website
|
27
|
+
%td= link_to post.website_name, post.website_href
|
28
|
+
|
9
29
|
.post-body.post-content
|
10
30
|
= effective_region @post, :body do
|
11
31
|
%p Default content
|
data/config/effective_posts.rb
CHANGED
@@ -3,15 +3,15 @@ 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 = [:
|
6
|
+
config.categories = [:news, :events]
|
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
|
10
10
|
# For example:
|
11
|
-
# Visiting /
|
12
|
-
# Visiting /
|
11
|
+
# Visiting /news will display all posts created with the 'news' category
|
12
|
+
# Visiting /events will display all posts created with the 'events' category
|
13
13
|
#
|
14
|
-
# Regardless of this setting, posts will always be available via /posts?category=
|
14
|
+
# Regardless of this setting, posts will always be available via /posts?category=events
|
15
15
|
config.use_category_routes = true
|
16
16
|
|
17
17
|
# Number of posts displayed per page (Kaminari)
|
@@ -48,9 +48,12 @@ EffectivePosts.setup do |config|
|
|
48
48
|
# Configure the Layout per controller, or all at once
|
49
49
|
config.layout = {
|
50
50
|
posts: 'application',
|
51
|
-
admin: '
|
51
|
+
admin: 'admin'
|
52
52
|
}
|
53
53
|
|
54
|
+
# Add additional permitted params
|
55
|
+
# config.permitted_params += [:additional_field]
|
56
|
+
|
54
57
|
# SimpleForm Options
|
55
58
|
# This Hash of options will be passed into any client facing simple_form_for() calls
|
56
59
|
config.simple_form_options = {}
|
@@ -80,7 +83,7 @@ EffectivePosts.setup do |config|
|
|
80
83
|
config.submissions_require_approval = true
|
81
84
|
|
82
85
|
# The Thank you message when they submit a post
|
83
|
-
config.submissions_note = "News & Event submitted! A confirmation email has been sent to the
|
86
|
+
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."
|
84
87
|
|
85
88
|
# Mailer Settings
|
86
89
|
# effective_posts will send the admin an email when a post is submitted
|
@@ -7,12 +7,20 @@ class CreateEffectivePosts < ActiveRecord::Migration
|
|
7
7
|
t.string :category
|
8
8
|
|
9
9
|
t.boolean :draft, :default => false
|
10
|
+
t.datetime :published_at
|
10
11
|
|
11
12
|
t.text :tags
|
12
13
|
|
13
14
|
t.integer :roles_mask, :default => 0
|
14
15
|
|
15
|
-
|
16
|
+
# Events fields
|
17
|
+
t.datetime :start_at
|
18
|
+
t.datetime :end_at
|
19
|
+
t.string :location
|
20
|
+
t.string :website_name
|
21
|
+
t.string :website_href
|
22
|
+
|
23
|
+
t.text :extra
|
16
24
|
|
17
25
|
t.datetime :updated_at
|
18
26
|
t.datetime :created_at
|
data/lib/effective_posts.rb
CHANGED
@@ -44,7 +44,11 @@ module EffectivePosts
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def self.permitted_params
|
47
|
-
@@permitted_params ||= [
|
47
|
+
@@permitted_params ||= [
|
48
|
+
:title, :draft, :category, :published_at, :body, :tags, :extra,
|
49
|
+
:start_at, :end_at, :location, :website_name, :website_href,
|
50
|
+
(EffectiveAssets.permitted_params if defined?(EffectiveAssets)), roles: []
|
51
|
+
].compact
|
48
52
|
end
|
49
53
|
|
50
54
|
end
|
@@ -15,7 +15,7 @@ class EffectivePostsMailerPreview < ActionMailer::Preview
|
|
15
15
|
category: EffectivePosts.categories.first.presence || 'posts',
|
16
16
|
published_at: Time.zone.now,
|
17
17
|
draft: true,
|
18
|
-
|
18
|
+
body: 'This is a new post that has been submitted by a public user.'
|
19
19
|
)
|
20
20
|
end
|
21
21
|
|
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: 0.5.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2017-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- README.md
|
149
149
|
- Rakefile
|
150
150
|
- app/assets/javascripts/effective/snippets/read_more_divider.js.coffee
|
151
|
+
- app/assets/javascripts/effective_pages/additional_fields.js.coffee
|
151
152
|
- app/assets/javascripts/effective_posts.js
|
152
153
|
- app/assets/stylesheets/effective_posts.scss
|
153
154
|
- app/controllers/admin/posts_controller.rb
|
@@ -172,6 +173,7 @@ files:
|
|
172
173
|
- app/views/effective/posts/_post.html.haml
|
173
174
|
- app/views/effective/posts/_recent_posts.html.haml
|
174
175
|
- app/views/effective/posts/_spacer.html.haml
|
176
|
+
- app/views/effective/posts/_upcoming_events.html.haml
|
175
177
|
- app/views/effective/posts/edit.html.haml
|
176
178
|
- app/views/effective/posts/index.html.haml
|
177
179
|
- app/views/effective/posts/new.html.haml
|