different templates depending on story text length
This commit is contained in:
parent
0055de6c83
commit
efa95e82c7
@ -2,6 +2,16 @@ require "redcarpet"
|
|||||||
|
|
||||||
module ApplicationHelper
|
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
|
def prose_classes
|
||||||
classes = "prose lg:prose-lg "
|
classes = "prose lg:prose-lg "
|
||||||
classes += "prose-headings:text-inherit "
|
classes += "prose-headings:text-inherit "
|
||||||
|
@ -32,4 +32,8 @@
|
|||||||
Sign out
|
Sign out
|
||||||
|
|
||||||
- @member.stories.each do |story|
|
- @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
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
= story.header
|
= story.header
|
||||||
%h4.text-xl.mt-10.md:text-2xl
|
%h4.text-xl.mt-10.md:text-2xl
|
||||||
= distance_of_time_in_words_to_now story.happened
|
= distance_of_time_in_words_to_now story.happened
|
||||||
ago
|
ago half
|
||||||
.mt-8{ prose_classes }
|
.mt-8{ prose_classes }
|
||||||
= markdown(story.text)
|
= markdown(story.text)
|
13
app/views/stories/_pic.haml
Normal file
13
app/views/stories/_pic.haml
Normal 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)
|
11
app/views/stories/_text.haml
Normal file
11
app/views/stories/_text.haml
Normal 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)
|
@ -1,6 +1,6 @@
|
|||||||
= paginate @stories
|
= paginate @stories
|
||||||
- @stories.each do |story|
|
- @stories.each do |story|
|
||||||
= render "inline" , story: story
|
= render_story(story)
|
||||||
|
|
||||||
%br
|
%br
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
= render "inline" , story: @story
|
= render_story @story
|
||||||
|
|
||||||
= link_to 'Edit', edit_story_path(@story)
|
= link_to 'Edit', edit_story_path(@story)
|
||||||
\|
|
\|
|
||||||
|
Loading…
Reference in New Issue
Block a user