polish base class

This commit is contained in:
Torsten 2022-12-15 13:09:59 +02:00
parent bd22c1fd95
commit 67dc8a07c3
4 changed files with 18 additions and 18 deletions

View File

@ -5,7 +5,7 @@ module Merged
belongs_to :section , class_name: "Merged::Section"
fields :id , :index , :section_id
fields :text , :header, :image , :options
fields :text , :header, :image
def move_up
swap_index_with(next_card)
@ -23,12 +23,14 @@ module Merged
section.cards.where(index: index + 1).first
end
def set_index(index)
@index = index
# card templates are stored in the section so the all cards
# have the same
def template
section.card_template
end
def template_style
CardStyle.find_by_template( section.card_template)
CardStyle.find_by_template( self.template )
end
def destroy

View File

@ -1,12 +1,8 @@
module Merged
class Page < ViewBase
# could be config options
def self.cms_root
"cms"
end
fields :name , :size , :updated_at
fields :name , :tempate
def sections
Section.where(page_id: id).order(index: :asc)

View File

@ -3,9 +3,9 @@ module Merged
belongs_to :page , class_name: "Merged::Page"
fields :id , :name , :page_id , :index
fields :id , :page_id , :index
fields :template , :card_template
fields :header, :text , :image , :options
fields :header, :text , :image
def cards
Card.where(section_id: id).order(index: :asc)
@ -21,10 +21,6 @@ module Merged
end
end
def template_style
SectionStyle.find_by_template( template )
end
def has_cards?
! card_template.blank?
end

View File

@ -1,13 +1,19 @@
module Merged
# base class for viewable elements: ie page, section and casrd
# they share the name and options , and the fact that
# they persist in ActiveYaml
# they share the template idea, options , change tracking,
# and the fact that they persist in ActiveYaml
class ViewBase < ActiveYaml::Base
set_root_path Rails.root #ouside engines not necessary
include ActiveHash::Associations
fields :options , :updated_at , :updated_by
def template_style
SectionStyle.find_by_template( template )
end
def has_option?(option)
options.has_key?(option) and !options[option].blank?
end