copy sections (template) and fix cards inclusion

This commit is contained in:
2022-12-03 00:14:19 +02:00
parent 1e452ca62a
commit ecaf0eb587
5 changed files with 38 additions and 12 deletions

View File

@ -34,8 +34,8 @@ module Merged
@@all[@name] = self
end
def new_section
section_template = params[:template] || "section_spacer"
def new_section(section_template)
section_template = "section_spacer" if section_template.blank?
section_data = Section.build_data(section_template)
index = sections.length
section = Section.new(self , index, section_data)

View File

@ -50,6 +50,22 @@ module Merged
options[option] = value
end
def set_template(new_template)
@content["template"] = new_template
new_style = template_style
if(new_style.cards?)
unless card_template
@content["card_template"] = Style.cards.keys.first
@content["cards"] = []
raise "Should not have cards" unless cards.empty?
end
else
@content.delete("cards")
@content.delete("card_template")
@cards.clear
end
end
def template_style
Style.sections[ template ]
end
@ -58,7 +74,7 @@ module Merged
end
def cards?
! cards.empty?
! card_template.blank?
end
def new_card
@ -133,11 +149,15 @@ module Merged
def self.build_data(template)
data = { "template" => template , "id" => SecureRandom.hex(10) }
Style.sections[ template ].fields.each do |key|
style = Style.sections[ template ]
style.fields.each do |key|
data[key] = key.upcase
end unless style.fields.blank?
if(style.cards?)
data["cards"] = []
data["card_template"] = Style.cards.keys.first
end
data
end
def self.find(section_id)

View File

@ -2,7 +2,6 @@ module Merged
class Style
include ActiveModel::API
cattr_accessor :sections , :cards
@@sections = {}
@@cards = {}
@ -29,16 +28,16 @@ module Merged
end
def self.cards
self.all
self.load
@@cards
end
def self.sections
self.all
self.load
@@sections
end
def self.all
def self.load
if @@sections.length == 0
all = YAML.load_file(Engine.root.join("config/styles.yaml"))
all["sections"].each do |content|