diff --git a/app/models/merged/card.rb b/app/models/merged/card.rb index c9518aa..f8dfc50 100644 --- a/app/models/merged/card.rb +++ b/app/models/merged/card.rb @@ -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 diff --git a/app/models/merged/page.rb b/app/models/merged/page.rb index db02c03..8160320 100644 --- a/app/models/merged/page.rb +++ b/app/models/merged/page.rb @@ -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) diff --git a/app/models/merged/section.rb b/app/models/merged/section.rb index d0c2b26..06ea624 100644 --- a/app/models/merged/section.rb +++ b/app/models/merged/section.rb @@ -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 diff --git a/app/models/merged/view_base.rb b/app/models/merged/view_base.rb index 8c20949..a9fa48d 100644 --- a/app/models/merged/view_base.rb +++ b/app/models/merged/view_base.rb @@ -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