different templates depending on story text length

This commit is contained in:
Torsten 2023-01-11 21:14:36 +02:00
parent 0055de6c83
commit efa95e82c7
7 changed files with 42 additions and 4 deletions

View File

@ -2,6 +2,16 @@ require "redcarpet"
module ApplicationHelper
# different template according to the amount of text
def render_story(story)
return "" unless story
text_length = story.text.length
template = "text"
template = "half" if text_length < 200
template = "pic" if text_length < 100
render partial: "stories/#{template}" , locals: {story: story}
end
def prose_classes
classes = "prose lg:prose-lg "
classes += "prose-headings:text-inherit "

View File

@ -32,4 +32,8 @@
Sign out
- @member.stories.each do |story|
=render "stories/inline" , story: story
=render_story( story )
.flex.justify-around
= link_to edit_story_path(story) do
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
Edit Story

View File

@ -7,6 +7,6 @@
= story.header
%h4.text-xl.mt-10.md:text-2xl
= distance_of_time_in_words_to_now story.happened
ago
ago half
.mt-8{ prose_classes }
= markdown(story.text)

View File

@ -0,0 +1,13 @@
%section.flex.justify-center.p-8.flex-col.md:flex-row.m-20
.flex.items-center.h-40.md:h-60.lg:h-96.w-full.overflow-hidden{class: "lg:w-2/3"}
= image_for(story ,"object-cover")
.flex.items-center.w-full.max-w.px-6.mt-6.mx-auto{:class => "lg:w-1/3"}
.flex-1
.text-center
%h2.text-4xl.font-bold.text-center.mb-4.lg:mb-8
= story.header
%h4.text-xl.mt-4.lg:mt-8.md:text-2xl
= distance_of_time_in_words_to_now story.happened
ago pic
.mt-3{ prose_classes }
= markdown(story.text)

View File

@ -0,0 +1,11 @@
%section.p-20.my-20
.flex.justify-center
.max-w-prose.text-center
%h1.mb-10.text-2xl.font-bold.tracking-tight.sm:text-4xl
= story.header
.text-xl.pb-6{ prose_classes }
= distance_of_time_in_words_to_now story.happened
ago
.max-w-full.mt-4.gap-16.columns-1.md:columns-2.lg:columns-3.xl:columns-4{ prose_classes }
= image_for( story , "h-56 w-full object-cover sm:h-full")
= markdown(story.text)

View File

@ -1,6 +1,6 @@
= paginate @stories
- @stories.each do |story|
= render "inline" , story: story
= render_story(story)
%br

View File

@ -1,4 +1,4 @@
= render "inline" , story: @story
= render_story @story
= link_to 'Edit', edit_story_path(@story)
\|