From 9bc91be23f74263cdecdb2a550cdf4531b0c8372 Mon Sep 17 00:00:00 2001 From: Neetpone <132411956+Neetpone@users.noreply.github.com> Date: Sat, 13 Apr 2024 18:21:51 -0400 Subject: [PATCH] refactor: create story card partial --- app/views/search/search.html.slim | 50 ++----------------------------- app/views/stories/_card.html.slim | 47 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 47 deletions(-) create mode 100644 app/views/stories/_card.html.slim diff --git a/app/views/search/search.html.slim b/app/views/search/search.html.slim index 11a04f5..21f5cb6 100644 --- a/app/views/search/search.html.slim +++ b/app/views/search/search.html.slim @@ -9,54 +9,10 @@ = render partial: 'advanced', locals: { show_button: true } - @records.each do |rec| - - character_tags = rec.tags.where(type: 'character') - - normal_tags = rec.tags.where.not(type: 'character') section.result - section.fic-cell - header - - if rec.cover_image - = image_tag '/images?url=' + CGI.escape(rec.cover_image), alt: 'Cover Image' - .details - h2= link_to rec.title, story_path(rec) - span.author - ' by - = link_to rec.author.name, author_path(rec.author) - br - span.popular - span.stats - - if rec.short_description - p.description= rec.short_description - - else - div.description - == rec.description_html - footer - .rating - = rating_display(rec.rating) - = status_display(rec.completion_status) - - normal_tags.each do |t| - = tag_to_html(t) - .characters - - character_tags.each do |t| - = character_display(t) - br - .ficstats - span.chapters - = pluralize(rec.chapters.count, 'Chapter') + ',' - '  - span.words - =<> rec.num_words - ' Words:  - span.time_est - ' Estimated - => reading_time(rec.num_words) - | to read - .published - ' Published - span= rec.date_published - .updated - ' Last Update - span= rec.date_updated + = render partial: 'stories/card', locals: { story: rec } + .searchnav = paginate(@records, params: { scope: @scope.scope_key }) br - span.searchtime Found #{@search.total_count} results. \ No newline at end of file + span.searchtime Found #{pluralize(@search.total_count, 'result')}. \ No newline at end of file diff --git a/app/views/stories/_card.html.slim b/app/views/stories/_card.html.slim new file mode 100644 index 0000000..8a6229b --- /dev/null +++ b/app/views/stories/_card.html.slim @@ -0,0 +1,47 @@ +/ A "card" that displays a story in a list +- character_tags = story.tags.where(type: 'character') +- normal_tags = story.tags.where.not(type: 'character') +section.fic-cell + header + - if story.cover_image + = image_tag "/images?url=#{CGI.escape(story.cover_image)}", alt: 'Cover Image' + .details + h2= link_to story.title, story_path(story) + span.author + ' by + = link_to story.author.name, author_path(story.author) + br + span.popular + span.stats + - if story.short_description + p.description= story.short_description + - else + div.description + == story.description_html + footer + .rating + = rating_display(story.rating) + = status_display(story.completion_status) + - normal_tags.each do |t| + = tag_to_html(t) + .characters + - character_tags.each do |t| + = character_display(t) + br + .ficstats + span.chapters + = pluralize(story.chapters.count, 'Chapter') + ',' + '  + span.words + =<> story.num_words + ' Words:  + span.time_est + ' Estimated + => reading_time(story.num_words) + | to read + .published + ' Published + span= story.date_published + .updated + ' Last Update + span= story.date_updated \ No newline at end of file