From 9770a03d78068771d14cffe76d4fad028cc2f003 Mon Sep 17 00:00:00 2001 From: Olivier Patry Date: Wed, 15 May 2024 13:29:53 +0200 Subject: [PATCH] Simpler code for custom rating display --- content/index.html.erb | 7 ++----- layouts/book.html.erb | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/content/index.html.erb b/content/index.html.erb index 4e21fe4..289156a 100644 --- a/content/index.html.erb +++ b/content/index.html.erb @@ -35,11 +35,8 @@ unless @items["/cover/#{book[:isbn]}.*"].nil? <%= book[:author] %>

- <% book[:rating].times do |star_on| %> - <%= star_svg(filled: true) %> - <% end %> - <% (10 - book[:rating]).times do |star_off| %> - <%= star_svg(filled: false) %> + <% 10.times do |i| %> + <%= star_svg(filled: i < book[:rating]) %> <% end %>

diff --git a/layouts/book.html.erb b/layouts/book.html.erb index 93fb34b..a662452 100644 --- a/layouts/book.html.erb +++ b/layouts/book.html.erb @@ -7,11 +7,8 @@

<%= @item[:author] %>

-<% @item[:rating].times do |star_on| %> -<%= star_svg(filled: true) %> -<% end %> -<% (10 - @item[:rating]).times do |star_off| %> -<%= star_svg(filled: false) %> +<% 10.times do |i| %> +<%= star_svg(filled: i < @item[:rating]) -%> <% end %>