homeland-press 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: e9cc3c455c07a0670af45ab7a72ff155d5447688
4
- data.tar.gz: ec7204dbc3eceb92ea1c36a2ecb5f695e76c3a10
3
+ metadata.gz: 30be3e204d09b92d87040eb9d2ae7761afbcdad7
4
+ data.tar.gz: df05927e51707cd6bbce8c83dc19a5917c995f50
5
5
  SHA512:
6
- metadata.gz: b0f854ec0699c3e0567385da2d5cab44c4a198e17963b1664a5dfc978417db886b9064e2b982ed0af23b753f8dc5d0536222d51e11488ced7aa7028b828e0635
7
- data.tar.gz: e97c740289298fe1f58ece76c606d7e46c6f5c8c7689c5e392c7cd90fa3e09365399e002a06e809ec4ac9a07dd36920f663c2d3c1dc86ab741987ab2e3b61efd
6
+ metadata.gz: cda7883c57d45ec8bdd9096cb282b9da3bf8c7adc2c3a884bbc4a36aa4cf00d0e56a37e83145782318f52452dc54a5543b014a8401be3b82ecc424160181845c
7
+ data.tar.gz: 41ee2131ca13e4c292253819b9a5b2513c91ed356328eec0f2c59b64b1c9da913fba38aa0a88e6818b174de85aed11317fdd6a6a54fe98b0a81e9a6434d9028d
@@ -1,5 +1,10 @@
1
1
  module Homeland::Press
2
2
  module ApplicationHelper
3
3
  delegate :comments_path, to: :main_app
4
+
5
+ def press_user_name_tag(user)
6
+ return '官方' if user.admin?
7
+ user_name_tag(user)
8
+ end
4
9
  end
5
10
  end
@@ -4,10 +4,14 @@ class Post < ApplicationRecord
4
4
 
5
5
  enum status: %i(upcoming published rejected)
6
6
 
7
+ validates :slug, uniqueness: true, if: Proc.new { |post| post.slug.present? }
8
+ validates :title, :summary, :body, presence: true
9
+
7
10
  counter :hits
8
11
 
9
12
  before_save :generate_summary
10
13
  before_create :generate_published_at
14
+ before_validation :safe_slug
11
15
 
12
16
  def to_param
13
17
  self.slug.blank? ? self.id : self.slug
@@ -33,6 +37,11 @@ class Post < ApplicationRecord
33
37
 
34
38
  private
35
39
 
40
+ def safe_slug
41
+ self.slug.downcase!
42
+ self.slug.gsub!(/[^a-z0-9]/i, '-')
43
+ end
44
+
36
45
  def generate_published_at
37
46
  self.published_at = Time.now
38
47
  end
@@ -12,7 +12,7 @@
12
12
  <%= simple_format post.summary %>
13
13
  </div>
14
14
  <div class="post-info">
15
- <%= user_name_tag(post.user) %> ·
15
+ <%= press_user_name_tag(post.user) %> ·
16
16
  <span class="time" title="发布时间"><i class="fa fa-clock-o"></i> <%= timeago(post.created_at) %></span> ·
17
17
  <%= link_to "#{post.comments_count} 条评论", post_path(post, anchor: 'comments') %>
18
18
  </div>
@@ -23,7 +23,7 @@
23
23
  </div>
24
24
  <h1><%= @post.title %></h1>
25
25
  <div class="post-info">
26
- <%= user_name_tag(@post.user) %> ·
26
+ <%= press_user_name_tag(@post.user) %> ·
27
27
  <span class="time" title="发布时间"><i class="fa fa-clock-o"></i> <%= timeago @post.created_at %></span> ·
28
28
  <%= @post.hits %> 次阅读 ·
29
29
  <a href="#comments"><i class="fa fa-comments-o"></i> <%= @post.comments_count %> 条评论</a>
@@ -34,7 +34,9 @@
34
34
  <div class="post-actions">
35
35
  <%= likeable_tag(@post, class: 'btn btn-lg btn-default') %>
36
36
 
37
- <%= reward_user_tag(@post.user, class: 'btn btn-lg btn-default') %>
37
+ <% unless @post.user&.admin? %>
38
+ <%= reward_user_tag(@post.user, class: 'btn btn-lg btn-default') %>
39
+ <% end %>
38
40
  </div>
39
41
  </div>
40
42
  </div>
@@ -1,6 +1,6 @@
1
1
  module Homeland
2
2
  module Press
3
3
  NAME = 'press'
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: homeland-press
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee