first go at page view, list of sections, wip

This commit is contained in:
2022-11-25 18:56:46 +02:00
parent 0d159912f9
commit 1245c55b65
11 changed files with 73 additions and 30 deletions

View File

@ -1,5 +0,0 @@
module Cms
def self.table_name_prefix
"cms_"
end
end

View File

@ -8,10 +8,6 @@ module Cms
attr_reader :name , :content
def id
@name
end
def persisted?
false
end
@ -21,6 +17,10 @@ module Cms
@content = YAML.load_file(Rails.root.join("cms" , file_name))
end
def sections
@content.collect{|section_data| Section.new(self , section_data)}
end
def template
@content[0]["template"]
end

36
app/models/cms/section.rb Normal file
View File

@ -0,0 +1,36 @@
module Cms
class Section
include ActiveModel::Model
include ActiveModel::Conversion
include ActiveModel::Dirty
attr_reader :name , :content , :page
def persisted?
false
end
def initialize(page , section_data)
@page = page
@content = section_data
# id = SecureRandom.hex(10) if new or not there
end
def template
@content["template"]
end
def save
false
end
def self.all
@page.sections
end
def self.find(page_name , section_id)
Page.new(name + ".yaml")
end
end
end