more option work

This commit is contained in:
2022-12-06 14:33:38 +02:00
parent 3eeb03a10b
commit eeb0cb13a0
8 changed files with 150 additions and 80 deletions

View File

@ -21,70 +21,5 @@ module Merged
end
end
def order_option(section)
return {} unless section.has_option?("order")
option = section.option('order')
puts "Order #{option}"
return {} if option == "right"
{class: "order-last"}
end
def align_option(section)
return {} unless section.has_option?("align")
option = section.option('align')
puts "align #{option}"
# text-center , text-left , text-right , leave comment for tailwind
{class: "text-#{option}"}
end
def background_option(section)
return {} unless section.has_option?("background")
option = section.option('background')
puts "Background #{option}"
return {} if option == "white"
case option
when "light_blue"
background = "bg-cyan-100"
when "solid_blue"
background = "bg-cyan-700 text-white"
when "solid_red"
background = "bg-orange-800 text-white"
when "solid_green"
background = "bg-green-700 text-white"
when "solid_petrol"
background = "bg-teal-700 text-white"
when "solid_indigo"
background = "bg-indigo-800 text-white"
else
background = "white"
end
{class: background}
end
def column_option(section)
option = section.option('columns')
option = 2 if option.blank?
puts "Columns #{option}"
case option
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"
else # two
columns = "grid-cols-1 md:grid-cols-2"
end
{class: columns }
end
def button(text , url , color)
link_to(url) do
content_tag(:button , class: color + " " + button_classes ) do
text
end
end
end
def button_classes
"ml-3 inline-block rounded-lg px-4 py-3 text-md font-medium text-white"
end
end
end

View File

@ -0,0 +1,91 @@
module Merged
module OptionsHelper
# use options with as many option names as neccessary
def options(section, *args )
all = {}
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
all
end
def order_option(section)
return {} unless section.has_option?("order")
option = section.option('order')
puts "Order #{option}"
return {} if option == "left"
{class: "order-last"}
end
def align_option(section)
return {} unless section.has_option?("align")
option = section.option('align')
puts "align #{option}"
# text-center , text-left , text-right , leave comment for tailwind
{class: "text-#{option}"}
end
def background_option(section)
return {} unless section.has_option?("background")
option = section.option('background')
puts "Background #{option}"
background = bg_for(option)
background += " text-white" if option.include?("solid")
{class: background}
end
def color_option(section)
return {} unless section.has_option?("color")
option = section.option('color')
puts "Text color #{option} , #{color_for(option)}"
{class: color_for(option) }
end
def column_option(section)
option = section.option('columns')
option = 2 if option.blank?
puts "Columns #{option}"
case option
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"
else # two
columns = "grid-cols-1 md:grid-cols-2"
end
{class: columns }
end
private
# need full color names for tailwind to pick it up
def bg_for( option )
{ "white" => "bg-white" ,
"none" => "" ,
"light_blue" => "bg-cyan-100" ,
"light_grey" => "bg-grey-100" ,
"light_orange" => "bg-orange-50" ,
"solid_blue" => "bg-cyan-700" ,
"solid_red" => "bg-orange-800" ,
"solid_green" => "bg-green-700" ,
"solid_petrol" => "bg-teal-700" ,
"solid_indigo" => "bg-indigo-800" ,
"solid_black" => "bg-slate-900" ,
}[option] || ""
end
# need full color names for tailwind to pick it up
def color_for( option )
{ "white" => "text-white",
"none" => "",
"light_blue" => "text-cyan-100" ,
"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" ,
"solid_black" => "text-slate-900" ,
}[option] || ""
end
end
end

View File

@ -1,6 +1,6 @@
module Merged
module ViewHelper
include MergedHelper
include OptionsHelper
# section should be hash with at least 'template' key
def find_template(section)
"merged/view/" + section.template
@ -25,5 +25,16 @@ module Merged
image_tag("#{Image.image_root}/#{element.image}" , class: classes)
end
def button(text , url , color)
link_to(url) do
content_tag(:button , class: color + " " + button_classes ) do
text
end
end
end
def button_classes
"ml-3 inline-block rounded-lg px-4 py-3 text-md font-medium text-white"
end
end
end