splitting styles files and classes

This commit is contained in:
2022-12-08 16:16:28 +02:00
parent c83558f8d5
commit 6b08246c2c
13 changed files with 303 additions and 113 deletions

View File

@ -0,0 +1,42 @@
module Merged
class CardStyle
@@cards = {}
attr_reader :content
def initialize content
@content = content
end
[:template , :text , :header, :fields ].each do |meth|
define_method(meth) do
@content[meth.to_s]
end
end
def card_preview
"merged/card_preview/" + template
end
def options
option_defs = []
@content["options"].each do |name|
option = Option.options[name]
raise "no option for #{name}:#{name.class}" if option.blank?
option_defs << option
end if @content["options"]
option_defs
end
def self.cards
@@cards
end
def self.load( yaml )
yaml.each do |content|
card = CardStyle.new(content)
@@cards[card.template] = card
end
end
end
end

View File

@ -8,9 +8,11 @@ module Merged
@default = options["default"]
@description = options["description"]
@values = options["values"]
@type = options["type"]
end
def type
return @type unless @type.blank?
if has_values?
"select"
else
@ -27,5 +29,13 @@ module Merged
return [] unless has_values?
@values.split(" ")
end
def self.load(yaml)
yaml.each do |content|
option = Option.new(content)
@@options[option.name] = option
end
end
end
end

View File

@ -111,8 +111,8 @@ module Merged
end
def save
file_name = Rails.root.join(Page.cms_root , name + ".yaml")
File.write( file_name , @content.to_yaml)
File.write( filename , @content.to_yaml)
update_size
end
def self.find(name)

View File

@ -35,7 +35,7 @@ module Merged
def set_template(new_template)
@content["template"] = new_template
new_style = template_style
if(new_style.cards?)
if(new_style.has_cards?)
unless card_template
@content["card_template"] = Style.cards.keys.first
@content["cards"] = []
@ -56,7 +56,7 @@ module Merged
template_style.fields
end
def cards?
def has_cards?
! card_template.blank?
end
@ -151,7 +151,7 @@ module Merged
style.fields.each do |key|
data[key] = key.upcase
end unless style.fields.blank?
if(style.cards?)
if(style.has_cards?)
data["cards"] = []
data["card_template"] = Style.cards.keys.first
end

View File

@ -0,0 +1,26 @@
module Merged
class SectionStyle < CardStyle
@@sections = {}
def has_cards?
@content["cards"] == true
end
def section_preview
"merged/section_preview/" + template
end
def self.sections
@@sections
end
def self.load(yaml)
yaml.each do |content|
section = SectionStyle.new(content)
@@sections[section.template] = section
end
end
end
end

View File

@ -1,75 +0,0 @@
module Merged
class Style
include ActiveModel::API
@@options ={}
@@sections = {}
@@cards = {}
attr_reader :content
def initialize content
@content = content
end
[:template , :text , :header, :fields ].each do |meth|
define_method(meth) do
@content[meth.to_s]
end
end
def cards?
@content["cards"] == true
end
def section_preview
"merged/section_preview/" + template
end
def card_preview
"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 if @content["options"]
option_defs
end
def self.cards
self.load
@@cards
end
def self.options
self.load
@@options
end
def self.sections
self.load
@@sections
end
def self.load
if @@sections.length == 0 or Rails.env.development?
all = YAML.load_file(Engine.root.join("config/styles.yaml"))
all["sections"].each do |content|
section = Style.new(content)
@@sections[section.template] = section
end
all["cards"].each do |content|
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
end
end