From 5aae70298ba1ff9aa959ef1adc5380d76e0ddb34 Mon Sep 17 00:00:00 2001 From: Jeffrey Hardy Date: Wed, 4 Sep 2024 14:49:25 -0400 Subject: [PATCH] Rename Splat to Bubble --- .../stylesheets/{splats.css => bubble.css} | 76 +++++++++---------- app/controllers/boosts_controller.rb | 12 +-- app/controllers/bubbles_controller.rb | 43 +++++++++++ app/controllers/categories_controller.rb | 10 +-- app/controllers/comments_controller.rb | 10 +-- app/controllers/splats_controller.rb | 43 ----------- app/helpers/bubbles_helper.rb | 13 ++++ app/helpers/splats_helper.rb | 13 ---- app/models/boost.rb | 2 +- app/models/{splat.rb => bubble.rb} | 2 +- app/models/categorization.rb | 2 +- app/models/category.rb | 2 +- app/models/comment.rb | 2 +- app/views/boosts/_boost.html.erb | 2 +- app/views/boosts/create.turbo_stream.erb | 4 +- app/views/boosts/index.html.erb | 4 +- app/views/boosts/new.html.erb | 4 +- app/views/bubbles/_bubble.html.erb | 34 +++++++++ app/views/{splats => bubbles}/_form.html.erb | 8 +- app/views/bubbles/edit.html.erb | 3 + app/views/bubbles/index.html.erb | 51 +++++++++++++ app/views/bubbles/new.html.erb | 15 ++++ app/views/{splats => bubbles}/show.html.erb | 20 ++--- app/views/categories/index.html.erb | 2 +- app/views/categories/new.html.erb | 2 +- app/views/comments/_comment.html.erb | 2 +- app/views/comments/_new.html.erb | 4 +- app/views/sessions/new.html.erb | 10 +-- app/views/splats/_splat.html.erb | 34 --------- app/views/splats/edit.html.erb | 3 - app/views/splats/index.html.erb | 51 ------------- app/views/splats/new.html.erb | 15 ---- config/routes.rb | 4 +- ...20240904180510_rename_splats_to_bubbles.rb | 9 +++ db/schema.rb | 32 ++++---- public/406-unsupported-browser.html | 12 +-- ...ler_test.rb => bubbles_controller_test.rb} | 2 +- test/fixtures/boosts.yml | 8 +- test/fixtures/{splats.yml => bubbles.yml} | 0 test/fixtures/categorizations.yml | 8 +- test/fixtures/comments.yml | 4 +- test/models/{splat_test.rb => bubble_test.rb} | 2 +- 42 files changed, 294 insertions(+), 285 deletions(-) rename app/assets/stylesheets/{splats.css => bubble.css} (74%) create mode 100644 app/controllers/bubbles_controller.rb delete mode 100644 app/controllers/splats_controller.rb create mode 100644 app/helpers/bubbles_helper.rb delete mode 100644 app/helpers/splats_helper.rb rename app/models/{splat.rb => bubble.rb} (94%) create mode 100644 app/views/bubbles/_bubble.html.erb rename app/views/{splats => bubbles}/_form.html.erb (86%) create mode 100644 app/views/bubbles/edit.html.erb create mode 100644 app/views/bubbles/index.html.erb create mode 100644 app/views/bubbles/new.html.erb rename app/views/{splats => bubbles}/show.html.erb (63%) delete mode 100644 app/views/splats/_splat.html.erb delete mode 100644 app/views/splats/edit.html.erb delete mode 100644 app/views/splats/index.html.erb delete mode 100644 app/views/splats/new.html.erb create mode 100644 db/migrate/20240904180510_rename_splats_to_bubbles.rb rename test/controllers/{splats_controller_test.rb => bubbles_controller_test.rb} (55%) rename test/fixtures/{splats.yml => bubbles.yml} (100%) rename test/models/{splat_test.rb => bubble_test.rb} (64%) diff --git a/app/assets/stylesheets/splats.css b/app/assets/stylesheets/bubble.css similarity index 74% rename from app/assets/stylesheets/splats.css rename to app/assets/stylesheets/bubble.css index 9a414a634..b29a78c7e 100644 --- a/app/assets/stylesheets/splats.css +++ b/app/assets/stylesheets/bubble.css @@ -1,5 +1,5 @@ :root { - --splat-size: 30vw; + --bubble-size: 30vw; } .windshield { @@ -10,14 +10,14 @@ } } -.splat { +.bubble { --hover-size: 0; - --splat-color: var(--color-ink); - --splat-rotate: 20deg; + --bubble-color: var(--color-ink); + --bubble-rotate: 20deg; aspect-ratio: 1; - block-size: var(--splat-size); - color: var(--splat-color, currentColor); + block-size: var(--bubble-size); + color: var(--bubble-color, currentColor); container-type: inline-size; display: grid; max-inline-size: 100%; @@ -50,8 +50,8 @@ scale: 1.1; z-index: 999; - .splat__svg { - transform: rotate(calc(var(--splat-rotate) + 10deg)); + .bubble__svg { + transform: rotate(calc(var(--bubble-rotate) + 10deg)); } } } @@ -60,23 +60,23 @@ grid-area: 1/1; } - .splat__perma & { - --splat-size: 40vh !important; + .bubble__perma & { + --bubble-size: 40vh !important; } } -.splat__bubble { +.bubble__bubble { background-color: var(--color-bg); - border: 0.3em solid var(--splat-color); + border: 0.3em solid var(--bubble-color); border-radius: 50%; position: absolute; z-index: -1; a { - color: var(--splat-color); + color: var(--bubble-color); } - &:is(.splat__boosts) { + &:is(.bubble__boosts) { aspect-ratio: 1; display: grid; min-inline-size: 6ch; @@ -89,7 +89,7 @@ text-decoration: none; } - .windshield .splat:hover & { + .windshield .bubble:hover & { transform: translate(0, 1rem) !important; } @@ -98,7 +98,7 @@ } } - &.splat__category { + &.bubble__category { inset: auto auto 10cqi -3cqi; + & { @@ -109,20 +109,20 @@ } } - .windshield &:has(.splat__category--new) { + .windshield &:has(.bubble__category--new) { display: none; } } - &.splat__date { + &.bubble__date { aspect-ratio: 1; inset: 2cqi 2cqi auto auto; } - &:where(.splat__meta) { + &:where(.bubble__meta) { background-color: var(--color-bg); block-size: auto; - color: var(--splat-color); + color: var(--bubble-color); display: flex; font-size: 5cqi; font-weight: 800; @@ -143,27 +143,27 @@ padding: 0.2em 0.5em; .input { - color: var(--splat-color); + color: var(--bubble-color); } } } @media (hover: hover) { - .windshield .splat:hover & { + .windshield .bubble:hover & { transform: translate(1rem, 1rem); } - .windshield .splat:hover & + & { + .windshield .bubble:hover & + & { transform: translate(0, -1rem); } - .windshield .splat:hover & + & + & { + .windshield .bubble:hover & + & + & { transform: translate(-1rem, -1rem); } } } -.splat__image { +.bubble__image { -webkit-mask-image: url(blob.svg); -webkit-mask-size: contain; -webkit-mask-repeat: no-repeat; @@ -176,44 +176,44 @@ mask-size: contain; place-items: center; pointer-events: none; - transform: rotate(var(--splat-rotate)); + transform: rotate(var(--bubble-rotate)); @media (hover: hover) { - .windshield .splat:hover & { - transform: rotate(calc(var(--splat-rotate) + 10deg)); + .windshield .bubble:hover & { + transform: rotate(calc(var(--bubble-rotate) + 10deg)); } } img { block-size: 100%; object-fit: cover; - transform: rotate(calc(var(--splat-rotate) * -1)); + transform: rotate(calc(var(--bubble-rotate) * -1)); } } -.splat__link { +.bubble__link { content: ""; inset: 0; position: absolute; z-index: -1; } -.splat__notes { +.bubble__notes { position: relative; } -.splat__svg { +.bubble__svg { fill: var(--color-bg); pointer-events: none; position: relative; scale: 1.1; - stroke: var(--splat-color); + stroke: var(--bubble-color); stroke-width: 1.1rem; transition: all 200ms ease-out; z-index: -1; } -.splat__title { +.bubble__title { -webkit-line-clamp: var(--lines, 5); -webkit-box-orient: vertical; display: -webkit-box; @@ -229,19 +229,19 @@ white-space: normal; @media (hover: hover) { - .splat:has(.splat__image):hover & { + .bubble:has(.bubble__image):hover & { color: var(--color-ink-reversed); - text-shadow: 0 0 0.2em var(--splat-color), 0 0 0.2em var(--splat-color), 0 0 0.2em var(--splat-color); + text-shadow: 0 0 0.2em var(--bubble-color), 0 0 0.2em var(--bubble-color), 0 0 0.2em var(--bubble-color); position: relative; z-index: 1; } } } -.splats-list { +.bubbles-list { --hover-size: 0; - .splat__title-link { + .bubble__title-link { color: var(--color-txt); text-decoration: none; } diff --git a/app/controllers/boosts_controller.rb b/app/controllers/boosts_controller.rb index 398874e7c..597052fd7 100644 --- a/app/controllers/boosts_controller.rb +++ b/app/controllers/boosts_controller.rb @@ -1,12 +1,12 @@ class BoostsController < ApplicationController - before_action :set_splat + before_action :set_bubble def new - @boost = @splat.boosts.build + @boost = @bubble.boosts.build end def create - @boost = @splat.boosts.new + @boost = @bubble.boosts.new @boost.save respond_to do |format| @@ -16,11 +16,11 @@ class BoostsController < ApplicationController end def index - @boosts = @splat.boosts + @boosts = @bubble.boosts end private - def set_splat - @splat = Splat.find(params[:splat_id]) + def set_bubble + @bubble = Bubble.find(params[:bubble_id]) end end diff --git a/app/controllers/bubbles_controller.rb b/app/controllers/bubbles_controller.rb new file mode 100644 index 000000000..3cb25f5fd --- /dev/null +++ b/app/controllers/bubbles_controller.rb @@ -0,0 +1,43 @@ +class BubblesController < ApplicationController + before_action :set_bubble, only: %i[ show edit update ] + + def index + if params[:category_id] + @category = Category.find(params[:category_id]) + @bubbles = @category.bubbles + else + @bubbles = Bubble.all + end + end + + def new + @bubble = Bubble.new + end + + def edit + end + + def update + @bubble.update(bubble_params) + + redirect_to bubble_path(@bubble) + end + + def create + Bubble.create! bubble_params + + redirect_to bubbles_path + end + + def show + end + + private + def set_bubble + @bubble = Bubble.find(params[:id]) + end + + def bubble_params + params.require(:bubble).permit(:title, :body, :color, :image, category_ids: []) + end +end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 3e21f9102..379e625ea 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,6 +1,6 @@ class CategoriesController < ApplicationController before_action :set_category, only: :destroy - before_action :set_splat, only: %i[ new create ] + before_action :set_bubble, only: %i[ new create ] def index @categories = Category.all @@ -14,8 +14,8 @@ class CategoriesController < ApplicationController @category = Category.find_or_create_by(category_params) @category.save - @category.splats << @splat - redirect_to splat_path(@splat) + @category.bubbles << @bubble + redirect_to bubble_path(@bubble) end def destroy @@ -33,7 +33,7 @@ class CategoriesController < ApplicationController @category = Category.find(params[:id]) end - def set_splat - @splat = Splat.find(params[:splat_id]) + def set_bubble + @bubble = Bubble.find(params[:bubble_id]) end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index a08a0d12c..7058ced2c 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,11 +1,11 @@ class CommentsController < ApplicationController - before_action :set_splat + before_action :set_bubble def create - @comment = @splat.comments.create(comment_params) + @comment = @bubble.comments.create(comment_params) @comment.save - redirect_to splat_path(@splat, anchor: "comment_#{@comment.id}") + redirect_to bubble_path(@bubble, anchor: "comment_#{@comment.id}") end private @@ -13,7 +13,7 @@ class CommentsController < ApplicationController params.require(:comment).permit(:body) end - def set_splat - @splat = Splat.find(params[:splat_id]) + def set_bubble + @bubble = Bubble.find(params[:bubble_id]) end end diff --git a/app/controllers/splats_controller.rb b/app/controllers/splats_controller.rb deleted file mode 100644 index 471006d19..000000000 --- a/app/controllers/splats_controller.rb +++ /dev/null @@ -1,43 +0,0 @@ -class SplatsController < ApplicationController - before_action :set_splat, only: %i[ show edit update ] - - def index - if params[:category_id] - @category = Category.find(params[:category_id]) - @splats = @category.splats - else - @splats = Splat.all - end - end - - def new - @splat = Splat.new - end - - def edit - end - - def update - @splat.update(splat_params) - - redirect_to splat_path(@splat) - end - - def create - Splat.create! splat_params - - redirect_to splats_path - end - - def show - end - - private - def set_splat - @splat = Splat.find(params[:id]) - end - - def splat_params - params.require(:splat).permit(:title, :body, :color, :image, category_ids: []) - end -end diff --git a/app/helpers/bubbles_helper.rb b/app/helpers/bubbles_helper.rb new file mode 100644 index 000000000..263244705 --- /dev/null +++ b/app/helpers/bubbles_helper.rb @@ -0,0 +1,13 @@ +module BubblesHelper + BUBBLE_ROTATION = %w[ 90 80 75 60 45 35 25 5 -45 -40 -75 ] + BUBBLE_SIZE = [ 14, 16, 18, 20, 22 ] + MIN_THRESHOLD = 7 + + def bubble_rotation(bubble) + BUBBLE_ROTATION[Zlib.crc32(bubble.to_param) % BUBBLE_ROTATION.size] + end + + def bubble_size(bubble) + "--bubble-size: #{ BUBBLE_SIZE.min_by { |size| (size - (bubble.boosts.size + bubble.comments.size + MIN_THRESHOLD)).abs } }cqi;" + end +end diff --git a/app/helpers/splats_helper.rb b/app/helpers/splats_helper.rb deleted file mode 100644 index 8adfcd27b..000000000 --- a/app/helpers/splats_helper.rb +++ /dev/null @@ -1,13 +0,0 @@ -module SplatsHelper - SPLAT_ROTATION = %w[ 90 80 75 60 45 35 25 5 -45 -40 -75 ] - SPLAT_SIZE = [ 14, 16, 18, 20, 22 ] - MIN_THRESHOLD = 7 - - def splat_rotation(splat) - SPLAT_ROTATION[Zlib.crc32(splat.to_param) % SPLAT_ROTATION.size] - end - - def splat_size(splat) - "--splat-size: #{ SPLAT_SIZE.min_by { |size| (size - (splat.boosts.size + splat.comments.size + MIN_THRESHOLD)).abs } }cqi;" - end -end diff --git a/app/models/boost.rb b/app/models/boost.rb index b368ec116..41b0edb7a 100644 --- a/app/models/boost.rb +++ b/app/models/boost.rb @@ -1,4 +1,4 @@ class Boost < ApplicationRecord - belongs_to :splat + belongs_to :bubble belongs_to :creator, class_name: "User", default: -> { Current.user } end diff --git a/app/models/splat.rb b/app/models/bubble.rb similarity index 94% rename from app/models/splat.rb rename to app/models/bubble.rb index 22a30ca9c..98cdbcce8 100644 --- a/app/models/splat.rb +++ b/app/models/bubble.rb @@ -1,4 +1,4 @@ -class Splat < ApplicationRecord +class Bubble < ApplicationRecord belongs_to :creator, class_name: "User", default: -> { Current.user } has_many :comments, dependent: :destroy diff --git a/app/models/categorization.rb b/app/models/categorization.rb index ebf51a5df..dba46484c 100644 --- a/app/models/categorization.rb +++ b/app/models/categorization.rb @@ -1,4 +1,4 @@ class Categorization < ApplicationRecord - belongs_to :splat + belongs_to :bubble belongs_to :category end diff --git a/app/models/category.rb b/app/models/category.rb index 5a61d0d49..09f1548c5 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,4 +1,4 @@ class Category < ApplicationRecord has_many :categorizations, dependent: :destroy - has_many :splats, through: :categorizations + has_many :bubbles, through: :categorizations end diff --git a/app/models/comment.rb b/app/models/comment.rb index cd4b57456..3791cde58 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,4 +1,4 @@ class Comment < ApplicationRecord - belongs_to :splat + belongs_to :bubble belongs_to :creator, class_name: "User", default: -> { Current.user } end diff --git a/app/views/boosts/_boost.html.erb b/app/views/boosts/_boost.html.erb index 4fac9ef2c..fac9f3522 100644 --- a/app/views/boosts/_boost.html.erb +++ b/app/views/boosts/_boost.html.erb @@ -1 +1 @@ -<%= link_to splat.boosts.any? ? "+ #{splat.boosts.size}" : "+", new_splat_boost_path(splat), data: { action: "toggle-class#toggle" } %> +<%= link_to bubble.boosts.any? ? "+ #{bubble.boosts.size}" : "+", new_bubble_boost_path(bubble), data: { action: "toggle-class#toggle" } %> diff --git a/app/views/boosts/create.turbo_stream.erb b/app/views/boosts/create.turbo_stream.erb index 1a7fb26fd..68e8def74 100644 --- a/app/views/boosts/create.turbo_stream.erb +++ b/app/views/boosts/create.turbo_stream.erb @@ -1,3 +1,3 @@ -<%= turbo_stream.update dom_id(@splat, "boosts") do %> - <%= render "/boosts/boost", splat: @splat %> +<%= turbo_stream.update dom_id(@bubble, "boosts") do %> + <%= render "/boosts/boost", bubble: @bubble %> <% end %> diff --git a/app/views/boosts/index.html.erb b/app/views/boosts/index.html.erb index c3eebad03..71e421d1d 100644 --- a/app/views/boosts/index.html.erb +++ b/app/views/boosts/index.html.erb @@ -1,3 +1,3 @@ -"> - <%= render "/boosts/boost", splat: @splat %> +"> + <%= render "/boosts/boost", bubble: @bubble %> diff --git a/app/views/boosts/new.html.erb b/app/views/boosts/new.html.erb index 180f27376..1d7ced7e1 100644 --- a/app/views/boosts/new.html.erb +++ b/app/views/boosts/new.html.erb @@ -1,5 +1,5 @@ -"> - <%= form_with model: [@splat, @boost], data: { controller: "auto-submit" } do |form| %> +"> + <%= form_with model: [@bubble, @boost], data: { controller: "auto-submit" } do |form| %> <%= form.submit "Boost this", hidden: true %> <% end %> diff --git a/app/views/bubbles/_bubble.html.erb b/app/views/bubbles/_bubble.html.erb new file mode 100644 index 000000000..f769ece8a --- /dev/null +++ b/app/views/bubbles/_bubble.html.erb @@ -0,0 +1,34 @@ +
+

<%= bubble.title %>

+ + + + <%= link_to bubble, class: "bubble__link" do %> + <%= bubble.title %> + <% end %> + + <% if bubble.image.attached? %> +
+ <%= image_tag bubble.image %> +
+ <% end %> + + + + <% bubble.categories.each do | category | %> + <%= link_to "##{category.title}", bubbles_path(category_id: category.id), class: "bubble__bubble bubble__meta bubble__category" %> + <% end %> + + <% if bubble.categories.count < 3 %> + + + <%= link_to "#", new_bubble_category_path(bubble), class: "bubble__category--new" %> + + + <% end %> + + <%= tag.div class: "bubble__bubble bubble__meta bubble__boosts", + data: { controller: "animation toggle-class", animation_play_class: "boosting", toggle_class_toggle_class: "boosting", action: "animationend->toggle-class#toggle" } do %> + " src="<%= bubble_boosts_path(bubble) %>" /> + <% end %> +
diff --git a/app/views/splats/_form.html.erb b/app/views/bubbles/_form.html.erb similarity index 86% rename from app/views/splats/_form.html.erb rename to app/views/bubbles/_form.html.erb index 4c695df63..2e503a5c4 100644 --- a/app/views/splats/_form.html.erb +++ b/app/views/bubbles/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_with model: splat, class: "flex flex-column gap full-width" do | form | %> +<%= form_with model: bubble, class: "flex flex-column gap full-width" do | form | %> <%= form.label :title, class: "flex flex-column justify-start align-start" do %> <%= form.text_field :title, class: "input full-width", required: true, placeholder: "Name it…" %> <% end %> @@ -7,7 +7,7 @@ Color
- <% Splat.colors.keys.each do | color | %> + <% Bubble.colors.keys.each do | color | %>