flattened routes, lots of paths and arg changes

This commit is contained in:
2022-11-30 16:22:11 +02:00
parent 1d91ff2fc6
commit df5713e6fe
31 changed files with 121 additions and 104 deletions

View File

@ -7,10 +7,11 @@ module Merged
cattr_reader :all
@@all = {}
attr_reader :content , :section
attr_reader :content , :index , :section
def initialize(section , card_data)
def initialize(section , index , card_data)
@section = section
@index = index
raise "No data #{card_data}" unless card_data.is_a?(Hash)
@content = card_data
raise "No id #{card_data}" unless id.is_a?(String)
@ -20,5 +21,16 @@ module Merged
def id
@content['id']
end
def save
section.save
end
def self.find(id)
raise "nil given" if id.blank?
card = @@all[id]
raise "Section not found #{id}" unless card
return card
end
end
end

View File

@ -35,7 +35,7 @@ module Merged
File.open(Rails.root.join(Image.asset_root, full_filename), "wb") do |f|
f.write( io.read )
end
self.add( full_filename )
Image.new( full_filename )
end
def self.asset_root

View File

@ -26,22 +26,14 @@ module Merged
def initialize( file_name )
@name = file_name.split(".").first
@content = YAML.load_file(Rails.root.join(Page.cms_root , file_name))
@sections = {}
@sections = []
@content.each_with_index do |section_data, index|
section = Section.new(self , index, section_data)
@sections[ section.id] = section
@sections << section
end
@@all[@name] = self
end
def find_section(section_id)
@content.each_with_index do |section , index|
next unless section["id"] == section_id
return Section.new(self , index , section)
end
raise "Page #{name} as no section #{section_id}"
end
def first_template
@content[0]["template"]
end
@ -59,7 +51,11 @@ module Merged
end
def self.find(name)
@@all[name]
raise "nil given" if name.blank?
page = @@all[name]
raise "Page not found #{name}" unless page
return page
end
end

View File

@ -16,12 +16,11 @@ module Merged
@index = index
@content = section_data
@@all[self.id] = self
@cards = {}
@cards = []
element = @content["cards"]
return if element.nil?
element.each do|card_content|
card = Card.new(self , card_content)
@cards[card.id] = card
element.each_with_index do|card_content , index|
@cards << Card.new(self , index , card_content)
end
end
@ -48,12 +47,14 @@ module Merged
end
def save
raise "Called"
page.save
end
def self.find(page_name , section_id)
raise "buggy"
Page.new(name + ".yaml")
def self.find(section_id)
raise "nil given" if section_id.blank?
section = @@all[section_id]
raise "Section not found #{section_id}" unless section
return section
end
end