go_blog 0.1.8 → 0.1.9

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: 8ea2e81e2488db6670ce03b199d35a88b8c84867
4
- data.tar.gz: 3c2016f760d3499f91e724ca3f13a2c6dc53883a
3
+ metadata.gz: f3a55d622a8b87cdbc4536bd1fbdcbee7704467b
4
+ data.tar.gz: 1d4495930c588ff2b8e59f02379c22cbc71b7d0a
5
5
  SHA512:
6
- metadata.gz: 8e9e7e823cfcf027ad47b3501a540851d11100ca7aa48fc31191dce8bf1da8351ee49a8088c7cb4bde6f5e029ad48489ea923298c7522a0877d66d603c8971e5
7
- data.tar.gz: 5d05e7670151d66de3bef1b0fd18ed6e2b7b1789421483b46496fc1818a43a08bb9d725d7b7b748e8e1c11530a78e70401bfb946b83d80c0b569f305b62154fe
6
+ metadata.gz: d4c0653c5a17f365aa96d8e8bed240dd793071b97a3a1075466d3b84e7587ec6b0fe580179182b3b9e2fa01bfd66f9666cf005727782c848a0ae5e235d7c88a6
7
+ data.tar.gz: bbc94763298bfb8d2284e6e2342c4df2aeb603d0ad4a614b1a9596a620cdfc458c0dd55ef9159cf0aaee9ba9d7673bc75f128a3b31319e5897977464a018698c
@@ -0,0 +1,4 @@
1
+ .css1 { font-size: 1.0em;}
2
+ .css2 { font-size: 1.2em;}
3
+ .css3 { font-size: 1.4em;}
4
+ .css4 { font-size: 1.6em;}
@@ -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
- @blog_posts = Post.all.page params[:page]
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
- @blog_posts = Post.where('? >= published_at and draft = ?', DateTime.now, false).includes(:user).page params[:page]
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
@@ -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 list_text
7
- return '' if !teaser.blank? and !body.blank?
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
@@ -0,0 +1,8 @@
1
+ class Blog::Tag < ApplicationRecord
2
+ has_many :taggings
3
+ has_many :posts, through: :taggings
4
+
5
+ def self.counts
6
+ self.select("blog_tags.name, count(blog_taggings.tag_id) as count").joins(:taggings).group("blog_taggings.tag_id,blog_tags.name")
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ class Blog::Tagging < ApplicationRecord
2
+ belongs_to :post
3
+ belongs_to :tag
4
+ 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(truncate_with_hover(resource.teaser, 30)) %></td>
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(truncate_with_hover(resource.teaser,30)) %></p>
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
- <h3 class="h4 text-white-op push-20 visibility-hidden" data-toggle="appear"> <strong></strong> </h3>
155
- <!--<a class="btn btn-rounded btn-noborder btn-lg btn-success visibility-hidden" data-toggle="appear" data-class="animated bounceIn" href="frontend_pricing.php">Get Started Today</a>-->
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%></em>
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
@@ -4,6 +4,7 @@ Rails.application.routes.draw do
4
4
  collection do
5
5
  get 'list'
6
6
  get 'show_list'
7
+ get 'tags/:tag', to: 'posts#list', as: "tag"
7
8
  end
8
9
  end
9
10
  end
@@ -0,0 +1,9 @@
1
+ class CreateBlogTags < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :blog_tags do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class CreateBlogTaggings < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :blog_taggings do |t|
4
+ t.integer :tag_id
5
+ t.integer :post_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module GoBlog
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
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.8
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-12 00:00:00.000000000 Z
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