go_blog 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/tags.css.scss +4 -0
- data/app/controllers/blog/posts_controller.rb +12 -3
- data/app/helpers/blog/posts_helper.rb +12 -0
- data/app/models/blog/post.rb +21 -4
- data/app/models/blog/tag.rb +8 -0
- data/app/models/blog/tagging.rb +4 -0
- data/app/views/blog/posts/_collection.html.erb +1 -1
- data/app/views/blog/posts/_collection_list.html.erb +1 -1
- data/app/views/blog/posts/_form.html.erb +2 -2
- data/app/views/blog/posts/list.html.erb +6 -2
- data/app/views/blog/posts/show.html.erb +4 -0
- data/app/views/blog/posts/show_list.html.erb +11 -1
- data/config/routes.rb +1 -0
- data/db/migrate/20171012235935_create_blog_tags.rb +9 -0
- data/db/migrate/20171013000036_create_blog_taggings.rb +10 -0
- data/lib/go_blog/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3a55d622a8b87cdbc4536bd1fbdcbee7704467b
|
4
|
+
data.tar.gz: 1d4495930c588ff2b8e59f02379c22cbc71b7d0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4c0653c5a17f365aa96d8e8bed240dd793071b97a3a1075466d3b84e7587ec6b0fe580179182b3b9e2fa01bfd66f9666cf005727782c848a0ae5e235d7c88a6
|
7
|
+
data.tar.gz: bbc94763298bfb8d2284e6e2342c4df2aeb603d0ad4a614b1a9596a620cdfc458c0dd55ef9159cf0aaee9ba9d7673bc75f128a3b31319e5897977464a018698c
|
@@ -5,11 +5,20 @@ module Blog
|
|
5
5
|
load_and_authorize_resource except: [:list, :show_list, :create]
|
6
6
|
# GET /blog/posts
|
7
7
|
def index
|
8
|
-
|
8
|
+
if params[:tag]
|
9
|
+
@blog_posts = Post.tagged_with(params[:tag]).page params[:page]
|
10
|
+
else
|
11
|
+
@blog_posts = Post.all.page params[:page]
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
def list
|
12
|
-
|
16
|
+
|
17
|
+
if params[:tag]
|
18
|
+
@blog_posts = Post.tagged_with(params[:tag]).page params[:page]
|
19
|
+
else
|
20
|
+
@blog_posts = Post.where('? >= published_at and draft = ?', DateTime.now, false).includes(:user).page params[:page]
|
21
|
+
end
|
13
22
|
end
|
14
23
|
|
15
24
|
# GET /blog/posts/1
|
@@ -64,7 +73,7 @@ module Blog
|
|
64
73
|
|
65
74
|
# Only allow a trusted parameter "white list" through.
|
66
75
|
def blog_post_params
|
67
|
-
params.require(:blog_post).permit(:title, :teaser, :body, :draft, :published_at, :user_id, :custom_url, :access_count)
|
76
|
+
params.require(:blog_post).permit(:title, :teaser, :body, :draft, :published_at, :user_id, :custom_url, :access_count,:all_tags)
|
68
77
|
end
|
69
78
|
end
|
70
79
|
end
|
@@ -1,2 +1,14 @@
|
|
1
1
|
module Blog::PostsHelper
|
2
|
+
|
3
|
+
def tag_links(tags)
|
4
|
+
tags.split(",").map{|tag| link_to tag.strip, list_blog_posts_path(tag:tag.strip) }.join(", ")
|
5
|
+
end
|
6
|
+
|
7
|
+
def tag_cloud(tags, classes)
|
8
|
+
max = tags.sort_by(&:count).last
|
9
|
+
tags.each do |tag|
|
10
|
+
index = tag.count.to_f / max.count * (classes.size-1)
|
11
|
+
yield(tag, classes[index.round])
|
12
|
+
end
|
13
|
+
end
|
2
14
|
end
|
data/app/models/blog/post.rb
CHANGED
@@ -2,11 +2,28 @@ module Blog
|
|
2
2
|
class Post < ApplicationRecord
|
3
3
|
validates_presence_of :title, :user_id, :body
|
4
4
|
belongs_to :user
|
5
|
+
has_many :taggings
|
6
|
+
has_many :tags, through: :taggings
|
5
7
|
|
6
|
-
def
|
7
|
-
|
8
|
-
teaser if !teaser.blank?
|
9
|
-
body if !body.blank?
|
8
|
+
def self.tagged_with(name)
|
9
|
+
Tag.find_by_name!(name).posts.where('? >= published_at and draft = ?', DateTime.now, false).includes(:user)
|
10
10
|
end
|
11
|
+
|
12
|
+
def reading_time
|
13
|
+
words_per_minute = 150
|
14
|
+
text = Nokogiri::HTML(self.body).at('body').inner_text
|
15
|
+
(text.scan(/\w+/).length / words_per_minute).to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def all_tags=(names)
|
19
|
+
self.tags = names.split(",").map do |name|
|
20
|
+
Tag.where(name: name.strip).first_or_create!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def all_tags
|
25
|
+
self.tags.map(&:name).join(", ")
|
26
|
+
end
|
27
|
+
|
11
28
|
end
|
12
29
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<% collection.each do |resource| %>
|
2
2
|
<tr id="<%= dom_id(resource) %>">
|
3
3
|
<td><%= resource.title %></td>
|
4
|
-
<td><%= raw(
|
4
|
+
<td><%= raw(resource.teaser) %></td>
|
5
5
|
<td><%= resource.draft %></td>
|
6
6
|
<td><%= converte_date(resource.published_at) %></td>
|
7
7
|
<td><%= resource.user_id %></td>
|
@@ -14,7 +14,7 @@
|
|
14
14
|
</div>
|
15
15
|
<h4 class="text-uppercase push-10">
|
16
16
|
<%= resource.decorate.link_to_title %></h4>
|
17
|
-
<p class="push-20"><%= raw(
|
17
|
+
<p class="push-20"><%= raw(resource.teaser) %></p>
|
18
18
|
<div class="btn-group btn-group-sm">
|
19
19
|
<!--<a class="btn btn-default" href="javascript:void(0)"><i class="fa fa-share-alt push-5-r"></i> Compartilhar</a>-->
|
20
20
|
<%= resource.decorate.link_to_read_more %>
|
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
<%= f.input :custom_url, id: :blog_post_custom_url %>
|
17
17
|
|
18
|
-
|
18
|
+
<%= f.input :all_tags, placeholder: "Tags separated with comma" %>
|
19
19
|
|
20
20
|
<div class="form-group form-actions">
|
21
21
|
<%= link_to I18n.t('misc.action.back'), blog_posts_path, class: 'btn btn-sm btn-square btn-default' %>
|
@@ -24,7 +24,7 @@
|
|
24
24
|
<% end %>
|
25
25
|
|
26
26
|
<script type="text/javascript">
|
27
|
-
$(document).ready(function() {
|
27
|
+
$(document).ready(function () {
|
28
28
|
$('#blog_post_teaser').summernote({
|
29
29
|
lang: 'pt-BR',
|
30
30
|
codemirror: { // codemirror options
|
@@ -151,8 +151,12 @@
|
|
151
151
|
<div class="bg-primary-dark">
|
152
152
|
<section class="content content-full content-boxed">
|
153
153
|
<div class="push-20-t push-20 text-center">
|
154
|
-
<
|
155
|
-
|
154
|
+
<div class="tags-cloud glassy-bg">
|
155
|
+
<h4>Nuvem de Tags</h4>
|
156
|
+
<% tag_cloud Blog::Tag.counts, %w{css1 css2 css3 css4} do |tag, css_class| %>
|
157
|
+
<%= link_to tag.name, list_blog_posts_path(tag:tag.name), class: css_class %>
|
158
|
+
<% end %>
|
159
|
+
</div>
|
156
160
|
</div>
|
157
161
|
</section>
|
158
162
|
</div>
|
@@ -66,6 +66,10 @@
|
|
66
66
|
<td><strong><%= t 'activerecord.attributes.blog_post.access_count' %>:</strong></td>
|
67
67
|
<td><%= @blog_post.access_count %></td>
|
68
68
|
</tr>
|
69
|
+
<tr>
|
70
|
+
<td><strong><%= t 'activerecord.attributes.blog_post.tags' %>:</strong></td>
|
71
|
+
<td><%=raw tag_links(@blog_post.all_tags)%></td>
|
72
|
+
</tr>
|
69
73
|
|
70
74
|
|
71
75
|
</tbody>
|
@@ -11,7 +11,10 @@
|
|
11
11
|
<div class="bg-white">
|
12
12
|
<section class="content content-boxed">
|
13
13
|
<div class="text-center">
|
14
|
-
<%= @blog_post.decorate.link_to_author %> - <%= converte_date(@blog_post.published_at) %> <em>visualizado <%=@blog_post.access_count
|
14
|
+
<%= @blog_post.decorate.link_to_author %> - <%= converte_date(@blog_post.published_at) %> <em>visualizado <%=@blog_post.access_count%> x- <div class="wordcount">
|
15
|
+
<i class="fa fa-clock-o"></i>
|
16
|
+
<span><%=pluralize(@blog_post.reading_time, 'minutos')%></span>
|
17
|
+
</div></em>
|
15
18
|
</div>
|
16
19
|
<div class="row push-50-t push-50 nice-copy-story">
|
17
20
|
<div class="col-sm-8 col-sm-offset-2">
|
@@ -20,9 +23,16 @@
|
|
20
23
|
|
21
24
|
</div>
|
22
25
|
</div>
|
26
|
+
|
23
27
|
</section>
|
24
28
|
</div>
|
25
29
|
|
30
|
+
<section class="content content-full content-boxed">
|
31
|
+
<div class="push-20-t push-20 text-center">
|
32
|
+
<h3 class="h4 text-white-op push-20 animated fadeIn" data-toggle="appear"> <%=raw tag_links(@blog_post.all_tags)%></h3>
|
33
|
+
</div>
|
34
|
+
</section>
|
35
|
+
|
26
36
|
</main>
|
27
37
|
|
28
38
|
|
data/config/routes.rb
CHANGED
data/lib/go_blog/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: go_blog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Carlos Ottobboni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: draper
|
@@ -66,12 +66,15 @@ files:
|
|
66
66
|
- app/assets/javascripts/blog/posts.js
|
67
67
|
- app/assets/stylesheets/blog/posts.css
|
68
68
|
- app/assets/stylesheets/scaffold.css
|
69
|
+
- app/assets/stylesheets/tags.css.scss
|
69
70
|
- app/controllers/blog/posts_controller.rb
|
70
71
|
- app/decorator/blog/post_decorator.rb
|
71
72
|
- app/helpers/blog/posts_helper.rb
|
72
73
|
- app/models/application_record.rb
|
73
74
|
- app/models/blog.rb
|
74
75
|
- app/models/blog/post.rb
|
76
|
+
- app/models/blog/tag.rb
|
77
|
+
- app/models/blog/tagging.rb
|
75
78
|
- app/views/blog/posts/_collection.html.erb
|
76
79
|
- app/views/blog/posts/_collection_list.html.erb
|
77
80
|
- app/views/blog/posts/_form.html.erb
|
@@ -86,6 +89,8 @@ files:
|
|
86
89
|
- app/views/blog/posts/show_list.html.erb
|
87
90
|
- config/routes.rb
|
88
91
|
- db/migrate/20171008203759_create_blog_posts.rb
|
92
|
+
- db/migrate/20171012235935_create_blog_tags.rb
|
93
|
+
- db/migrate/20171013000036_create_blog_taggings.rb
|
89
94
|
- lib/go_blog.rb
|
90
95
|
- lib/go_blog/engine.rb
|
91
96
|
- lib/go_blog/version.rb
|