improving the text section, now with one image

This commit is contained in:
Torsten 2023-01-04 01:20:48 +02:00
parent 9bcd43215b
commit 01e424caa8
5 changed files with 36 additions and 23 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 414 KiB

View File

@ -12,20 +12,18 @@ module Merged
Redcarpet::Markdown.new(html, options) Redcarpet::Markdown.new(html, options)
end 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) def markdown(text)
text = text.text unless text.is_a?(String) text = text.text unless text.is_a?(String)
return "" if text.blank? return "" if text.blank?
self.renderer.render(text).html_safe self.renderer.render(text).html_safe
end 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 def aspect_ratio image
x , y = image.aspect_ratio x , y = image.aspect_ratio
"#{x} / #{y}" "#{x} / #{y}"

View File

@ -87,6 +87,20 @@ module Merged
{class: clazz } {class: clazz }
end 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) def column_option(section)
option = section.option('columns') option = section.option('columns')
option = 2 if option.blank? option = 2 if option.blank?

View File

@ -1,5 +1,4 @@
.p-20.my-20{ options(section , :background , :color)} %section.p-20.my-20{ options(section , :background , :color)}
%section
.flex.justify-center .flex.justify-center
.max-w-prose{ options(section , :text_align)} .max-w-prose{ options(section , :text_align)}
- if !section.header.blank? - if !section.header.blank?
@ -9,6 +8,5 @@
%p.prose.text-xl.pb-6 %p.prose.text-xl.pb-6
= section.option("subheader") = section.option("subheader")
.mt-4.grid.gap-16{ column_option(section)} .prose.max-w-full.mt-4.gap-16{ text_column_option(section)}
- split_section(section).each do |part| = markdown_image(section)
.prose.text-justify= part

View File

@ -28,8 +28,11 @@
- button_link - button_link
- button_text - button_text
- template: section_text - template: section_text
header: Text only section for longer passages of text, mostly news header: Newspaper style section for longer passages of text.
text: Text may be markdown. For longer text culumns should be set. 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: fields:
- header - header
- text - text