From a8f5229935e22f5aa8092647ec8c610477bdaa98 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 10 Jan 2023 21:13:09 +0200 Subject: [PATCH] improve section and preview rendering --- app/helpers/merged/merged_helper.rb | 4 ---- app/helpers/merged/view_helper.rb | 5 +++++ app/views/merged/cards/index.haml | 3 +-- app/views/merged/sections/show.haml | 3 +-- app/views/merged/view/_section_news.haml | 3 +-- app/views/merged/view/page.haml | 3 +-- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/helpers/merged/merged_helper.rb b/app/helpers/merged/merged_helper.rb index 6716e5e..ae6a2e1 100644 --- a/app/helpers/merged/merged_helper.rb +++ b/app/helpers/merged/merged_helper.rb @@ -97,10 +97,6 @@ module Merged def button_classes "mr-3 inline-block rounded-lg px-3 py-2 text-md font-medium border border-gray-500" end - # section should be hash with at least 'template' key - def find_template(section) - "merged/view/" + section.template - end end end diff --git a/app/helpers/merged/view_helper.rb b/app/helpers/merged/view_helper.rb index 0c0b98a..4bebf9a 100644 --- a/app/helpers/merged/view_helper.rb +++ b/app/helpers/merged/view_helper.rb @@ -3,6 +3,11 @@ module Merged include MergedHelper include PagesHelper + def render_section(section) + template = "merged/view/" + section.template + render( template , section: section) + end + def rows( text ) return 5 if text.blank? text = text.text unless text.is_a?(String) diff --git a/app/views/merged/cards/index.haml b/app/views/merged/cards/index.haml index 9715c40..c936153 100644 --- a/app/views/merged/cards/index.haml +++ b/app/views/merged/cards/index.haml @@ -5,8 +5,7 @@ = link_to @section.header , merged.section_path( @section.id) , class: "underline" = link_to( "New Card" , merged.new_section_card_path(@section.id) , class: "p-2 border border-gray-200 bg-cyan-100 font-bold rounded-lg hover:bg-sky-100") -- template = find_template(@section) -= render( template , section: @section) += render_section( @section ) - @section.cards.each_with_index do |card , index| .flex.gap-10.px-20.pt-4.pb-2.mb-2.border.border-2.bg-neutral-50.border-slate-400{ id: "card_#{card.id}"} diff --git a/app/views/merged/sections/show.haml b/app/views/merged/sections/show.haml index 886beaf..07c79b4 100644 --- a/app/views/merged/sections/show.haml +++ b/app/views/merged/sections/show.haml @@ -2,8 +2,7 @@ = render "sections_pagination" , section: @section = link_to( "New Section" , merged.new_page_section_path(@section.page.id) , class: button_classes + " bg-cyan-100") -- template = find_template(@section) -= render( template , section: @section) += render_section( @section ) .flex.gap-8.my-10.flex-wrap.mx-20 .basis-80 diff --git a/app/views/merged/view/_section_news.haml b/app/views/merged/view/_section_news.haml index 67244c3..badd5ca 100644 --- a/app/views/merged/view/_section_news.haml +++ b/app/views/merged/view/_section_news.haml @@ -7,8 +7,7 @@ = distance_of_time_in_words_to_now last_blog.updated_at ago %hr.mt-2.border.border-4.border-gray-600 - - template = find_template(last_blog) - = render( template , section: last_blog) + = render_section( last_blog ) .flex.justify-between.items-center.border-b-8.border-gray-600 .ml-20.mb-2.text-lg = section.text diff --git a/app/views/merged/view/page.haml b/app/views/merged/view/page.haml index 3d47fc4..2a9b793 100644 --- a/app/views/merged/view/page.haml +++ b/app/views/merged/view/page.haml @@ -1,3 +1,2 @@ - @page.sections.each do |section| - - template = find_template(section) - = render( template , section: section) + = render_section( section )