about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-10-13 12:50:33 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-10-13 12:50:33 -0400
commit250ef8b5d4f6cb457c4976528f72f6ea7bf5f6cc (patch)
tree21dba266c2d0b6c39a7202fbaf119d6a0b7cecf0
parent27482983496cd0b8b6fa7dc943a1b05959735835 (diff)
downloadthoughts-250ef8b5d4f6cb457c4976528f72f6ea7bf5f6cc.tar.gz
thoughts-250ef8b5d4f6cb457c4976528f72f6ea7bf5f6cc.tar.bz2
thoughts-250ef8b5d4f6cb457c4976528f72f6ea7bf5f6cc.zip
Tag cloud
-rw-r--r--app/assets/stylesheets/main/entries.scss37
-rw-r--r--app/controllers/tags_controller.rb4
-rw-r--r--app/helpers/tags_helper.rb11
-rw-r--r--app/views/tags/index.html.haml4
-rw-r--r--config/routes.rb2
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 @@
1class TagsController < ApplicationController 1class 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 @@
1module 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
11end
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