diff --git a/app/controllers/cms/sections_controller.rb b/app/controllers/cms/sections_controller.rb index b15d894..632e964 100644 --- a/app/controllers/cms/sections_controller.rb +++ b/app/controllers/cms/sections_controller.rb @@ -1,4 +1,13 @@ module Cms class SectionsController < CmsController + before_action :set_page, only: %i[ show edit update destroy ] + + + private + def set_page + @page = Page.find(params[:page_id]) + @section = @page.find_section( params[:id] ) + end + end end diff --git a/app/models/cms/page.rb b/app/models/cms/page.rb index 2d841ee..da06ec8 100644 --- a/app/models/cms/page.rb +++ b/app/models/cms/page.rb @@ -21,12 +21,25 @@ module Cms @content.collect{|section_data| Section.new(self , section_data)} end - def template + def find_section(section_id) + content = @content.find{|section| section["id"] == section_id } + Section.new(self , content) + end + + def first_template @content[0]["template"] end + def new_section + section = Hash.new + section['id'] = SecureRandom.hex(10) + @content << section + Section.new(self , section) + end + def save - false + file_name = Rails.root.join("cms" , name + ".yaml") + File.write( file_name , @content.to_yaml) end def self.all diff --git a/app/models/cms/section.rb b/app/models/cms/section.rb index d1645d1..0755ab1 100644 --- a/app/models/cms/section.rb +++ b/app/models/cms/section.rb @@ -20,6 +20,10 @@ module Cms @content["template"] end + def id + @content["id"] + end + def save false end diff --git a/app/views/cms/pages/index.haml b/app/views/cms/pages/index.haml index 4c5693d..9b5b04a 100644 --- a/app/views/cms/pages/index.haml +++ b/app/views/cms/pages/index.haml @@ -19,7 +19,7 @@ %td.whitespace-nowrap.px-4.py-2.text-gray-700 = link_to cms_page.name , cms_page_path(cms_page.name) %td.whitespace-nowrap.px-4.py-2.text-gray-700 - = cms_page.template + = cms_page.first_template %td.whitespace-nowrap.px-4.py-2.text-gray-700 = cms_page.content.length %td.whitespace-nowrap.px-4.py-2 diff --git a/app/views/cms/pages/show.haml b/app/views/cms/pages/show.haml index c0e3ee5..bb6788c 100644 --- a/app/views/cms/pages/show.haml +++ b/app/views/cms/pages/show.haml @@ -15,10 +15,10 @@ %button.mt-4.rounded-lg.bg-yellow-500.p-4 =link_to "Down" , "/index" %button.mt-4.rounded-lg.bg-blue-400.p-4 - =link_to "Edit" , cms_page_section_path(@page.name , 1234) + =link_to "Edit" , cms_page_section_path(@page.name , section.id) %button.mt-4.rounded-lg.bg-cyan-400.p-4 =link_to "New" , "/index" %button.mt-4.rounded-lg.bg-red-400.p-4 =link_to "Delete" , "/index" -section.content.each do |key , value| - = render "cms/sections/data/#{key}", section: section , key: key , value: value + = render "cms/sections/overview/#{key}", section: section , key: key , value: value diff --git a/app/views/cms/sections/editors/_button.haml b/app/views/cms/sections/editors/_button.haml new file mode 100644 index 0000000..bd91f0e --- /dev/null +++ b/app/views/cms/sections/editors/_button.haml @@ -0,0 +1,9 @@ +.relative.block.border.border-gray-100 + %h3.mt-4.text-lg.font-bold= key.upcase + %p + .font-bold Text + = value["text"] +.relative.block.border.border-gray-100 + %p + .font-bold Link + = value["link"] diff --git a/app/views/cms/sections/editors/_card_template.haml b/app/views/cms/sections/editors/_card_template.haml new file mode 100644 index 0000000..7c68474 --- /dev/null +++ b/app/views/cms/sections/editors/_card_template.haml @@ -0,0 +1,6 @@ +.relative.block.border.border-gray-100 + %h3.mt-4.text-lg.font-bold= key.upcase + %p= value + %p #{section.content['cards'].length} cards +.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 new file mode 100644 index 0000000..b0730ae --- /dev/null +++ b/app/views/cms/sections/editors/_cards.haml @@ -0,0 +1,4 @@ +.relative.block.border.border-gray-100 + Cards number +.relative.block.border.border-gray-100 + Card preview diff --git a/app/views/cms/sections/editors/_header.haml b/app/views/cms/sections/editors/_header.haml new file mode 100644 index 0000000..54f381e --- /dev/null +++ b/app/views/cms/sections/editors/_header.haml @@ -0,0 +1,4 @@ +.relative.block.border.border-gray-100 + %h3.mt-4.text-lg.font-bold= key.upcase +.relative.block.border.border-gray-100 + %p= value diff --git a/app/views/cms/sections/data/_cards.haml b/app/views/cms/sections/editors/_id.haml similarity index 100% rename from app/views/cms/sections/data/_cards.haml rename to app/views/cms/sections/editors/_id.haml diff --git a/app/views/cms/sections/editors/_image.haml b/app/views/cms/sections/editors/_image.haml new file mode 100644 index 0000000..458b635 --- /dev/null +++ b/app/views/cms/sections/editors/_image.haml @@ -0,0 +1,4 @@ +.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 diff --git a/app/views/cms/sections/editors/_template.haml b/app/views/cms/sections/editors/_template.haml new file mode 100644 index 0000000..df0ca6a --- /dev/null +++ b/app/views/cms/sections/editors/_template.haml @@ -0,0 +1,5 @@ +.relative.block.border.border-gray-100 + %h3.mt-4.text-lg.font-bold= key.upcase + %p= value +.relative.block.border.border-gray-100 + =image_tag("cms/section_preview/#{section.template}" , class: "w-full object-contain") diff --git a/app/views/cms/sections/editors/_text.haml b/app/views/cms/sections/editors/_text.haml new file mode 100644 index 0000000..54f381e --- /dev/null +++ b/app/views/cms/sections/editors/_text.haml @@ -0,0 +1,4 @@ +.relative.block.border.border-gray-100 + %h3.mt-4.text-lg.font-bold= key.upcase +.relative.block.border.border-gray-100 + %p= value diff --git a/app/views/cms/sections/data/_button.haml b/app/views/cms/sections/overview/_button.haml similarity index 100% rename from app/views/cms/sections/data/_button.haml rename to app/views/cms/sections/overview/_button.haml diff --git a/app/views/cms/sections/overview/_card b/app/views/cms/sections/overview/_card new file mode 100644 index 0000000..e69de29 diff --git a/app/views/cms/sections/data/_card_template.haml b/app/views/cms/sections/overview/_card_template.haml similarity index 100% rename from app/views/cms/sections/data/_card_template.haml rename to app/views/cms/sections/overview/_card_template.haml diff --git a/app/views/cms/sections/overview/_cards.haml b/app/views/cms/sections/overview/_cards.haml new file mode 100644 index 0000000..e69de29 diff --git a/app/views/cms/sections/data/_header.haml b/app/views/cms/sections/overview/_header.haml similarity index 100% rename from app/views/cms/sections/data/_header.haml rename to app/views/cms/sections/overview/_header.haml diff --git a/app/views/cms/sections/overview/_id.haml b/app/views/cms/sections/overview/_id.haml new file mode 100644 index 0000000..e69de29 diff --git a/app/views/cms/sections/data/_image.haml b/app/views/cms/sections/overview/_image.haml similarity index 100% rename from app/views/cms/sections/data/_image.haml rename to app/views/cms/sections/overview/_image.haml diff --git a/app/views/cms/sections/data/_template.haml b/app/views/cms/sections/overview/_template.haml similarity index 100% rename from app/views/cms/sections/data/_template.haml rename to app/views/cms/sections/overview/_template.haml diff --git a/app/views/cms/sections/data/_text.haml b/app/views/cms/sections/overview/_text.haml similarity index 100% rename from app/views/cms/sections/data/_text.haml rename to app/views/cms/sections/overview/_text.haml diff --git a/app/views/cms/sections/show.html.haml b/app/views/cms/sections/show.html.haml index becbe90..09782ad 100644 --- a/app/views/cms/sections/show.html.haml +++ b/app/views/cms/sections/show.html.haml @@ -1,5 +1,8 @@ %p#notice= notice +.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 = #link_to 'Edit', edit_cms_section_path(@cms_section) \|