polish base class
This commit is contained in:
parent
bd22c1fd95
commit
67dc8a07c3
@ -5,7 +5,7 @@ module Merged
|
|||||||
belongs_to :section , class_name: "Merged::Section"
|
belongs_to :section , class_name: "Merged::Section"
|
||||||
|
|
||||||
fields :id , :index , :section_id
|
fields :id , :index , :section_id
|
||||||
fields :text , :header, :image , :options
|
fields :text , :header, :image
|
||||||
|
|
||||||
def move_up
|
def move_up
|
||||||
swap_index_with(next_card)
|
swap_index_with(next_card)
|
||||||
@ -23,12 +23,14 @@ module Merged
|
|||||||
section.cards.where(index: index + 1).first
|
section.cards.where(index: index + 1).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_index(index)
|
# card templates are stored in the section so the all cards
|
||||||
@index = index
|
# have the same
|
||||||
|
def template
|
||||||
|
section.card_template
|
||||||
end
|
end
|
||||||
|
|
||||||
def template_style
|
def template_style
|
||||||
CardStyle.find_by_template( section.card_template)
|
CardStyle.find_by_template( self.template )
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
module Merged
|
module Merged
|
||||||
class Page < ViewBase
|
class Page < ViewBase
|
||||||
|
|
||||||
# could be config options
|
|
||||||
def self.cms_root
|
|
||||||
"cms"
|
|
||||||
end
|
|
||||||
|
|
||||||
fields :name , :size , :updated_at
|
|
||||||
|
fields :name , :tempate
|
||||||
|
|
||||||
def sections
|
def sections
|
||||||
Section.where(page_id: id).order(index: :asc)
|
Section.where(page_id: id).order(index: :asc)
|
||||||
|
@ -3,9 +3,9 @@ module Merged
|
|||||||
|
|
||||||
belongs_to :page , class_name: "Merged::Page"
|
belongs_to :page , class_name: "Merged::Page"
|
||||||
|
|
||||||
fields :id , :name , :page_id , :index
|
fields :id , :page_id , :index
|
||||||
fields :template , :card_template
|
fields :template , :card_template
|
||||||
fields :header, :text , :image , :options
|
fields :header, :text , :image
|
||||||
|
|
||||||
def cards
|
def cards
|
||||||
Card.where(section_id: id).order(index: :asc)
|
Card.where(section_id: id).order(index: :asc)
|
||||||
@ -21,10 +21,6 @@ module Merged
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def template_style
|
|
||||||
SectionStyle.find_by_template( template )
|
|
||||||
end
|
|
||||||
|
|
||||||
def has_cards?
|
def has_cards?
|
||||||
! card_template.blank?
|
! card_template.blank?
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
module Merged
|
module Merged
|
||||||
|
|
||||||
# base class for viewable elements: ie page, section and casrd
|
# base class for viewable elements: ie page, section and casrd
|
||||||
# they share the name and options , and the fact that
|
# they share the template idea, options , change tracking,
|
||||||
# they persist in ActiveYaml
|
# and the fact that they persist in ActiveYaml
|
||||||
|
|
||||||
class ViewBase < ActiveYaml::Base
|
class ViewBase < ActiveYaml::Base
|
||||||
set_root_path Rails.root #ouside engines not necessary
|
set_root_path Rails.root #ouside engines not necessary
|
||||||
include ActiveHash::Associations
|
include ActiveHash::Associations
|
||||||
|
|
||||||
|
fields :options , :updated_at , :updated_by
|
||||||
|
|
||||||
|
def template_style
|
||||||
|
SectionStyle.find_by_template( template )
|
||||||
|
end
|
||||||
|
|
||||||
def has_option?(option)
|
def has_option?(option)
|
||||||
options.has_key?(option) and !options[option].blank?
|
options.has_key?(option) and !options[option].blank?
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user