2022-12-06 14:33:38 +02:00
|
|
|
module Merged
|
|
|
|
module OptionsHelper
|
|
|
|
|
|
|
|
# use options with as many option names as neccessary
|
|
|
|
def options(section, *args )
|
|
|
|
all = {}
|
2023-01-04 17:12:34 +02:00
|
|
|
extra_class = ""
|
|
|
|
extra_class = args.pop if args.last.is_a?(String)
|
2022-12-06 14:33:38 +02:00
|
|
|
args.each do |option_name|
|
|
|
|
hash = send "#{option_name}_option".to_sym , section
|
|
|
|
all.merge!(hash) { |key, one, two| one.to_s + " " + two.to_s }
|
|
|
|
end
|
2023-01-04 17:12:34 +02:00
|
|
|
all[:class] = all[:class] + " #{extra_class}"
|
2022-12-06 14:33:38 +02:00
|
|
|
all
|
|
|
|
end
|
|
|
|
|
2022-12-28 12:18:42 +02:00
|
|
|
def date_precision(element , date_name)
|
|
|
|
precision = element.option("date_precision")
|
|
|
|
date = element.option(date_name)
|
|
|
|
if( precision == "precise")
|
|
|
|
return date.to_formatted_s(:short) + " " + date.year.to_s
|
|
|
|
end
|
2022-12-28 18:33:46 +02:00
|
|
|
return Date.today if date.blank?
|
2022-12-28 12:18:42 +02:00
|
|
|
if(date.day < 10)
|
|
|
|
attr = "Beginning"
|
|
|
|
elsif date.day < 20
|
|
|
|
attr = "Middle"
|
|
|
|
else
|
|
|
|
attr = "End"
|
|
|
|
end
|
|
|
|
"#{attr} of #{date.strftime('%B')} #{date.year}"
|
|
|
|
end
|
|
|
|
|
2023-01-05 00:11:55 +02:00
|
|
|
# adds prose irrespective of options
|
|
|
|
def prose_option(section)
|
|
|
|
prose_classes
|
|
|
|
end
|
|
|
|
|
2022-12-06 21:23:01 +02:00
|
|
|
def order_option(section , clazz = "")
|
|
|
|
if section.has_option?("order")
|
2023-01-25 01:16:05 +02:00
|
|
|
clazz += " order-last" if section.option('order') == "right"
|
2022-12-06 21:23:01 +02:00
|
|
|
end
|
|
|
|
{class: clazz}
|
2022-12-06 14:33:38 +02:00
|
|
|
end
|
|
|
|
|
2022-12-15 14:25:57 +02:00
|
|
|
def text_align_option(section , clazz = "")
|
2022-12-15 15:19:07 +02:00
|
|
|
if section.has_option?("text_align")
|
2022-12-07 14:14:50 +02:00
|
|
|
# text-center , text-left , text-right , leave comment for tailwind
|
2022-12-15 15:19:07 +02:00
|
|
|
clazz += " text-#{section.option('text_align')}"
|
2022-12-07 14:14:50 +02:00
|
|
|
end
|
|
|
|
{class: clazz}
|
2022-12-06 14:33:38 +02:00
|
|
|
end
|
|
|
|
|
2022-12-15 15:19:07 +02:00
|
|
|
def item_align_option(section , clazz = "")
|
|
|
|
if section.has_option?("item_align")
|
|
|
|
case section.option("item_align")
|
|
|
|
when "left"
|
|
|
|
clazz += " justify-start"
|
|
|
|
when "right"
|
|
|
|
clazz += " justify-end"
|
|
|
|
else
|
|
|
|
clazz += " justify-center"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{class: clazz }
|
|
|
|
end
|
|
|
|
|
2022-12-07 14:14:50 +02:00
|
|
|
def background_option(section , clazz = "")
|
|
|
|
if section.has_option?("background")
|
|
|
|
option = section.option('background')
|
2022-12-07 15:01:36 +02:00
|
|
|
clazz += bg_for(section)
|
2022-12-07 14:14:50 +02:00
|
|
|
clazz += " text-white" if option.include?("solid")
|
|
|
|
end
|
|
|
|
{class: clazz}
|
2022-12-06 14:33:38 +02:00
|
|
|
end
|
|
|
|
|
2022-12-07 14:14:50 +02:00
|
|
|
def margin_option(section , clazz = "")
|
2023-01-28 14:37:08 +02:00
|
|
|
return {class: clazz} unless section.has_option?("margin")
|
|
|
|
margin = { "none" => " m-0" ,
|
|
|
|
"small" => " 2 md:4 lg:6 xl:m-8" ,
|
|
|
|
"medium" => " 5 md:8 lg:10 xl:m-14" ,
|
|
|
|
"large" => " 8 md:12 lg:16 xl:m-20" ,
|
|
|
|
}[section.option("margin")] || ""
|
|
|
|
{class: clazz + margin}
|
2022-12-06 21:23:01 +02:00
|
|
|
end
|
|
|
|
|
2023-01-19 00:07:52 +02:00
|
|
|
def text_color_option(section , clazz = "")
|
|
|
|
if section.has_option?("text_color")
|
2022-12-07 15:01:36 +02:00
|
|
|
clazz += color_for(section)
|
2022-12-07 14:14:50 +02:00
|
|
|
end
|
|
|
|
{class: clazz }
|
2022-12-06 14:33:38 +02:00
|
|
|
end
|
|
|
|
|
2022-12-07 15:01:36 +02:00
|
|
|
def shade_option(section , clazz = "")
|
2022-12-07 14:14:50 +02:00
|
|
|
if section.has_option?("shade_color")
|
2022-12-07 15:01:36 +02:00
|
|
|
clazz += shade_for(section)
|
2022-12-07 14:14:50 +02:00
|
|
|
end
|
|
|
|
{class: clazz }
|
2022-12-06 19:54:17 +02:00
|
|
|
end
|
|
|
|
|
2023-01-04 01:20:48 +02:00
|
|
|
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
|
|
|
|
|
2022-12-06 14:33:38 +02:00
|
|
|
def column_option(section)
|
|
|
|
option = section.option('columns')
|
|
|
|
case option
|
2023-01-05 18:54:13 +02:00
|
|
|
when "1"
|
|
|
|
columns = "grid-cols-1"
|
2022-12-06 14:33:38 +02:00
|
|
|
when "3"
|
|
|
|
columns = "grid-cols-1 md:grid-cols-2 lg:grid-cols-3"
|
|
|
|
when "4"
|
|
|
|
columns = "grid-cols-1 md:grid-cols-2 lg:grid-cols-4"
|
2023-01-05 17:47:50 +02:00
|
|
|
when "5"
|
|
|
|
columns = "grid-cols-1 md:grid-cols-3 lg:grid-cols-5"
|
|
|
|
when "6"
|
|
|
|
columns = "grid-cols-2 md:grid-cols-4 lg:grid-cols-6"
|
2022-12-06 14:33:38 +02:00
|
|
|
else # two
|
|
|
|
columns = "grid-cols-1 md:grid-cols-2"
|
|
|
|
end
|
2023-01-25 01:16:05 +02:00
|
|
|
columns += " gap-8 md:gap-12 lg:gap-16"
|
2022-12-06 14:33:38 +02:00
|
|
|
{class: columns }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
# need full color names for tailwind to pick it up
|
2022-12-07 15:01:36 +02:00
|
|
|
def bg_for( section )
|
2022-12-07 14:14:50 +02:00
|
|
|
{ "white" => " bg-white" ,
|
2022-12-06 14:33:38 +02:00
|
|
|
"none" => "" ,
|
2022-12-07 14:14:50 +02:00
|
|
|
"light_blue" => " bg-cyan-100" ,
|
|
|
|
"light_gray" => " bg-gray-100" ,
|
|
|
|
"light_orange" => " bg-orange-50" ,
|
|
|
|
"solid_blue" => " bg-cyan-700" ,
|
2022-12-23 21:52:02 +02:00
|
|
|
"solid_red" => " bg-amber-600" ,
|
2022-12-07 14:14:50 +02:00
|
|
|
"solid_green" => " bg-green-700" ,
|
|
|
|
"solid_petrol" => " bg-teal-700" ,
|
2022-12-23 21:52:02 +02:00
|
|
|
"solid_indigo" => " bg-cyan-900" ,
|
2022-12-07 14:14:50 +02:00
|
|
|
"solid_black" => " bg-slate-900" ,
|
2022-12-07 15:01:36 +02:00
|
|
|
}[section.option('background')] || ""
|
2022-12-06 14:33:38 +02:00
|
|
|
end
|
2023-01-28 14:37:08 +02:00
|
|
|
|
2022-12-06 14:33:38 +02:00
|
|
|
# need full color names for tailwind to pick it up
|
2022-12-07 15:01:36 +02:00
|
|
|
def color_for( section )
|
2022-12-07 14:14:50 +02:00
|
|
|
{ "white" => " text-white",
|
2022-12-06 14:33:38 +02:00
|
|
|
"none" => "",
|
2022-12-07 14:14:50 +02:00
|
|
|
"light_blue" => " text-cyan-100" ,
|
2022-12-07 15:01:36 +02:00
|
|
|
"light_gray" => " text-gray-100" ,
|
2022-12-07 14:14:50 +02:00
|
|
|
"solid_blue" => " text-cyan-700" ,
|
|
|
|
"solid_red" => " text-orange-800" ,
|
|
|
|
"solid_green" => " text-green-700" ,
|
|
|
|
"solid_petrol" => " text-teal-700" ,
|
|
|
|
"solid_indigo" => " text-indigo-800" ,
|
2022-12-07 15:01:36 +02:00
|
|
|
"solid_black" => " text-slate-800" ,
|
2023-01-19 00:07:52 +02:00
|
|
|
}[section.option("text_color")] || ""
|
2022-12-06 14:33:38 +02:00
|
|
|
end
|
2022-12-06 19:54:17 +02:00
|
|
|
# need full color names for tailwind to pick it up
|
|
|
|
|
2022-12-07 15:01:36 +02:00
|
|
|
def shade_for( section )
|
2022-12-07 14:14:50 +02:00
|
|
|
{ "white_25" => " bg-white/25",
|
2022-12-06 19:54:17 +02:00
|
|
|
"none" => "",
|
2022-12-07 14:14:50 +02:00
|
|
|
"black_25" => " bg-black/25" ,
|
|
|
|
"light_blue_25" => " bg-cyan-100/25" ,
|
|
|
|
"light_red_25" => " bg-orange-300/25" ,
|
|
|
|
"solid_blue_25" => " bg-cyan-700/25" ,
|
|
|
|
"solid_red_25" => " bg-orange-800/25" ,
|
2022-12-07 15:01:36 +02:00
|
|
|
}[section.option("shade_color")] || ""
|
2022-12-06 19:54:17 +02:00
|
|
|
end
|
2022-12-06 14:33:38 +02:00
|
|
|
end
|
|
|
|
end
|