effective_posts 1.0.1 → 1.0.2

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: e7e2b60e89549a66946feb9f84f811a90fa6ae02
4
- data.tar.gz: d7340cf007baa0db85a8d0b5073a9e202edf9e6a
3
+ metadata.gz: a73d09c2c4fda7417d196c7ce701792f4972a269
4
+ data.tar.gz: 40bd397f0941f6403819db29b6e5c5a6a0b505c2
5
5
  SHA512:
6
- metadata.gz: d8c233609e2ab6151f8ccc911855b60b0175eaec11289031853fbc567d04f1e1a2731b97e6a66a56e1b70007c56240a697f33ac863d88c1d76114b78ee730eba
7
- data.tar.gz: 49570f10e2e4e43d528ea96329946cf73cbc9cde86315b32d78f75b784db6ad2c1096df0108a1c2b5211e3665c146f21de9e914e90383e01a51ca416e9839496
6
+ metadata.gz: 93f00476ee697241229faf88324137ecb167e3677e9f9fe9fcfb0b5f7752204426e4c95caa7d748fb0b745aa1a348edfcc21fa9618ad10cab777e8de5778a4e5
7
+ data.tar.gz: 1e295bc8f6ba1a1a1059a03d041e3b7b3f913803b5aba5b2f99422d6703c77a9bf34bd8af9092a09bd0a0ad6adabe20f21d09082d195b62c61699fd0604f95cd
data/README.md CHANGED
@@ -49,6 +49,13 @@ Then migrate the database:
49
49
  rake db:migrate
50
50
  ```
51
51
 
52
+
53
+ Add the following helper to your application layout in the `<head>..</head>` section. This works alongside effective_pages to include some publisher meta tags.
54
+
55
+ ```ruby
56
+ = effective_posts_header_tags
57
+ ```
58
+
52
59
  There are no required javascript or stylesheet includes.
53
60
 
54
61
 
@@ -60,8 +67,6 @@ If you've defined more than one category in the `/app/config/initializers/effect
60
67
 
61
68
  You can schedule a post to appear at a later date by setting the published_at value to a future date.
62
69
 
63
- If you're using the [effective_form_inputs](https://github.com/code-and-effect/effective_form_inputs) gem, the published_at input will be displayed with a nice bootstrap3 datetimepicker, otherwise it will use the default simple_form datetime input (which is pretty bad).
64
-
65
70
  As well, if you're using the [effective_roles](https://github.com/code-and-effect/effective_roles) gem, you will be able to configure permissions so that only permitted users may view this post.
66
71
 
67
72
  Once you click `Save and Edit Content` you will be brought into the effective_regions editor where you may enter the content for your post. Click `Insert Snippet` -> `Read more divider` from the toolbar to place a divider into your post. Only the content above the Read more divider, the excerpt content, will be displayed on any posts#index screens. The full content will be displayed on the posts#show screen.
@@ -32,6 +32,8 @@ module Admin
32
32
  elsif params[:commit] == 'Save and Add New'
33
33
  flash[:success] = 'Successfully created post'
34
34
  redirect_to effective_posts.new_admin_post_path
35
+ elsif params[:commit] == 'Save and View'
36
+ redirect_to effective_posts.post_path(@post)
35
37
  else
36
38
  flash[:success] = 'Successfully created post'
37
39
  redirect_to effective_posts.edit_admin_post_path(@post)
@@ -61,6 +63,8 @@ module Admin
61
63
  elsif params[:commit] == 'Save and Add New'
62
64
  flash[:success] = 'Successfully updated post'
63
65
  redirect_to effective_posts.new_admin_post_path
66
+ elsif params[:commit] == 'Save and View'
67
+ redirect_to effective_posts.post_path(@post)
64
68
  elsif params[:commit] == 'Save and Duplicate'
65
69
  begin
66
70
  post = @post.duplicate!
@@ -6,7 +6,12 @@ module Effective
6
6
  if: -> { EffectivePosts.submissions_require_current_user }
7
7
 
8
8
  def index
9
- @posts ||= Effective::Post.posts(user: current_user, category: params[:category])
9
+ @posts ||= Effective::Post.posts(
10
+ user: current_user,
11
+ category: params[:category],
12
+ unpublished: EffectivePosts.authorized?(self, :admin, :effective_posts)
13
+ )
14
+
10
15
  @posts = @posts.page(params[:page]).per(EffectivePosts.per_page)
11
16
 
12
17
  if params[:category] == 'events'
@@ -24,7 +29,7 @@ module Effective
24
29
  end
25
30
 
26
31
  def show
27
- @posts ||= Effective::Post.posts(user: current_user, category: params[:category], drafts: (params[:edit].to_s == 'true' || params[:preview].to_s == 'true'))
32
+ @posts ||= Effective::Post.posts(user: current_user, category: params[:category], unpublished: EffectivePosts.authorized?(self, :admin, :effective_posts))
28
33
  @post = @posts.find(params[:id])
29
34
 
30
35
  if @post.respond_to?(:roles_permit?)
@@ -33,7 +38,18 @@ module Effective
33
38
 
34
39
  EffectivePosts.authorize!(self, :show, @post)
35
40
 
41
+ if EffectivePosts.authorized?(self, :admin, :effective_posts)
42
+ flash.now[:warning] = [
43
+ 'Hi Admin!',
44
+ ('You are viewing a hidden post.' unless @post.published?),
45
+ 'Click here to',
46
+ ("<a href='#{effective_regions.edit_path(effective_posts.post_path(@post, exit: effective_posts.post_path(@post)))}' class='alert-link'>edit post content</a> or" unless admin_edit?),
47
+ ("<a href='#{effective_posts.edit_admin_post_path(@post)}' class='alert-link'>edit post settings</a>.")
48
+ ].compact.join(' ')
49
+ end
50
+
36
51
  @page_title = @post.title
52
+ @meta_description = @post.description
37
53
  end
38
54
 
39
55
  # Public user submit a post functionality
@@ -117,5 +133,9 @@ module Effective
117
133
  params.require(:effective_post).permit(EffectivePosts.permitted_params)
118
134
  end
119
135
 
136
+ def admin_edit?
137
+ EffectivePosts.authorized?(self, :admin, :effective_posts) && (params[:edit].to_s == 'true')
138
+ end
139
+
120
140
  end
121
141
  end
@@ -1,6 +1,20 @@
1
1
  require 'cgi'
2
2
 
3
3
  module EffectivePostsHelper
4
+
5
+ def effective_posts_header_tags
6
+ return unless @post.present? && @post.kind_of?(Effective::Post)
7
+
8
+ @effective_pages_og_type = 'article'
9
+
10
+ tags = [
11
+ tag(:meta, itemprop: 'author', content: @post.user.to_s),
12
+ tag(:meta, itemprop: 'publisher', content: @post.user.to_s),
13
+ tag(:meta, itemprop: 'datePublised', content: @post.published_at.strftime('%FT%T%:z')),
14
+ tag(:meta, itemprop: 'headline', content: @post.title)
15
+ ].join("\n").html_safe
16
+ end
17
+
4
18
  def effective_post_path(post, opts = nil)
5
19
  category = post.category.to_s.downcase
6
20
  opts ||= {}
@@ -39,13 +53,24 @@ module EffectivePostsHelper
39
53
  ].compact.join(' ').html_safe
40
54
  end
41
55
 
56
+ def admin_post_status_badge(post)
57
+ return nil unless EffectivePosts.authorized?(self, :admin, :effective_posts)
58
+
59
+ if post.draft?
60
+ content_tag(:span, 'DRAFT', class: 'badge badge-info')
61
+ elsif post.published? == false
62
+ content_tag(:span, "TO BE PUBLISHED AT #{post.published_at.strftime('%F %H:%M')}", class: 'badge badge-info')
63
+ end
64
+ end
65
+
42
66
  # Only supported options are:
43
67
  # :label => 'Read more' to set the label of the 'Read More' link
44
68
  # :omission => '...' passed to the final text node's truncate
45
69
  # :length => 200 to set the max inner_text length of the content
46
70
  # All other options are passed to the link_to 'Read more'
47
- def post_excerpt(post, read_more_link: true, label: 'Read more', omission: '...', length: 200)
71
+ def post_excerpt(post, read_more_link: true, label: 'Continue reading', omission: '...', length: 200)
48
72
  content = effective_region(post, :body, :editable => false) { '<p>Default content</p>'.html_safe }
73
+ description = content_tag(:p, post.description)
49
74
 
50
75
  divider = content.index(Effective::Snippets::ReadMoreDivider::TOKEN)
51
76
  read_more = (read_more_link && label.present?) ? readmore_link(post, label: label) : ''
@@ -53,15 +78,15 @@ module EffectivePostsHelper
53
78
  CGI.unescapeHTML(if divider.present?
54
79
  truncate_html(content, Effective::Snippets::ReadMoreDivider::TOKEN, '') + read_more
55
80
  elsif length.present?
56
- truncate_html(content, length, omission) + read_more
81
+ truncate_html(description, length, omission) + read_more
57
82
  else
58
- content
83
+ description
59
84
  end).html_safe
60
85
  end
61
86
 
62
- def read_more_link(post, options)
87
+ def read_more_link(post, options = {})
63
88
  content_tag(:p, class: 'post-read-more') do
64
- link_to((options.delete(:label) || 'Read more'), effective_post_path(post), (options.delete(:class) || {class: 'btn btn-primary'}).reverse_merge(options))
89
+ link_to((options.delete(:label) || 'Continue reading'), effective_post_path(post), (options.delete(:class) || {class: ''}).reverse_merge(options))
65
90
  end
66
91
  end
67
92
  alias_method :readmore_link, :read_more_link
@@ -9,10 +9,14 @@ module Effective
9
9
 
10
10
  # Attributes
11
11
  # title :string
12
+ # description :string
13
+
12
14
  # category :string
15
+
13
16
  # draft :boolean
14
17
  # published_at :datetime
15
18
  # tags :text
19
+
16
20
  # roles_mask :integer
17
21
 
18
22
  # Event Fields
@@ -25,6 +29,7 @@ module Effective
25
29
  # timestamps
26
30
 
27
31
  validates :title, presence: true, length: { maximum: 255 }
32
+ validates :description, presence: true, length: { maximum: 150 }
28
33
  validates :category, presence: true
29
34
  validates :published_at, presence: true
30
35
 
@@ -32,9 +37,10 @@ module Effective
32
37
 
33
38
  scope :drafts, -> { where(draft: true) }
34
39
  scope :published, -> { where(draft: false).where("#{EffectivePosts.posts_table_name}.published_at < ?", Time.zone.now) }
40
+ scope :unpublished, -> { where(draft: true).or(where("#{EffectivePosts.posts_table_name}.published_at > ?", Time.zone.now)) }
35
41
  scope :with_category, -> (category) { where(category: category.to_s.downcase) }
36
42
 
37
- scope :posts, -> (user: nil, category: nil, drafts: false) {
43
+ scope :posts, -> (user: nil, category: nil, unpublished: false) {
38
44
  scope = all.includes(:regions).order(published_at: :desc)
39
45
 
40
46
  if defined?(EffectiveRoles) && EffectivePosts.use_effective_roles
@@ -47,7 +53,7 @@ module Effective
47
53
  scope = scope.with_category(category)
48
54
  end
49
55
 
50
- if drafts.blank?
56
+ unless unpublished
51
57
  scope = scope.published
52
58
  end
53
59
 
@@ -58,6 +64,10 @@ module Effective
58
64
  title.presence || 'New Post'
59
65
  end
60
66
 
67
+ def published?
68
+ !draft? && published_at < Time.zone.now
69
+ end
70
+
61
71
  def approved?
62
72
  draft == false
63
73
  end
@@ -3,7 +3,9 @@ module Effective
3
3
  class ReadMoreDivider < Snippet
4
4
  TOKEN = "<div style='display: none;'>READ_MORE_DIVIDER</div>"
5
5
 
6
- attribute :throwaway, String
6
+ def snippet_attributes
7
+ super + [:throwaway]
8
+ end
7
9
  end
8
10
  end
9
11
  end
@@ -7,7 +7,7 @@
7
7
  - if EffectivePosts.use_fullscreen_editor
8
8
  = dropdown_link_to 'Edit Content', effective_post_path(post, edit: true), title: 'Edit Content', 'data-no-turbolink': true, target: '_blank'
9
9
 
10
- = dropdown_link_to 'View', effective_post_path(post, preview: true), target: '_blank'
10
+ = dropdown_link_to 'View', effective_post_path(post), target: '_blank'
11
11
 
12
12
  = dropdown_link_to "Delete", effective_posts.admin_post_path(post),
13
13
  data: { method: :delete, confirm: "Really delete #{post}?" }
@@ -1,5 +1,6 @@
1
1
  = effective_form_with(model: post, url: post.persisted? ? effective_posts.admin_post_path(post.id) : effective_posts.admin_posts_path) do |f|
2
2
  = f.text_field :title, hint: 'The title of your post.'
3
+ = f.text_field :description, hint: 'Will be used for the post excerpt and meta tags.', maxlength: 150
3
4
 
4
5
  - if Array(EffectivePosts.categories).length > 1
5
6
  = f.select :category, EffectivePosts.categories
@@ -12,7 +13,8 @@
12
13
 
13
14
  = f.check_box :draft, hint: 'Save this post as a draft. It will not be accessible on the website.'
14
15
 
15
- = f.editor :body, delta: false
16
+ - unless EffectivePosts.use_fullscreen_editor
17
+ = f.ck_editor :body
16
18
 
17
19
  - if defined?(EffectiveRoles) and f.object.respond_to?(:roles) && EffectivePosts.use_effective_roles
18
20
  = f.checks :roles, EffectiveRoles.roles_collection(f.object), hint: '* leave blank for a regular public post that anyone can view'
@@ -21,5 +23,5 @@
21
23
  = f.save 'Save'
22
24
  - if EffectivePosts.use_fullscreen_editor
23
25
  = f.save 'Save and Edit Content'
24
- = f.save 'Save and Add New'
26
+ = f.save 'Save and View'
25
27
  = f.save 'Save and Duplicate'
@@ -0,0 +1,22 @@
1
+ - if post.category == 'events'
2
+ %table.table.post-events
3
+ %tbody
4
+ - if post.start_at.present?
5
+ %tr
6
+ %th Starts
7
+ %td= post.start_at
8
+
9
+ - if post.end_at.present?
10
+ %tr
11
+ %th Ends
12
+ %td= post.end_at
13
+
14
+ - if post.location.present?
15
+ %tr
16
+ %th Location
17
+ %td= post.location
18
+
19
+ - if post.website_href.present? && post.website_name.present?
20
+ %tr
21
+ %th Website
22
+ %td= link_to post.website_name, post.website_href
@@ -10,12 +10,9 @@
10
10
 
11
11
  = f.datetime_field :published_at, label: 'Publish date', hint: 'When should this be displayed on the website.'
12
12
 
13
- = f.text_area :body
13
+ = f.check_box :draft, hint: 'Save this post as a draft. It will not be accessible on the website.'
14
14
 
15
- / = f.input :body,
16
- / as: (defined?(EffectiveFormInputs) ? :effective_ckeditor_text_area : :text),
17
- / hint: 'The body of your post. You can add content here, or with the full screen editor on the next page.',
18
- / toolbar: 'simple',
19
- / required: true
15
+ - unless EffectivePosts.use_fullscreen_editor
16
+ = f.ck_editor :body
20
17
 
21
18
  = f.submit 'Save'
@@ -0,0 +1,4 @@
1
+ %h2.post-title= link_to post, effective_post_path(post)
2
+ %p.post-meta.text-muted
3
+ = post_meta(post, author: false)
4
+ = admin_post_status_badge(post)
@@ -1,32 +1,6 @@
1
1
  .effective-post
2
- %h2.post-title= link_to post, effective_post_path(post)
2
+ = render 'effective/posts/header', post: post
3
+ = render 'effective/posts/event', post: post
3
4
 
4
- %p.post-meta= post_meta(post, author: false)
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.end_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
-
29
- - if block_given?
30
- = yield
31
- - else
32
- .post-content.post-excerpt= post_excerpt(post)
5
+ .post-content.post-excerpt
6
+ = post_excerpt(post)
@@ -1,28 +1,31 @@
1
1
  - posts = recent_posts(category: nil, limit: 5)
2
- %h4.sidebar-title Recent Posts
3
- %ul.nav.flex-column
4
- - posts.each do |post|
5
- = nav_link_to post, effective_post_path(post)
6
-
7
- - if posts.length == 0
8
- = nav_link_to 'None', effective_posts.posts_path, class: 'disabled'
2
+ %h4.dashboard-title About
3
+ %p.mb-5
4
+ Welcome to the Tadum blog, where you can learn how to build a culture of high-value meetings.
9
5
 
10
6
  - if EffectivePosts.categories.present?
11
7
  - categories = EffectivePosts.categories
12
- %h4.sidebar-title Categories
13
- %ul.nav.flex-column
14
- = nav_link_to 'All Posts', effective_posts.posts_path
8
+ %h4.dashboard-title Categories
9
+ %ul.list-unstyled
10
+ %li= link_to 'All Posts', effective_posts.posts_path
15
11
 
16
- - categories.each do |category|
17
- = nav_link_to category.to_s.titleize, effective_post_category_path(category)
12
+ - categories.sort.each do |category|
13
+ %li= link_to category.to_s.titleize, effective_post_category_path(category)
18
14
 
19
- - if params[:category]
20
- - category_posts = recent_posts(category: params[:category], limit: 5)
21
- %h4.sidebar-title Recent #{params[:category].titleize}
22
- %ul.nav.flex-column
23
- - category_posts.each do |post|
24
- = nav_link_to post, effective_post_path(post)
15
+ - posts = recent_posts(category: nil, limit: 5)
16
+ %h4.dashboard-title Recent Posts
17
+ %ul.list-unstyled
18
+ - posts.each do |post|
19
+ %li= link_to post, effective_post_path(post)
20
+
21
+ - if posts.length == 0
22
+ %li= link_to 'None', effective_posts.posts_path, class: 'disabled'
25
23
 
26
- - if category_posts.length == 0
27
- = nav_link_to 'None', effective_posts.posts_path, class: 'disabled'
24
+ - if EffectivePosts.authorized?(self, :admin, :effective_posts)
25
+ %h4.dashboard-title Admin
26
+ %ul.list-unstyled
27
+ %li= link_to 'All Posts', effective_posts.admin_posts_path
28
28
 
29
+ - if @post.present?
30
+ %li= link_to 'Edit Post Content', effective_regions.edit_path(effective_posts.post_path(@post, exit: effective_posts.post_path(@post)))
31
+ %li= link_to 'Edit Post Settings', effective_posts.edit_admin_post_path(@post)
@@ -1,8 +1,8 @@
1
1
  = render 'layout' do
2
- = render('effective/posts/post', post: @post) do
2
+ .effective-post
3
+ = render 'effective/posts/header', post: @post
4
+ = render 'effective/posts/event', post: @post
5
+
3
6
  .post-body.post-content
4
7
  = effective_region @post, :body do
5
8
  %p Default content
6
-
7
- .border-top.mb-3
8
- = link_to 'Continue', effective_posts.posts_path, class: 'btn btn-primary'
@@ -4,6 +4,8 @@ class CreateEffectivePosts < ActiveRecord::Migration[4.2]
4
4
  t.integer :user_id
5
5
 
6
6
  t.string :title
7
+ t.string :description
8
+
7
9
  t.string :category
8
10
 
9
11
  t.boolean :draft, :default => false
@@ -55,7 +55,7 @@ module EffectivePosts
55
55
 
56
56
  def self.permitted_params
57
57
  @@permitted_params ||= [
58
- :title, :draft, :category, :published_at, :body, :tags, :extra,
58
+ :title, :description, :draft, :category, :published_at, :body, :tags, :extra,
59
59
  :start_at, :end_at, :location, :website_name, :website_href, roles: []
60
60
  ].compact
61
61
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePosts
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.0.2'.freeze
3
3
  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: 1.0.1
4
+ version: 1.0.2
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: 2019-03-20 00:00:00.000000000 Z
11
+ date: 2019-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -154,7 +154,9 @@ files:
154
154
  - app/views/admin/posts/new.html.haml
155
155
  - app/views/effective/posts/_additional_fields.html.haml
156
156
  - app/views/effective/posts/_categories.html.haml
157
+ - app/views/effective/posts/_event.html.haml
157
158
  - app/views/effective/posts/_form.html.haml
159
+ - app/views/effective/posts/_header.html.haml
158
160
  - app/views/effective/posts/_layout.html.haml
159
161
  - app/views/effective/posts/_post.html.haml
160
162
  - app/views/effective/posts/_recent_posts.html.haml