diff --git a/app/assets/images/merged/section_preview/section_text.png b/app/assets/images/merged/section_preview/section_text.png index 88a3d41..1b2bf65 100644 Binary files a/app/assets/images/merged/section_preview/section_text.png and b/app/assets/images/merged/section_preview/section_text.png differ diff --git a/app/helpers/merged/merged_helper.rb b/app/helpers/merged/merged_helper.rb index 6d8b925..3641584 100644 --- a/app/helpers/merged/merged_helper.rb +++ b/app/helpers/merged/merged_helper.rb @@ -12,20 +12,18 @@ module Merged Redcarpet::Markdown.new(html, options) end + def markdown_image(section) + down = self.renderer.render(section.text) + image = image_for(section) + down.gsub("IMAGE" , image).html_safe + end + def markdown(text) text = text.text unless text.is_a?(String) return "" if text.blank? 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/options_helper.rb b/app/helpers/merged/options_helper.rb index 9fe6a0b..52c0f20 100644 --- a/app/helpers/merged/options_helper.rb +++ b/app/helpers/merged/options_helper.rb @@ -87,6 +87,20 @@ module Merged {class: clazz } end + def text_column_option( section) + option = section.option('columns') + option = 2 if option.blank? + case option + when "3" + columns = "columns-1 md:columns-2 lg:columns-3" + when "4" + columns = "columns-1 md:columns-2 lg:columns-3 xl:columns-4" + else # two + columns = "columns-1 md:columns-2" + end + {class: columns } + end + def column_option(section) option = section.option('columns') option = 2 if option.blank? diff --git a/app/views/merged/view/_section_text.haml b/app/views/merged/view/_section_text.haml index 2efc28c..425db92 100644 --- a/app/views/merged/view/_section_text.haml +++ b/app/views/merged/view/_section_text.haml @@ -1,14 +1,12 @@ -.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") +%section.p-20.my-20{ options(section , :background , :color)} + .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 + .prose.max-w-full.mt-4.gap-16{ text_column_option(section)} + = markdown_image(section) diff --git a/config/merged/section_styles.yml b/config/merged/section_styles.yml index eca4506..92e38b5 100644 --- a/config/merged/section_styles.yml +++ b/config/merged/section_styles.yml @@ -28,8 +28,11 @@ - button_link - button_text - template: section_text - header: Text only section for longer passages of text, mostly news - text: Text may be markdown. For longer text culumns should be set. + header: Newspaper style section for longer passages of text. + text: Text may be markdown. The section may have one image than + can be embedded into the text by writing IMAGE (in caps) + where the image should be inserted. Not more than 200 words + or 1000 characters are best. fields: - header - text