proclaim 0.6.0 → 0.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: 8ed66630af32fc0c1e8ef5217eb3cb511b60cfd34e9198fb1b8f1f12ae8054ff
4
- data.tar.gz: a69c720636b0d4d86ea43bbd60294af073ad86561a165094cff5bad6a9c69960
3
+ metadata.gz: 26d5c8a84089609896acf5ec9d4217133f38e7610d5928bb787344ca708f034f
4
+ data.tar.gz: d2a9d27c63d5594e85db0d0f77a5540305d9590c92094e9026a10328e824ee2d
5
5
  SHA512:
6
- metadata.gz: 89c16c4398abd72ff076c6abcb6cc8389477a8f0c623e979d4bef670cc69f668c3393e5caccd5a4c401240d2534748bea2eae88ddab01e939317a6659bc592ff
7
- data.tar.gz: fe9c5f4aa15fd2aafa5a3b01869986b452b16bccace9676459876bb493990d494fb642bd8926ee5e538a8855aeb8b5dffba8bdd2d7e0a97f99fa3fac1d7397e6
6
+ metadata.gz: 9e03292d0337594913998faa19610a6c386a01647ed36ae1848241d73670eb8e2f94ac1795290f3aa33ca14b1b10f10c75114be6e1e46fc75700c3407794d3f2
7
+ data.tar.gz: bdd25c22095e91b41e494c9113735e859f992b6c7ba0e1e6767e100f7cb7fcd4f9fec926f6947b7c11d43424e745e71a7b15eef5ba0724561cd30e877cb77c9e
@@ -1,9 +1,11 @@
1
1
  class Editor
2
2
  constructor: (@form, @titleFormField, @titleEditableItem, @titleContents,
3
+ @subtitleFormField, @subtitleEditableItem, @subtitleContents,
3
4
  @bodyFormField, @quillBodyFormField, @bodyEditableItem,
4
5
  @bodyScrollingContainer, @bodyContents, @toolbar, @formats) ->
5
6
  if (@form.length == 1) and (@titleFormField.length == 1) and
6
- (@titleEditableItem.length == 1) and (@bodyFormField.length == 1) and
7
+ (@titleEditableItem.length == 1) and (@subtitleFormField.length == 1) and
8
+ (@subtitleEditableItem.length == 1)and (@bodyFormField.length == 1) and
7
9
  (@bodyEditableItem.length == 1) and (@bodyScrollingContainer.length == 1)
8
10
  @bodyEditor = new Quill(@bodyEditableItem.get(0), {
9
11
  placeholder: @bodyEditableItem.data("placeholder"),
@@ -25,14 +27,19 @@ class Editor
25
27
  @form.on "submit", @updateFormFields
26
28
  @titleEditableItem.on "paste", @stripFormatting
27
29
  @titleEditableItem.on "keypress", @disallowNewlines
30
+ @subtitleEditableItem.on "paste", @stripFormatting
31
+ @subtitleEditableItem.on "keypress", @disallowNewlines
28
32
 
29
33
  cleanBindings: ->
30
34
  @form.off "submit"
31
35
  @titleEditableItem.off "paste"
32
36
  @titleEditableItem.off "keypress"
37
+ @subtitleEditableItem.off "paste"
38
+ @subtitleEditableItem.off "keypress"
33
39
 
34
40
  updateFormFields: (event) =>
35
41
  @titleFormField.val(@titleEditableItem.text())
42
+ @subtitleFormField.val(@subtitleEditableItem.text())
36
43
  @quillBodyFormField.val(JSON.stringify(@bodyEditor.getContents()))
37
44
  @bodyFormField.val(@bodyEditableItem.children('div.ql-editor').html())
38
45
 
@@ -3,12 +3,15 @@
3
3
  They will automatically be included in application.css.
4
4
  */
5
5
 
6
+ div.post_title
7
+ {
8
+ border-bottom: solid 1px #ddd;
9
+ }
10
+
6
11
  h1.post_title
7
12
  {
8
13
  text-align: center;
9
- padding-bottom: 10px;
10
14
  font-weight: bold;
11
- border-bottom: solid 1px #ddd;
12
15
 
13
16
  &:empty:before
14
17
  {
@@ -19,6 +22,39 @@ h1.post_title
19
22
  }
20
23
  }
21
24
 
25
+ h1.post_title.editable
26
+ {
27
+ margin-bottom: 20px;
28
+ &:after
29
+ {
30
+ position: relative;
31
+ text-align: center;
32
+ }
33
+ }
34
+
35
+ h2.post_subtitle
36
+ {
37
+ text-align: center;
38
+
39
+ &:empty:before
40
+ {
41
+ content: attr(placeholder);
42
+ display: block; /* For Firefox */
43
+ font-style: italic;
44
+ color: rgba(0,0,0,0.6);
45
+ }
46
+ }
47
+
48
+ h2.post_subtitle.editable
49
+ {
50
+ margin-bottom: 20px;
51
+ &:after
52
+ {
53
+ position: relative;
54
+ text-align: center;
55
+ }
56
+ }
57
+
22
58
  div.post_information
23
59
  {
24
60
  border-top: solid 1px #ddd;
@@ -88,16 +124,6 @@ div.post_body.editable:after
88
124
  top: 0;
89
125
  }
90
126
 
91
- h1.post_title.editable
92
- {
93
- margin-bottom: 20px;
94
- &:after
95
- {
96
- position: relative;
97
- text-align: center;
98
- }
99
- }
100
-
101
127
  /* Specify our own scrolling container */
102
128
  div.scrolling-container {
103
129
  height: 100%;
@@ -17,6 +17,11 @@ module Proclaim
17
17
  def show
18
18
  authorize @post
19
19
 
20
+ # Don't track traffic if it's a logged-in user
21
+ unless current_author
22
+ @post.punch(request)
23
+ end
24
+
20
25
  # If an old id or a numeric id was used to find the record, then
21
26
  # the request path will not match the post_path, and we should do
22
27
  # a 301 redirect that uses the current friendly id.
@@ -99,12 +104,16 @@ module Proclaim
99
104
 
100
105
  # Only allow a trusted parameter "white list" through.
101
106
  def post_params
102
- # Ensure post title is sanitized of all HTML
107
+ # Ensure post title and subtitle are sanitized of all HTML
103
108
  if params[:post].include? :title
104
109
  params[:post][:title] = HTMLEntities.new.decode(Rails::Html::FullSanitizer.new.sanitize(params[:post][:title]))
105
110
  end
106
111
 
107
- params.require(:post).permit(:title, :body, :quill_body)
112
+ if params[:post].include? :subtitle
113
+ params[:post][:subtitle] = HTMLEntities.new.decode(Rails::Html::FullSanitizer.new.sanitize(params[:post][:subtitle]))
114
+ end
115
+
116
+ params.require(:post).permit(:title, :subtitle, :body, :quill_body)
108
117
  end
109
118
  end
110
119
  end
@@ -40,7 +40,7 @@ module Proclaim
40
40
  validates_presence_of :published_at, if: :published?
41
41
  validates :published_at, absence: true, unless: :published?
42
42
 
43
- validates_presence_of :title, :body, :quill_body, :author
43
+ validates_presence_of :title, :subtitle, :body, :quill_body, :author
44
44
  validate :verifyBodyHtml
45
45
 
46
46
  after_validation :move_friendly_id_error_to_title
@@ -48,25 +48,14 @@ module Proclaim
48
48
  # Using after_commit since we use deliver_later and re-load them from the database
49
49
  after_commit :notifyBlogSubscribersIfPublished, on: [:create, :update]
50
50
 
51
- # Only save the slug history if the post is published
52
- def create_slug
53
- # No real reason to keep a slug history unless it's been published
54
- unless published?
55
- slugs.destroy_all
56
- end
57
-
58
- super
59
- end
51
+ # Track views
52
+ acts_as_punchable
60
53
 
61
54
  attr_writer :excerpt_length
62
55
  def excerpt_length
63
56
  @excerpt_length ||= Proclaim.excerpt_length
64
57
  end
65
58
 
66
- def body_plaintext
67
- HTMLEntities.new.decode(Rails::Html::FullSanitizer.new.sanitize(body.gsub(/\r\n?/, ' ')))
68
- end
69
-
70
59
  def excerpt
71
60
  document = Nokogiri::HTML.fragment(body)
72
61
 
@@ -86,8 +75,32 @@ module Proclaim
86
75
  end
87
76
  end
88
77
 
78
+ def feature_image
79
+ document = Nokogiri::HTML.fragment(body)
80
+ return nil if document.children.empty?
81
+
82
+ first_element_images = document.children.first.css("img")
83
+ return nil if first_element_images.empty?
84
+
85
+ return first_element_images.first.attr "src"
86
+ end
87
+
89
88
  private
90
89
 
90
+ # Only save the slug history if the post is published
91
+ def create_slug
92
+ # No real reason to keep a slug history unless it's been published
93
+ unless published?
94
+ slugs.destroy_all
95
+ end
96
+
97
+ super
98
+ end
99
+
100
+ def body_plaintext
101
+ HTMLEntities.new.decode(Rails::Html::FullSanitizer.new.sanitize(body.gsub(/\r\n?/, ' ')))
102
+ end
103
+
91
104
  def should_generate_new_friendly_id?
92
105
  title_changed? || super
93
106
  end
@@ -10,8 +10,11 @@
10
10
  <% if @post.new_record? %>
11
11
  new Editor($(document).find("form.new_post"),
12
12
  $(document).find("input#post_title"),
13
- $(document).find("form.new_post h1.editable"),
13
+ $(document).find("form.new_post h1.post_title.editable"),
14
14
  '<%= @post.title.html_safe.strip %>',
15
+ $(document).find("input#post_subtitle"),
16
+ $(document).find("form.new_post h2.post_subtitle.editable"),
17
+ '<%= @post.subtitle.html_safe.strip %>',
15
18
  $(document).find("input#post_body"),
16
19
  $(document).find("input#post_quill_body"),
17
20
  $(document).find("form.new_post div.editable"),
@@ -22,8 +25,11 @@
22
25
  <% else %>
23
26
  new Editor($(document).find("form.edit_post"),
24
27
  $(document).find("input#post_title"),
25
- $(document).find("form.edit_post h1.editable"),
28
+ $(document).find("form.edit_post h1.post_title.editable"),
26
29
  '<%= @post.title.html_safe.strip %>',
30
+ $(document).find("input#post_subtitle"),
31
+ $(document).find("form.edit_post h2.post_subtitle.editable"),
32
+ '<%= @post.subtitle.html_safe.strip %>',
27
33
  $(document).find("input#post_body"),
28
34
  $(document).find("input#post_quill_body"),
29
35
  $(document).find("form.edit_post div.editable"),
@@ -49,12 +55,21 @@
49
55
  <% end %>
50
56
 
51
57
  <div class = "post">
52
- <%=
53
- fake_form_field @post, :title do
54
- content_tag :h1, @post.title, class: "post_title editable",
55
- contenteditable: true, placeholder: "Post Title"
56
- end
57
- %>
58
+ <div class = "post_title">
59
+ <%=
60
+ fake_form_field @post, :title do
61
+ content_tag :h1, @post.title, class: "post_title editable",
62
+ contenteditable: true, placeholder: "Post Title"
63
+ end
64
+ %>
65
+
66
+ <%=
67
+ fake_form_field @post, :subtitle do
68
+ content_tag :h2, @post.subtitle, class: "post_subtitle editable",
69
+ contenteditable: true, placeholder: "Post Subtitle"
70
+ end
71
+ %>
72
+ </div>
58
73
 
59
74
  <div id="scrolling-container">
60
75
  <%=
@@ -79,6 +94,7 @@
79
94
  </div>
80
95
 
81
96
  <%= f.hidden_field :title %>
97
+ <%= f.hidden_field :subtitle %>
82
98
  <%= f.hidden_field :body %>
83
99
  <%= f.hidden_field :quill_body %>
84
100
 
@@ -42,7 +42,10 @@
42
42
  </div>
43
43
 
44
44
  <div class = "post">
45
- <h1 class = "post_title"><%= content_for :proclaim_title %></h1>
45
+ <div class = "post_title">
46
+ <h1 class = "post_title"><%= content_for :proclaim_title %></h1>
47
+ <h2 class = "post_subtitle"><%= @post.subtitle %></h2>
48
+ </div>
46
49
 
47
50
  <div id="scrolling-container">
48
51
  <div class = "post_body show">
@@ -0,0 +1,21 @@
1
+ class CreatePunchesTable < ActiveRecord::Migration[4.2]
2
+ def self.up
3
+ create_table :punches do |t|
4
+ t.integer :punchable_id, :null => false
5
+ t.string :punchable_type, :null => false, :limit => 20
6
+ t.datetime :starts_at, :null => false
7
+ t.datetime :ends_at, :null => false
8
+ t.datetime :average_time, :null => false
9
+ t.integer :hits, :null => false, :default=>1
10
+ end
11
+
12
+ add_index :punches, [:punchable_type, :punchable_id], :name => :punchable_index, :unique => false
13
+ add_index :punches, :average_time, :unique => false
14
+ end
15
+
16
+ def self.down
17
+ remove_index :punches, :name => :punchable_index
18
+ remove_index :punches, :average_time
19
+ drop_table :punches
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ class AddSubtitleToPosts < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :proclaim_posts, :subtitle, :string, null: false, default: ""
4
+ end
5
+ end
@@ -10,6 +10,7 @@ require 'aasm'
10
10
  require 'rails-timeago'
11
11
  require 'pundit'
12
12
  require 'premailer'
13
+ require 'punching_bag'
13
14
 
14
15
  module Proclaim
15
16
  class Engine < ::Rails::Engine
@@ -1,3 +1,3 @@
1
1
  module Proclaim
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proclaim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Fazzari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-08 00:00:00.000000000 Z
11
+ date: 2019-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
194
  version: 2.0.1
195
+ - !ruby/object:Gem::Dependency
196
+ name: punching_bag
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 0.6.1
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 0.6.1
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: sqlite3
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -407,6 +421,8 @@ files:
407
421
  - db/migrate/20141115022230_create_proclaim_comment_hierarchies.rb
408
422
  - db/migrate/20141210234057_create_proclaim_subscriptions.rb
409
423
  - db/migrate/20150213015321_create_friendly_id_slugs.rb
424
+ - db/migrate/20190615232009_create_punches_table.rb
425
+ - db/migrate/20190617014907_add_subtitle_to_posts.rb
410
426
  - lib/generators/proclaim/install_generator.rb
411
427
  - lib/generators/proclaim/templates/README
412
428
  - lib/generators/proclaim/templates/initialize_proclaim.rb
@@ -513,7 +529,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
513
529
  requirements:
514
530
  - - ">="
515
531
  - !ruby/object:Gem::Version
516
- version: '0'
532
+ version: 2.6.0
517
533
  required_rubygems_version: !ruby/object:Gem::Requirement
518
534
  requirements:
519
535
  - - ">="