fixes from option change

This commit is contained in:
Torsten 2022-12-10 19:22:44 +02:00
parent 2abdf7add1
commit d936fc05ab
12 changed files with 117 additions and 124 deletions

View File

@ -2,6 +2,7 @@ require "redcarpet"
module Merged module Merged
module MergedHelper module MergedHelper
include OptionsHelper
@@renderer = nil @@renderer = nil
def renderer def renderer

View File

@ -1,6 +1,7 @@
module Merged module Merged
module SectionsHelper module SectionsHelper
include ViewHelper #for previews
def section_form(options) def section_form(options)
url = section_url( @section.id) url = section_url( @section.id)
form_tag( url , {method: :patch}) do form_tag( url , {method: :patch}) do

View File

@ -54,6 +54,11 @@ module Merged
def save def save
section.save section.save
end end
def save_soon
super
data = Option.all.collect {|obj| obj.attributes}
File.write( Option.full_path , data.to_yaml)
end
def set_index(index) def set_index(index)
@index = index @index = index

View File

@ -21,7 +21,7 @@ module Merged
def options def options
option_defs = [] option_defs = []
@content["options"].each do |name| @content["options"].each do |name|
option = Option.options[name] option = Option.find_by_name(name)
raise "no option for #{name}:#{name.class}" if option.blank? raise "no option for #{name}:#{name.class}" if option.blank?
option_defs << option option_defs << option
end if @content["options"] end if @content["options"]

View File

@ -1,20 +1,11 @@
module Merged module Merged
class Option < ActiveYaml::Base class Option < ActiveYaml::Base
set_root_path Engine.root + "config"
@@options = {}
fields :name , :default , :description , :values , :type fields :name , :default , :description , :values , :type
def initialize_old(options)
@name = options["name"]
@default = options["default"]
@description = options["description"]
@values = options["values"]
@type = options["type"]
end
def type def type
return @type unless @type.blank? return attributes[:type] unless attributes[:type].blank?
if has_values? if has_values?
"select" "select"
else else
@ -23,24 +14,17 @@ module Merged
end end
def has_values? def has_values?
return false if @values.nil? return false if attributes[:values].nil?
! @values.empty? ! attributes[:values].empty?
end end
def values def values
return [] unless has_values? return [] unless has_values?
@values.split(" ") attributes[:values].split(" ")
end end
def self.options def self.load()
@@options self.all
end
def self.load(yaml)
yaml.each do |content|
option = Option.new(content)
@@options[option.name] = option
end
end end
end end

View File

@ -1 +0,0 @@
ActiveFile::Base.set_root_path "config"

View File

@ -1,90 +1,89 @@
--- ---
- name: fixed - :name: fixed
description: :description: Paralax effect where background stays fixed during scrolling
Paralax effect where background stays fixed :values: on off
during scrolling :default: false
values: on off :id: 1
default: off - :name: columns
- name: columns :description: Number of columns in a layout that supports cards
description: :values: 2 3 4
Number of columns in a layout that supports cards :default: 3
values: 2 3 4 :id: 2
default: 3 - :name: background
- name: background :description: Background colors. Light colors stay with black text. Solid colors
description: invert to white text.
Background colors. Light colors stay with black text. :values: white none light_blue light_gray light_orange solid_blue solid_red solid_indigo
Solid colors invert to white text. :default: none
values: white none light_blue light_gray light_orange solid_blue solid_red solid_indigo :id: 3
default: none - :name: color
- name: color :description: Text colors. Don't use with solid background colors. Same colors as
description: background available. Default none, meas as parent.
Text colors. Don't use with solid background colors. :values: none white black light_blue light_gray solid_black solid_blue solid_red
Same colors as background available. Default none, meas as parent. solid_indigo
values: none white black light_blue light_gray solid_black solid_blue solid_red solid_indigo :default: none
default: none :id: 4
- name: shade_color - :name: shade_color
description: :description: Color of transparent shaded area. The number means transparency.
Color of transparent shaded area. :values: none black_25 white_25 light_red_25 light_blue_25 solid_blue_25 solid_red_25
The number means transparency. :default: none
values: none black_25 white_25 light_red_25 light_blue_25 solid_blue_25 solid_red_25 :id: 5
default: none - :name: align
- name: align :description: Align text of children. Normal Word meaning
description: :values: left center right
Align text of children. Normal Word meaning :default: left
values: left center right :id: 6
default: left - :name: order
- name: order :description: For two column layout determine order of sub-cards Values of left
description: and right usually refer to where the image is For cards it can also mean up and
For two column layout determine order of sub-cards down
Values of left and right usually refer to where the image is :values: left right
For cards it can also mean up and down :default: left
values: left right :id: 7
default: left - :name: margin
- name: margin :description: Most sections have standard margin of 20. This option makes it possible
description: to remove that
Most sections have standard margin of 20. :values: 0 20
This option makes it possible to remove that :default: 20
values: 0 20 :id: 8
default: 20 - :name: button_text
- name: button_text :description: Text for an optional button. Must also set button_link
description: :values:
Text for an optional button. Must also set button_link :default:
values: :id: 9
default: - :name: subheader
- name: subheader :description: Smaller header between Header and text
description: :values:
Smaller header between Header and text :default:
values: :id: 10
default: - :name: text
- name: text :description: Second text. Just a second paragraph
description: :values:
Second text. Just a second paragraph :default:
values: :id: 11
default: - :name: button_link
- name: button_link :description: Link for an option button. Must also set button_text. Link must be
description: a page name, ie only internal links allowed.
Link for an option button. Must also set button_text. :values:
Link must be a page name, ie only internal links allowed. :default:
values: :id: 12
default: - :name: compulsory
- name: compulsory :description: Form fields may be compulsory or not. By default they are.
description: :values: yes no
Form fields may be compulsory or not. By default they are. :default: false
values: yes no :id: 13
default: no - :name: form_type
- name: form_type :description: Form fields may have a type for special handling. The default is text
description:
Form fields may have a type for special handling. The default is text
but message would be a longer text, and email checked to be a name. but message would be a longer text, and email checked to be a name.
values: text message email phone date :values: text message email phone date
default: text :default: text
- name: ok_message :id: 14
description: - :name: ok_message
Message shown to the user when a form was submitted :description: Message shown to the user when a form was submitted
values: :values:
default: :default:
- name: handler :id: 15
description: - :name: handler
Form handler :description: Form handler
values: FormHandler :values: FormHandler
default: FormHandler :default: FormHandler
:id: 16

View File

@ -4,10 +4,11 @@ require "merged/engine"
module Merged module Merged
def self.load_data def self.load_data
["card_style" , "section_style" , "option"].each do |kind| ["card_style" , "section_style"].each do |kind|
# loading egine definitions first, can be overriden # loading egine definitions first, can be overriden
load_from kind , Engine.root.join("config/merged/#{kind}.yaml") load_from kind , Engine.root.join("config/merged/#{kind}.yaml")
end end
Option.load
Page.load_pages Page.load_pages
Image.load_images Image.load_images
end end

View File

@ -3,9 +3,9 @@ require 'rails_helper'
RSpec.feature "Changes", type: :feature do RSpec.feature "Changes", type: :feature do
describe "GET /changes" do describe "GET /changes" do
it "returns http success" do it "returns http success" do
visit "/merged/changes" visit "/merged/changes/index"
expect(page).to have_title("Merged") expect(page).to have_title("Deletions")
expect(page).to have_text("Pages") expect(page).to have_text("Additions")
end end
end end
end end

View File

@ -6,7 +6,7 @@ module Merged
it "has Style.cards" do it "has Style.cards" do
expect(CardStyle.cards.class).to be Hash expect(CardStyle.cards.class).to be Hash
expect(CardStyle.cards.length).to be 4 expect(CardStyle.cards.length).to be 5
end end
end end

View File

@ -2,16 +2,19 @@ require 'rails_helper'
module Merged module Merged
RSpec.describe Option, type: :model do RSpec.describe Option, type: :model do
let(:first) {Option.options.values.first} let(:first) {Option.first}
it "has Option.options" do it "has Option.first" do
expect(Option.options.class).to be Hash expect(Option.first.class).to be Option
end end
it "there are options" do it "there are options" do
expect(Option.options.length).to be 16 expect(Option.all.length).to be 16
end end
it "has option objects" do it "has option objects" do
expect(first.class).to be Option expect(first.class).to be Option
end end
it "has values" do
expect(first.values.class).to be Array
end
end end
end end

View File

@ -6,7 +6,7 @@ module Merged
it "has Style.sections" do it "has Style.sections" do
expect(SectionStyle.sections.class).to be Hash expect(SectionStyle.sections.class).to be Hash
expect(SectionStyle.sections.length).to be 6 expect(SectionStyle.sections.length).to be 7
end end
it "Finds section by template" do it "Finds section by template" do
spacer = SectionStyle.sections["section_spacer"] spacer = SectionStyle.sections["section_spacer"]