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)
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}"

View File

@ -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?

View File

@ -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)

View File

@ -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