diff --git a/app/controllers/merged/sections_controller.rb b/app/controllers/merged/sections_controller.rb index bc66f30..ea82f97 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -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 diff --git a/app/helpers/merged/view_helper.rb b/app/helpers/merged/view_helper.rb index 873dd27..ff927bb 100644 --- a/app/helpers/merged/view_helper.rb +++ b/app/helpers/merged/view_helper.rb @@ -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 diff --git a/app/models/merged/option.rb b/app/models/merged/option.rb new file mode 100644 index 0000000..d2f97f4 --- /dev/null +++ b/app/models/merged/option.rb @@ -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 diff --git a/app/models/merged/section.rb b/app/models/merged/section.rb index f0d88e2..c4da345 100644 --- a/app/models/merged/section.rb +++ b/app/models/merged/section.rb @@ -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 diff --git a/app/models/merged/style.rb b/app/models/merged/style.rb index 72864a9..f97f7e0 100644 --- a/app/models/merged/style.rb +++ b/app/models/merged/style.rb @@ -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 diff --git a/app/views/merged/sections/_option_form_select.haml b/app/views/merged/sections/_option_form_select.haml new file mode 100644 index 0000000..6e728c7 --- /dev/null +++ b/app/views/merged/sections/_option_form_select.haml @@ -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") diff --git a/app/views/merged/sections/_option_form_text.haml b/app/views/merged/sections/_option_form_text.haml new file mode 100644 index 0000000..d8c8ad3 --- /dev/null +++ b/app/views/merged/sections/_option_form_text.haml @@ -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") diff --git a/app/views/merged/sections/index.html.haml b/app/views/merged/sections/index.html.haml index 41a6821..609e5a8 100644 --- a/app/views/merged/sections/index.html.haml +++ b/app/views/merged/sections/index.html.haml @@ -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) ) diff --git a/app/views/merged/sections/show.html.haml b/app/views/merged/sections/show.html.haml index 6dd5144..994083a 100644 --- a/app/views/merged/sections/show.html.haml +++ b/app/views/merged/sections/show.html.haml @@ -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") diff --git a/app/views/merged/view/_section_full_left2.haml b/app/views/merged/view/_section_full_left2.haml index 2a05300..919f348 100644 --- a/app/views/merged/view/_section_full_left2.haml +++ b/app/views/merged/view/_section_full_left2.haml @@ -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'} diff --git a/app/views/merged/view/elements/_button.haml b/app/views/merged/view/elements/_button.haml index 016b4ae..56f2c0d 100644 --- a/app/views/merged/view/elements/_button.haml +++ b/app/views/merged/view/elements/_button.haml @@ -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) diff --git a/config/styles.yaml b/config/styles.yaml index 4e51a95..fe91341 100644 --- a/config/styles.yaml +++ b/config/styles.yaml @@ -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: