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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cbae7b7138b3a8c12923d42784c42ba660abfb1
4
- data.tar.gz: d3235a3688cd1d3dc9f1d7af60fb142f00a58c78
3
+ metadata.gz: be81ac9b127e592c28c261f3853fa5eae6947c14
4
+ data.tar.gz: 3200a7c2d3b17e51a289a2880473d948a8315a35
5
5
  SHA512:
6
- metadata.gz: f63838c6ffa90c6eaa6efb925c8cbd39a9b2bc9155605bebd8be62c44e8d29a5f0439bc9e89c8d25142bb143ce3ee537c17246a0f711bd33b56cfe7d12d35e10
7
- data.tar.gz: aa39d8b2d97656f24e387abc3f7de7108a5607ea7378f5b1e61b7bb3f014cc70157c63a678b6b8e9a4a26074a1a906a94d467b114355377d39050b50660677d7
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
- "/#{category}" + effective_posts.post_path(post, opts)
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, '') + readmore
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'), effective_posts.post_path(post), options)
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: nil, limit: EffectivePosts.per_page)
75
- @recent_posts ||= Effective::Post.posts(user: user, category: category).limit(limit)
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: nil, limit: EffectivePosts.per_page)
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
- # structure do
11
- # title :string, :validates => [:presence, :length => {:maximum => 255}]
12
- # category :string, :validates => [:presence]
13
- # published_at :datetime, :validates => [:presence]
14
- # draft :boolean, :default => false
15
- # tags :text
16
- # roles_mask :integer, :default => 0
17
- # timestamps
18
- # end
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, :editable => false)
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
- -# intentionally left blank
2
- -# = form.input :start_at
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
1
  .effective-posts-categories
2
2
  - categories.each do |category|
3
3
  .effective-post-category
4
- = link_to_post_category(category)
4
+ %p= link_to_post_category(category)
@@ -1,4 +1,4 @@
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|
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 your post will be displayed on the website.'
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)
@@ -0,0 +1,5 @@
1
+ .effective-posts-upcoming-events
2
+ - posts.each do |post|
3
+ .effective-post
4
+ %p= link_to post, effective_post_path(post)
5
+
@@ -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
@@ -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 = [:blog, :news]
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 /blog will display all posts created with the :blog category
12
- # Visiting /news will display all posts created with the :news category
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=blog
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: 'application'
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 AALA office. When approved, your submission will appear on the website."
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
- t.datetime :published_at
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
@@ -44,7 +44,11 @@ module EffectivePosts
44
44
  end
45
45
 
46
46
  def self.permitted_params
47
- @@permitted_params ||= [:title, :draft, :category, :published_at, :body, roles: []]
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
@@ -1,3 +1,3 @@
1
1
  module EffectivePosts
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.5.1'.freeze
3
3
  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
- content: 'This is a new post that has been submitted by a public user.'
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.0
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: 2016-12-07 00:00:00.000000000 Z
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