implement options, buttons and fixed bg
This commit is contained in:
parent
236d10a768
commit
77a7917869
@ -76,6 +76,10 @@ module Merged
|
||||
puts "updating:#{key}=#{params[key]}"
|
||||
end
|
||||
end
|
||||
options = params[:option]
|
||||
@section.option_definitions.each do |option|
|
||||
@section.set_option(option.name, options[option.name])
|
||||
end
|
||||
@section.save
|
||||
redirect_to :section
|
||||
end
|
||||
|
@ -9,9 +9,14 @@ module Merged
|
||||
# background image as inline style
|
||||
def bg(section)
|
||||
return "" if section.image.blank?
|
||||
puts "--#{Image.image_root}/#{section.image}--"
|
||||
#puts "--#{Image.image_root}/#{section.image}--"
|
||||
img = asset_url( "#{Image.image_root}/#{section.image}" )
|
||||
"background-image: url('#{img}');"
|
||||
style = {"style" => "background-image: url('#{img}');" }
|
||||
if(section.option("fixed") == "on")
|
||||
style[:class] = "bg-fixed"
|
||||
puts "Adding fixed"
|
||||
end
|
||||
style
|
||||
end
|
||||
|
||||
# works for with sections and cards that respond to .image
|
||||
|
31
app/models/merged/option.rb
Normal file
31
app/models/merged/option.rb
Normal file
@ -0,0 +1,31 @@
|
||||
module Merged
|
||||
class Option
|
||||
|
||||
attr_reader :name , :default , :description
|
||||
|
||||
def initialize(options)
|
||||
@name = options["name"]
|
||||
@default = options["default"]
|
||||
@description = options["description"]
|
||||
@values = options["values"]
|
||||
end
|
||||
|
||||
def type
|
||||
if has_values?
|
||||
"select"
|
||||
else
|
||||
"text"
|
||||
end
|
||||
end
|
||||
|
||||
def has_values?
|
||||
return false if @values.nil?
|
||||
! @values.empty?
|
||||
end
|
||||
|
||||
def values
|
||||
return [] unless has_values?
|
||||
@values.split(" ")
|
||||
end
|
||||
end
|
||||
end
|
@ -9,7 +9,6 @@ module Merged
|
||||
|
||||
attr_reader :name , :content , :page , :index , :cards
|
||||
|
||||
|
||||
def initialize(page , index , section_data)
|
||||
@page = page
|
||||
raise "No number #{index}" unless index.is_a?(Integer)
|
||||
@ -25,7 +24,7 @@ module Merged
|
||||
end
|
||||
end
|
||||
|
||||
[:template , :card_template , :id , :text , :header, :image].each do |meth|
|
||||
[:template , :card_template , :id , :text , :header, :image, :options].each do |meth|
|
||||
define_method(meth) do
|
||||
@content[meth.to_s]
|
||||
end
|
||||
@ -41,11 +40,20 @@ module Merged
|
||||
options.has_key?(option)
|
||||
end
|
||||
|
||||
def option_definitions
|
||||
template_style.options
|
||||
end
|
||||
|
||||
def option(name)
|
||||
options[name]
|
||||
end
|
||||
|
||||
def options
|
||||
@content["options"] || {}
|
||||
end
|
||||
|
||||
def set_option( option , value)
|
||||
puts "#{template} setting option #{option}=#{value.class}"
|
||||
@content["options"] = {} if @content["options"].nil?
|
||||
options[option] = value
|
||||
end
|
||||
|
@ -2,6 +2,7 @@ module Merged
|
||||
class Style
|
||||
include ActiveModel::API
|
||||
|
||||
@@options ={}
|
||||
@@sections = {}
|
||||
@@cards = {}
|
||||
|
||||
@ -11,7 +12,7 @@ module Merged
|
||||
@content = content
|
||||
end
|
||||
|
||||
[:template , :text , :header, :fields].each do |meth|
|
||||
[:template , :text , :header, :fields ].each do |meth|
|
||||
define_method(meth) do
|
||||
@content[meth.to_s]
|
||||
end
|
||||
@ -27,11 +28,26 @@ module Merged
|
||||
"merged/card_preview/" + template
|
||||
end
|
||||
|
||||
def options
|
||||
option_defs = []
|
||||
@content["options"].each do |name|
|
||||
option = Style.options[name]
|
||||
raise "no option for #{name}:name.class" if option.blank?
|
||||
option_defs << option
|
||||
end
|
||||
option_defs
|
||||
end
|
||||
|
||||
def self.cards
|
||||
self.load
|
||||
@@cards
|
||||
end
|
||||
|
||||
def self.options
|
||||
self.load
|
||||
@@options
|
||||
end
|
||||
|
||||
def self.sections
|
||||
self.load
|
||||
@@sections
|
||||
@ -48,6 +64,10 @@ module Merged
|
||||
card = Style.new(content)
|
||||
@@cards[card.template] = card
|
||||
end
|
||||
all["options"].each do |content|
|
||||
option = Option.new(content)
|
||||
@@options[option.name] = option
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
4
app/views/merged/sections/_option_form_select.haml
Normal file
4
app/views/merged/sections/_option_form_select.haml
Normal file
@ -0,0 +1,4 @@
|
||||
%label.block
|
||||
%h4.text-lg.font-bold
|
||||
= option.name.capitalize
|
||||
= select_tag( "option[#{option.name}]" , options_for_select(option.values, section.option(option.name)), class: "w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm")
|
4
app/views/merged/sections/_option_form_text.haml
Normal file
4
app/views/merged/sections/_option_form_text.haml
Normal file
@ -0,0 +1,4 @@
|
||||
%label.block
|
||||
%h4.text-lg.font-bold
|
||||
= option.name
|
||||
= text_field_tag( "option[#{option.name}]" , section.option(option.name), class: "w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm")
|
@ -37,6 +37,9 @@
|
||||
%p No image
|
||||
.relative.block.border.border-gray-100.p-4
|
||||
%h3.mt-4.text-lg.font-bold Options
|
||||
%p To be done
|
||||
- section.options.each do|name , value|
|
||||
%p
|
||||
= name
|
||||
= value
|
||||
%p
|
||||
= green_button( "New Section" , new_page_section_url(@page.name) )
|
||||
|
@ -56,4 +56,7 @@
|
||||
|
||||
.relative.block.border.border-gray-100
|
||||
%h3.mt-4.text-lg.font-bold Options
|
||||
To be done
|
||||
= section_form( class: "mx-auto mt-8 mb-0 max-w space-y-4") do
|
||||
- @section.option_definitions.each do |option|
|
||||
=render "option_form_#{option.type}" , section: @section , option: option
|
||||
= submit_button("Update")
|
||||
|
@ -1,4 +1,4 @@
|
||||
%section.overflow-hidden.bg-cover.bg-center.bg-no-repeat{style: bg(section)}
|
||||
%section.overflow-hidden.bg-cover.bg-center.bg-no-repeat{bg(section)}
|
||||
.mx-auto.max-w-screen-2xl.px-4.py-8.sm:px-6.lg:px-8
|
||||
.grid.grid-cols-1.gap-4.md:grid-cols-2
|
||||
.p-8.md:p-12.lg:px-16.lg:py-24{class: 'bg-black/25'}
|
||||
|
@ -1 +1,2 @@
|
||||
= blue_button( section.button_text , section.button_link)
|
||||
- unless section.button_text.blank? or section.button_link.blank?
|
||||
= blue_button( section.button_text , section.button_link)
|
||||
|
@ -17,6 +17,12 @@ sections:
|
||||
- template: section_half_right
|
||||
header: Split section image right
|
||||
text: Image right, header and text on the left. Optional button.
|
||||
fields:
|
||||
- header
|
||||
- text
|
||||
options:
|
||||
- button_link
|
||||
- button_text
|
||||
- template: section_full_left2
|
||||
header: Full image header, text left
|
||||
text: Large picture background with Header and text towards the left.
|
||||
@ -24,6 +30,8 @@ sections:
|
||||
fields:
|
||||
- header
|
||||
- text
|
||||
options:
|
||||
- fixed
|
||||
- template: section_half_left
|
||||
header: Split section image left
|
||||
text: Image left, header and text on the right. Optional button.
|
||||
@ -41,3 +49,21 @@ cards:
|
||||
fields:
|
||||
- header
|
||||
- text
|
||||
options:
|
||||
- name: fixed
|
||||
desciption:
|
||||
Paralax effect where background stays fixed
|
||||
during scrolling
|
||||
values: on off
|
||||
default: off
|
||||
- name: button_text
|
||||
desciption:
|
||||
Text for an optional button. Must also set button_link
|
||||
values:
|
||||
default:
|
||||
- name: button_link
|
||||
desciption:
|
||||
Link for an option button. Must also set button_text.
|
||||
Link must be a page name, ie only internal links allowed.
|
||||
values:
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user