adding new section

This commit is contained in:
2022-12-02 18:29:17 +02:00
parent ffbdccb263
commit 2eaa344ed0
7 changed files with 51 additions and 12 deletions

View File

@ -34,6 +34,15 @@ module Merged
@@all[@name] = self
end
def new_section
section_data = Section.build_data
index = sections.length
section = Section.new(self , index, section_data)
@sections << section
@content << section_data
section
end
def first_template
@content[0]["template"]
end
@ -41,16 +50,16 @@ module Merged
def move_section_up(section)
return if sections.length == 1
return if section.index == 0
swap( section , sections[section.index - 1])
swap_sections( section , sections[section.index - 1])
end
def move_section_down(section)
return if sections.length == 1
return if section.index == sections.last.index
swap( section , sections[section.index + 1])
swap_sections( section , sections[section.index + 1])
end
def swap( this_section , that_section)
def swap_sections( this_section , that_section)
# swap in the actual objects, index is cached in the objects
this_old_index = this_section.index
this_section.set_index( that_section.index )

View File

@ -25,6 +25,12 @@ module Merged
end
end
def self.build_data
data = { "template" => "spacer"}
data["id"] = SecureRandom.hex(10)
data
end
[:template , :card_template , :id , :text , :header, :image].each do |meth|
define_method(meth) do
@content[meth.to_s]
@ -50,6 +56,13 @@ module Merged
options[option] = value
end
def template_style
Style.sections[ template ]
end
def allowed_fields
template_style.fields
end
def cards?
! cards.empty?
end
@ -89,8 +102,8 @@ module Merged
end
def update(key , value)
return if key == "id" #not updating that
if(! @content[key].nil? )
raise "unsuported field #{key} for #{template}" unless allowed_fields.include?(key)
if(! @content[key].nil? ) # first setting ok, types not (yet?) specified
if( @content[key].class != value.class )
raise "Type mismatch #{key} #{key.class}!=#{value.class}"
end