diff --git a/app/models/cms/page.rb b/app/models/cms/page.rb index da06ec8..860095f 100644 --- a/app/models/cms/page.rb +++ b/app/models/cms/page.rb @@ -18,12 +18,19 @@ module Cms end def sections - @content.collect{|section_data| Section.new(self , section_data)} + sections = [] + @content.each_with_index do |section_data, index| + sections << Section.new(self , index, section_data) + end + sections end def find_section(section_id) - content = @content.find{|section| section["id"] == section_id } - Section.new(self , content) + @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 @@ -34,7 +41,7 @@ module Cms section = Hash.new section['id'] = SecureRandom.hex(10) @content << section - Section.new(self , section) + Section.new(self , 0 , section) end def save diff --git a/app/models/cms/section.rb b/app/models/cms/section.rb index 0755ab1..321705e 100644 --- a/app/models/cms/section.rb +++ b/app/models/cms/section.rb @@ -4,16 +4,18 @@ module Cms include ActiveModel::Conversion include ActiveModel::Dirty - attr_reader :name , :content , :page + attr_reader :name , :content , :page , :index def persisted? false end - def initialize(page , section_data) + def initialize(page , index , section_data) @page = page + raise "No number #{index}" unless index.is_a?(Integer) + raise "No has #{section_data}" unless section_data.is_a?(Hash) + @index = index @content = section_data - # id = SecureRandom.hex(10) if new or not there end def template diff --git a/app/views/cms/sections/editors/_card_template.haml b/app/views/cms/sections/editors/_card_template.haml index 7c68474..4fc5b97 100644 --- a/app/views/cms/sections/editors/_card_template.haml +++ b/app/views/cms/sections/editors/_card_template.haml @@ -2,5 +2,6 @@ %h3.mt-4.text-lg.font-bold= key.upcase %p= value %p #{section.content['cards'].length} cards + %p view cards (index) .relative.block.border.border-gray-100 =image_tag("cms/card_preview/#{value}" , class: "w-full object-contain") diff --git a/app/views/cms/sections/editors/_cards.haml b/app/views/cms/sections/editors/_cards.haml index b0730ae..e69de29 100644 --- a/app/views/cms/sections/editors/_cards.haml +++ b/app/views/cms/sections/editors/_cards.haml @@ -1,4 +0,0 @@ -.relative.block.border.border-gray-100 - Cards number -.relative.block.border.border-gray-100 - Card preview diff --git a/app/views/cms/sections/editors/_image.haml b/app/views/cms/sections/editors/_image.haml index 458b635..c6ce686 100644 --- a/app/views/cms/sections/editors/_image.haml +++ b/app/views/cms/sections/editors/_image.haml @@ -1,4 +1,7 @@ .relative.block.border.border-gray-100 %h3.mt-4.text-lg.font-bold= key.upcase .relative.block.border.border-gray-100 - = image_tag "cms/" + value + -if value + = image_tag "cms/" + value + -else + No image diff --git a/app/views/cms/sections/overview/_image.haml b/app/views/cms/sections/overview/_image.haml index ceb48ad..2beb501 100644 --- a/app/views/cms/sections/overview/_image.haml +++ b/app/views/cms/sections/overview/_image.haml @@ -1,3 +1,6 @@ .p-6 %h3.mt-4.text-lg.font-bold= key.upcase - = image_tag "cms/" + value + -if value + = image_tag "cms/" + value + -else + No image diff --git a/app/views/cms/sections/show.html.haml b/app/views/cms/sections/show.html.haml index 09782ad..6dab4c3 100644 --- a/app/views/cms/sections/show.html.haml +++ b/app/views/cms/sections/show.html.haml @@ -1,5 +1,9 @@ %p#notice= notice +%h1 Page #{@page.name} + +%h4 Section #{@section.id} + .grid.grid-cols-2.gap-2.m-8 - @section.content.each do |key , value| = render "cms/sections/editors/#{key}", section: @section , key: key , value: value diff --git a/cms/studios.yaml b/cms/studios.yaml index 313aec8..dc4bc62 100644 --- a/cms/studios.yaml +++ b/cms/studios.yaml @@ -6,7 +6,8 @@ The rooms are in the old hospital wings, so most are old patient rooms, but there are plenty of others too. Prices do not include electricity or vat, but do include the use of common spaces, see below. - image: makerspace.webp + image: + id: b7d16d4da518bafd3d39 card_template: card_full_image cards: - header: Standard @@ -19,4 +20,3 @@ are large enough to be shared. The size is about 30m2 and the cost 240e. Like the small rooms these are south facing, very light. image: large.webp - id: b7d16d4da518bafd3d39