merged/app/helpers/merged/options_helper.rb

113 lines
3.1 KiB
Ruby
Raw Normal View History

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
def order_option(section , clazz = "")
if section.has_option?("order")
2023-01-29 16:35:45 +02:00
clazz += " order-last" if section.option('order') == "right"
end
{class: clazz}
2022-12-06 14:33:38 +02:00
end
def text_align_option(section , clazz = "")
if section.has_option?("text_align")
2022-12-07 14:14:50 +02:00
# text-center , text-left , text-right , leave comment for tailwind
2023-01-29 16:35:45 +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
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')
2023-01-29 16:35:45 +02:00
clazz += " " + (Merged.background[section.option('background')] || "")
2022-12-07 14:14:50 +02:00
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 = Merged.margin[section.option("margin")] || ""
2023-01-28 14:37:08 +02:00
{class: clazz + margin}
end
2023-01-19 00:07:52 +02:00
def text_color_option(section , clazz = "")
if section.has_option?("text_color")
2023-01-29 16:35:45 +02:00
clazz += " " + (Merged.text_color[section.option("text_color")] || "")
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")
2023-01-29 16:35:45 +02:00
clazz += " " + (Merged.shade_color[section.option("shade_color")] || "")
2022-12-07 14:14:50 +02:00
end
{class: clazz }
end
2023-01-29 16:53:34 +02:00
def text_columns_option( section , clazz = "")
if section.has_option?("text_columns")
2023-01-29 16:35:45 +02:00
clazz += " " + (Merged.text_columns[section.option("text_columns")] || "")
end
{class: clazz }
end
2023-01-29 16:35:45 +02:00
def column_option( section , clazz = "" )
if section.has_option?("columns")
2023-01-29 16:35:45 +02:00
clazz += " " + (Merged.columns[section.option("columns")] || "")
2022-12-06 14:33:38 +02:00
end
{class: clazz }
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
end
end