From 137a768a6dfbf38234e88460038cbb1d76afc9a6 Mon Sep 17 00:00:00 2001 From: Torsten Date: Thu, 29 Dec 2022 13:47:42 +0200 Subject: [PATCH] make test sectio multi column --- app/helpers/merged/merged_helper.rb | 8 ++++++++ app/helpers/merged/view_helper.rb | 8 ++++++++ app/models/merged/page.rb | 4 ++-- app/views/merged/sections/show.haml | 2 +- app/views/merged/view/_section_cards.haml | 2 +- app/views/merged/view/_section_text.haml | 23 ++++++++++++++--------- config/merged/section_styles.yml | 4 ++-- 7 files changed, 36 insertions(+), 15 deletions(-) diff --git a/app/helpers/merged/merged_helper.rb b/app/helpers/merged/merged_helper.rb index 3797ee6..6d8b925 100644 --- a/app/helpers/merged/merged_helper.rb +++ b/app/helpers/merged/merged_helper.rb @@ -18,6 +18,14 @@ module Merged self.renderer.render(text).html_safe end + def split_section(section) + return [""] if section.text.blank? + words = self.renderer.render(section.text).split + bins = (words.length + 3) / section.option("columns").to_i + parts = words.each_slice(bins).to_a + parts.collect{|part| part.join(" ").html_safe} + end + def aspect_ratio image x , y = image.aspect_ratio "#{x} / #{y}" diff --git a/app/helpers/merged/view_helper.rb b/app/helpers/merged/view_helper.rb index c89fd60..9e443c5 100644 --- a/app/helpers/merged/view_helper.rb +++ b/app/helpers/merged/view_helper.rb @@ -2,6 +2,14 @@ module Merged module ViewHelper include MergedHelper + def rows( text ) + return 5 if text.blank? + text = text.text unless text.is_a?(String) + rows = (text.length / 60).to_i + return 5 if rows < 5 + rows + end + # background image as inline style def bg(section , clazz = "") attributes = {class: clazz} diff --git a/app/models/merged/page.rb b/app/models/merged/page.rb index 558cac8..faae3d9 100644 --- a/app/models/merged/page.rb +++ b/app/models/merged/page.rb @@ -1,9 +1,9 @@ module Merged class Page < ViewBase - fields :name , :type , :options, :redirects + fields :name , :type , :options, :redirects , :section_template - alias :template :type + alias :template :section_template def change_name self.name diff --git a/app/views/merged/sections/show.haml b/app/views/merged/sections/show.haml index 9b4f3a0..5717f03 100644 --- a/app/views/merged/sections/show.haml +++ b/app/views/merged/sections/show.haml @@ -35,7 +35,7 @@ = text_field_tag( :header , @section.header, class: "w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm") %label.block %h4.mt-4.text-lg.font-bold Text - = text_area_tag( :text , @section.text, rows: 5 ,class: "w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm") + = text_area_tag( :text , @section.text, rows: rows(@section) ,class: "w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm") .mt-4= submit_button("Update") - if( @section.has_cards? ) diff --git a/app/views/merged/view/_section_cards.haml b/app/views/merged/view/_section_cards.haml index 4ab3ef6..cf2a372 100644 --- a/app/views/merged/view/_section_cards.haml +++ b/app/views/merged/view/_section_cards.haml @@ -1,5 +1,5 @@ %section.m-20{ options(section , :background , :color)} - .flex{ item_align_option( section)} + .flex.text-center .max-w-prose.px-4.py-16{ options(section , :text_align)} %h1.text-2xl.font-bold.tracking-tight.sm:text-4xl = section.header diff --git a/app/views/merged/view/_section_text.haml b/app/views/merged/view/_section_text.haml index 9406511..2efc28c 100644 --- a/app/views/merged/view/_section_text.haml +++ b/app/views/merged/view/_section_text.haml @@ -1,9 +1,14 @@ -%section{ options(section , :background , :margin)} - .px-4.py-16.mx-20{options(section , :text_align , :color)} - %h1.text-2xl.font-bold.tracking-tight.sm:text-4xl - = section.header - -if section.has_option?("subheader") - %h4.text-xl.mt-10.md:text-2xl - = section.option("subheader") - .prose.mt-4.text-lg.pt-10 - = markdown(section) +.p-20.my-20{ options(section , :background , :color)} + %section + .flex.justify-center + .max-w-prose{ options(section , :text_align)} + - if !section.header.blank? + %h1.mb-10.text-2xl.font-bold.tracking-tight.sm:text-4xl + = section.header + -if section.has_option?("subheader") + %p.prose.text-xl.pb-6 + = section.option("subheader") + + .mt-4.grid.gap-16{ column_option(section)} + - split_section(section).each do |part| + .prose.text-justify= part diff --git a/config/merged/section_styles.yml b/config/merged/section_styles.yml index be9d534..7bc04cc 100644 --- a/config/merged/section_styles.yml +++ b/config/merged/section_styles.yml @@ -30,16 +30,16 @@ - button_text - template: section_text header: Text only section for longer passages of text, mostly news - text: Text may be markdown + text: Text may be markdown. For longer text culumns should be set. fields: - header - text options: + - columns - background - color - margin - subheader - - text_align - template: section_half_image header: Split section with image left or right text: Image on one side, header and text on the other.