fix new menthods
This commit is contained in:
@ -7,31 +7,15 @@ module Merged
|
||||
"cms"
|
||||
end
|
||||
|
||||
fields :name , :content , :size , :updated_at
|
||||
fields :name , :size , :updated_at
|
||||
|
||||
def sections
|
||||
Section.where(page_id: id).order(index: :asc)
|
||||
end
|
||||
|
||||
def self.check_name(name)
|
||||
return "only alphanumeric, not #{name}" if name.match(/\A[a-zA-Z0-9]*\z/).nil?
|
||||
nil
|
||||
end
|
||||
def self.build_new(name)
|
||||
raise "only alphanumeric, not #{name}" unless check_name(name).nil?
|
||||
name = name + ".yaml"
|
||||
fullname = Rails.root.join(Page.cms_root , name )
|
||||
File.write(fullname , "--- []\n")
|
||||
Page.new(name)
|
||||
end
|
||||
|
||||
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)
|
||||
@sections << section
|
||||
@content << section_data
|
||||
section = Section.new_section(section_template, self.id , sections.length)
|
||||
section
|
||||
end
|
||||
|
||||
@ -75,6 +59,17 @@ module Merged
|
||||
Page.save_all
|
||||
end
|
||||
|
||||
def self.new_page(name )
|
||||
raise "only alphanumeric, not #{name}" unless check_name(name).nil?
|
||||
data = { name: name.dup }
|
||||
Page.new(data)
|
||||
end
|
||||
|
||||
def self.check_name(name)
|
||||
return "only alphanumeric, not #{name}" if name.match(/\A[a-zA-Z0-9]*\z/).nil?
|
||||
nil
|
||||
end
|
||||
|
||||
def self.save_all
|
||||
data = Page.the_private_records.collect {|obj| obj.attributes}
|
||||
File.write( Page.full_path , data.to_yaml)
|
||||
|
@ -34,12 +34,6 @@ module Merged
|
||||
! card_template.blank?
|
||||
end
|
||||
|
||||
def new_card
|
||||
card = Card.new_card( card_template , self.id , cards.length)
|
||||
card.save
|
||||
card
|
||||
end
|
||||
|
||||
def remove_card(card)
|
||||
from_index = card.index
|
||||
@cards.delete_at(from_index)
|
||||
@ -66,9 +60,9 @@ module Merged
|
||||
page.sections.where(index: index + 1).first
|
||||
end
|
||||
|
||||
def self.build_data(template)
|
||||
data = { "template" => template , "id" => SecureRandom.hex(10) }
|
||||
style = SectionStyle.sections[ template ]
|
||||
def self.new_section(template , page_id , index)
|
||||
data = { template: template , index: index , page_id: page_id}
|
||||
style = SectionStyle.find_by_template( template)
|
||||
style.fields.each do |key|
|
||||
data[key] = key.upcase
|
||||
end unless style.fields.blank?
|
||||
@ -76,7 +70,9 @@ module Merged
|
||||
data["cards"] = []
|
||||
data["card_template"] = CardStyle.first.name
|
||||
end
|
||||
data
|
||||
s = Section.new(data)
|
||||
s.add_default_options
|
||||
s
|
||||
end
|
||||
|
||||
def reset_index
|
||||
|
Reference in New Issue
Block a user