2022-11-25 13:46:49 +01:00
|
|
|
module Cms
|
|
|
|
class Page
|
2022-11-25 15:03:39 +01:00
|
|
|
include ActiveModel::Model
|
2022-11-25 13:46:49 +01:00
|
|
|
include ActiveModel::Conversion
|
2022-11-25 15:03:39 +01:00
|
|
|
include ActiveModel::Dirty
|
2022-11-25 13:46:49 +01:00
|
|
|
|
|
|
|
@@files = Set.new Dir.new(Rails.root.join("cms")).children
|
|
|
|
|
2022-11-25 15:03:39 +01:00
|
|
|
attr_reader :name , :content
|
2022-11-25 13:46:49 +01:00
|
|
|
|
|
|
|
def persisted?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize file_name
|
|
|
|
@name = file_name.split(".").first
|
|
|
|
@content = YAML.load_file(Rails.root.join("cms" , file_name))
|
|
|
|
end
|
|
|
|
|
2022-11-25 17:56:46 +01:00
|
|
|
def sections
|
|
|
|
@content.collect{|section_data| Section.new(self , section_data)}
|
|
|
|
end
|
|
|
|
|
2022-11-25 15:03:39 +01:00
|
|
|
def template
|
|
|
|
@content[0]["template"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2022-11-25 13:46:49 +01:00
|
|
|
def self.all
|
|
|
|
@@files.collect{ |file| Page.new(file) }
|
|
|
|
end
|
2022-11-25 15:03:39 +01:00
|
|
|
|
2022-11-25 15:17:54 +01:00
|
|
|
def self.find(name)
|
|
|
|
Page.new(name + ".yaml")
|
|
|
|
end
|
|
|
|
|
2022-11-25 13:46:49 +01:00
|
|
|
end
|
2022-11-25 12:21:52 +01:00
|
|
|
end
|