diff options
-rw-r--r-- | app/assets/stylesheets/main/entries.scss | 37 | ||||
-rw-r--r-- | app/controllers/tags_controller.rb | 4 | ||||
-rw-r--r-- | app/helpers/tags_helper.rb | 11 | ||||
-rw-r--r-- | app/views/tags/index.html.haml | 4 | ||||
-rw-r--r-- | config/routes.rb | 2 |
5 files changed, 57 insertions, 1 deletions
diff --git a/app/assets/stylesheets/main/entries.scss b/app/assets/stylesheets/main/entries.scss index a4e9463..8d5796f 100644 --- a/app/assets/stylesheets/main/entries.scss +++ b/app/assets/stylesheets/main/entries.scss | |||
@@ -355,3 +355,40 @@ | |||
355 | margin-left: 1em; | 355 | margin-left: 1em; |
356 | } | 356 | } |
357 | } | 357 | } |
358 | |||
359 | #tag-cloud { | ||
360 | width: 75%; | ||
361 | margin: 0 auto; | ||
362 | text-align: center; | ||
363 | |||
364 | a { | ||
365 | display: inline-block; | ||
366 | margin-right: 0.5em; | ||
367 | text-decoration: none; | ||
368 | |||
369 | &:hover { | ||
370 | text-decoration: underline; | ||
371 | } | ||
372 | |||
373 | &:visited { | ||
374 | color: blue; | ||
375 | } | ||
376 | } | ||
377 | |||
378 | .xs { | ||
379 | font-size: 0.75em; | ||
380 | } | ||
381 | |||
382 | .m { | ||
383 | font-size: 2em; | ||
384 | } | ||
385 | |||
386 | .l { | ||
387 | font-size: 3em; | ||
388 | } | ||
389 | |||
390 | .xl { | ||
391 | font-size: 3em; | ||
392 | font-weight: bold; | ||
393 | } | ||
394 | } | ||
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index bceb3cf..355706b 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb | |||
@@ -1,5 +1,9 @@ | |||
1 | class TagsController < ApplicationController | 1 | class TagsController < ApplicationController |
2 | 2 | ||
3 | def index | ||
4 | @tags = Blog.tag_counts | ||
5 | end | ||
6 | |||
3 | def show | 7 | def show |
4 | @tag_name = params[:name] | 8 | @tag_name = params[:name] |
5 | @blogs = Blog.tagged_with(params[:name]).where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10) | 9 | @blogs = Blog.tagged_with(params[:name]).where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10) |
diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb new file mode 100644 index 0000000..9643834 --- /dev/null +++ b/app/helpers/tags_helper.rb | |||
@@ -0,0 +1,11 @@ | |||
1 | module TagsHelper | ||
2 | |||
3 | def tag_cloud(tags, classes) | ||
4 | max = tags.sort_by(&:taggings_count).last | ||
5 | tags.each do |tag| | ||
6 | index = tag.taggings_count.to_f / max.taggings_count * (classes.size - 1) | ||
7 | yield(tag, classes[index.round]) | ||
8 | end | ||
9 | end | ||
10 | |||
11 | end | ||
diff --git a/app/views/tags/index.html.haml b/app/views/tags/index.html.haml new file mode 100644 index 0000000..c9f1e85 --- /dev/null +++ b/app/views/tags/index.html.haml | |||
@@ -0,0 +1,4 @@ | |||
1 | %h2.centered Tag cloud | ||
2 | #tag-cloud | ||
3 | - tag_cloud @tags, %w[xs s m l xl] do |tag, css_class| | ||
4 | = link_to tag.name, tag_url(tag.name), class: css_class, title: tag.taggings_count | ||
diff --git a/config/routes.rb b/config/routes.rb index a3448f0..5aa1558 100644 --- a/config/routes.rb +++ b/config/routes.rb | |||
@@ -36,7 +36,7 @@ Rails.application.routes.draw do | |||
36 | 36 | ||
37 | get 'plays', to: 'games#index' | 37 | get 'plays', to: 'games#index' |
38 | 38 | ||
39 | resources :tags, only: [:show], param: :name do | 39 | resources :tags, only: [:index, :show], param: :name do |
40 | collection do | 40 | collection do |
41 | get 'suggest' | 41 | get 'suggest' |
42 | end | 42 | end |