From e29f2b79e8b384aabf0570e35fbb874314c66382 Mon Sep 17 00:00:00 2001 From: Torsten Date: Thu, 1 Dec 2022 15:35:52 +0200 Subject: [PATCH] inlined sectionoverview templates --- app/helpers/merged/sections_helper.rb | 8 +++ app/models/merged/section.rb | 21 ++++---- app/models/merged/style.rb | 2 +- app/views/merged/sections/index.html.haml | 51 +++++++++++++------ .../merged/sections/overview/_button.haml | 8 --- app/views/merged/sections/overview/_card | 0 .../sections/overview/_card_template.haml | 5 -- .../merged/sections/overview/_cards.haml | 0 .../merged/sections/overview/_header.haml | 3 -- app/views/merged/sections/overview/_id.haml | 0 .../merged/sections/overview/_image.haml | 6 --- .../merged/sections/overview/_template.haml | 4 -- app/views/merged/sections/overview/_text.haml | 3 -- 13 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 app/views/merged/sections/overview/_button.haml delete mode 100644 app/views/merged/sections/overview/_card delete mode 100644 app/views/merged/sections/overview/_card_template.haml delete mode 100644 app/views/merged/sections/overview/_cards.haml delete mode 100644 app/views/merged/sections/overview/_header.haml delete mode 100644 app/views/merged/sections/overview/_id.haml delete mode 100644 app/views/merged/sections/overview/_image.haml delete mode 100644 app/views/merged/sections/overview/_template.haml delete mode 100644 app/views/merged/sections/overview/_text.haml diff --git a/app/helpers/merged/sections_helper.rb b/app/helpers/merged/sections_helper.rb index 3008a82..bba2eaa 100644 --- a/app/helpers/merged/sections_helper.rb +++ b/app/helpers/merged/sections_helper.rb @@ -12,5 +12,13 @@ module Merged Image.image_root end + #image tag for the preview, passing options through + def section_preview(section , options) + image_tag("merged/section_preview/#{section.template}" , options) + end + + def card_preview(section , options) + image_tag("merged/card_preview/#{section.card_template}" , options) + end end end diff --git a/app/models/merged/section.rb b/app/models/merged/section.rb index 5c8094c..b989cb1 100644 --- a/app/models/merged/section.rb +++ b/app/models/merged/section.rb @@ -9,6 +9,7 @@ module Merged attr_reader :name , :content , :page , :index , :cards + def initialize(page , index , section_data) @page = page raise "No number #{index}" unless index.is_a?(Integer) @@ -24,6 +25,15 @@ module Merged end end + [:template , :card_template , :id , :text , :header, :image].each do |meth| + define_method(meth) do + @content[meth.to_s] + end + end + + def cards? + @content["cards"] == true + end def update(key , value) return if key == "id" #not updating that @@ -35,17 +45,6 @@ module Merged @content[key] = value end - def template - @content["template"] - end - def card_template - @content["card_template"] - end - - def id - @content["id"] - end - def save page.save end diff --git a/app/models/merged/style.rb b/app/models/merged/style.rb index 84ffc17..7260fa0 100644 --- a/app/models/merged/style.rb +++ b/app/models/merged/style.rb @@ -20,7 +20,7 @@ module Merged def text @content["text"] end - def cards + def cards? @content["cards"] == true end def section_preview diff --git a/app/views/merged/sections/index.html.haml b/app/views/merged/sections/index.html.haml index 1c64672..e463346 100644 --- a/app/views/merged/sections/index.html.haml +++ b/app/views/merged/sections/index.html.haml @@ -6,19 +6,38 @@ Page #{@page.name} -@page.sections.each do |section | - .grid.grid-cols-6.gap-2.m-8{class: (section.index%2)==1 ? 'bg-cyan-50' : 'bg-red-50' } - .relative.block.border.border-gray-100 - .p-4 - %h3.mt-4.text-lg.font-bold Section #{section.index + 1} - %button.mt-4.rounded-lg.bg-yellow-500.p-4 - =link_to( "Up" , "/index") - %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" , section_path(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 "merged/sections/overview/#{key}", section: section , key: key , value: value + .grid.grid-cols-5.gap-2.m-8{class: (section.index%2)==1 ? 'bg-cyan-50' : 'bg-red-50' } + .relative.block.border.border-gray-100.p-4 + %h3.mt-4.text-lg.font-bold Section #{section.index + 1} + %button.mt-4.rounded-lg.bg-yellow-500.p-4 + =link_to( "Up" , "/index") + %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" , section_path(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" + .relative.block.border.border-gray-100.p-4 + %h3.mt-4.text-lg.font-bold Template + %p= section.template + = section_preview(section , class: "w-full object-contain") + .relative.block.border.border-gray-100.p-4 + %h3.mt-4.text-lg.font-bold Header + %p= section.header + %h3.mt-4.text-lg.font-bold Text + %p= section.text + .relative.block.border.border-gray-100.p-4 + - if section.cards? + %h3.mt-4.text-lg.font-bold #{section.content['cards'].length} Cards + =card_preview(section , class: "w-full object-contain") + - else + %h3.mt-4.text-lg.font-bold Image + -if section.image + = image_tag "cms/" + section.image + -else + No image + .relative.block.border.border-gray-100.p-4 + %h3.mt-4.text-lg.font-bold Options + %p To be done diff --git a/app/views/merged/sections/overview/_button.haml b/app/views/merged/sections/overview/_button.haml deleted file mode 100644 index fe2d63a..0000000 --- a/app/views/merged/sections/overview/_button.haml +++ /dev/null @@ -1,8 +0,0 @@ -.p-6 - %h3.mt-4.text-lg.font-bold= key.upcase - %p - .font-bold Text - = value["text"] - %p - .font-bold Link - = value["link"] diff --git a/app/views/merged/sections/overview/_card b/app/views/merged/sections/overview/_card deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/merged/sections/overview/_card_template.haml b/app/views/merged/sections/overview/_card_template.haml deleted file mode 100644 index 216b5ef..0000000 --- a/app/views/merged/sections/overview/_card_template.haml +++ /dev/null @@ -1,5 +0,0 @@ -.p-6 - %h3.mt-4.text-lg.font-bold= key.upcase - %p= value - =image_tag("merged/card_preview/#{value}" , class: "w-full object-contain") - %p #{section.content['cards'].length} cards diff --git a/app/views/merged/sections/overview/_cards.haml b/app/views/merged/sections/overview/_cards.haml deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/merged/sections/overview/_header.haml b/app/views/merged/sections/overview/_header.haml deleted file mode 100644 index eaf2df3..0000000 --- a/app/views/merged/sections/overview/_header.haml +++ /dev/null @@ -1,3 +0,0 @@ -.p-6 - %h3.mt-4.text-lg.font-bold= key.upcase - %p= value diff --git a/app/views/merged/sections/overview/_id.haml b/app/views/merged/sections/overview/_id.haml deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/merged/sections/overview/_image.haml b/app/views/merged/sections/overview/_image.haml deleted file mode 100644 index 2beb501..0000000 --- a/app/views/merged/sections/overview/_image.haml +++ /dev/null @@ -1,6 +0,0 @@ -.p-6 - %h3.mt-4.text-lg.font-bold= key.upcase - -if value - = image_tag "cms/" + value - -else - No image diff --git a/app/views/merged/sections/overview/_template.haml b/app/views/merged/sections/overview/_template.haml deleted file mode 100644 index d8aafb3..0000000 --- a/app/views/merged/sections/overview/_template.haml +++ /dev/null @@ -1,4 +0,0 @@ -.p-6 - %h3.mt-4.text-lg.font-bold= key.upcase - %p= value - =image_tag("merged/section_preview/#{section.template}" , class: "w-full object-contain") diff --git a/app/views/merged/sections/overview/_text.haml b/app/views/merged/sections/overview/_text.haml deleted file mode 100644 index eaf2df3..0000000 --- a/app/views/merged/sections/overview/_text.haml +++ /dev/null @@ -1,3 +0,0 @@ -.p-6 - %h3.mt-4.text-lg.font-bold= key.upcase - %p= value