From 2b4a89dea85172d9077e3a74c38ae9b69ac19ef8 Mon Sep 17 00:00:00 2001 From: Torsten Date: Fri, 2 Dec 2022 18:05:20 +0200 Subject: [PATCH] hashes for styles to reference by template --- app/controllers/merged/styles_controller.rb | 3 ++- app/models/merged/style.rb | 30 ++++++++++++--------- app/views/merged/styles/index.haml | 4 +-- config/styles.yaml | 16 +++++++++++ 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/app/controllers/merged/styles_controller.rb b/app/controllers/merged/styles_controller.rb index d9705e7..0447cdd 100644 --- a/app/controllers/merged/styles_controller.rb +++ b/app/controllers/merged/styles_controller.rb @@ -2,7 +2,8 @@ module Merged class StylesController < MergedController def index - @sections , @cards = Style.all + @sections = Style.sections + @cards = Style.cards end end diff --git a/app/models/merged/style.rb b/app/models/merged/style.rb index 7260fa0..a1bd827 100644 --- a/app/models/merged/style.rb +++ b/app/models/merged/style.rb @@ -3,23 +3,21 @@ module Merged include ActiveModel::API cattr_accessor :sections , :cards - @@sections = [] - @@cards = [] + @@sections = {} + @@cards = {} attr_reader :content def initialize content @content = content end - def template - @content["template"] - end - def header - @content["header"] - end - def text - @content["text"] + + [:template , :text , :header, :fields].each do |meth| + define_method(meth) do + @content[meth.to_s] + end end + def cards? @content["cards"] == true end @@ -34,6 +32,7 @@ module Merged self.all @@cards end + def self.sections self.all @@sections @@ -42,10 +41,15 @@ module Merged def self.all if @@sections.length == 0 all = YAML.load_file(Engine.root.join("config/styles.yaml")) - all["sections"].each { |content| @@sections << Style.new(content) } - all["cards"].each { |content| @@cards << Style.new(content) } + all["sections"].each do |content| + section = Style.new(content) + @@sections[section.template] = section + end + all["cards"].each do |content| + card = Style.new(content) + @@cards[card.template] = card + end end - [@@sections , @@cards] end end diff --git a/app/views/merged/styles/index.haml b/app/views/merged/styles/index.haml index 8abd7e3..60b6fa9 100644 --- a/app/views/merged/styles/index.haml +++ b/app/views/merged/styles/index.haml @@ -2,7 +2,7 @@ %h1.text-4xl.font-bold Section styles .grid.grid-cols-3.gap-4.m-8 - -@sections.each do |style| + -@sections.each do |name , style| %article.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm =image_tag(style.section_preview , class: "h-56 w-full object-contain lg:h-72") %p.mt-2.text-sm.text-gray-500 @@ -31,7 +31,7 @@ %h1.text-4xl.font-bold Card styles .grid.grid-cols-3.gap-4.m-8 - -@cards.each do |style| + -@cards.each do |name , style| %article.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm =image_tag(style.card_preview , class: "h-56 w-full object-contain lg:h-72") %p.mt-2.text-sm.text-gray-500 diff --git a/config/styles.yaml b/config/styles.yaml index 4a6bcb5..04c3f53 100644 --- a/config/styles.yaml +++ b/config/styles.yaml @@ -5,9 +5,15 @@ sections: text: A header with text and two column layout. Columns have a little gap, so background color comes through. cards: true + fields: + - header + text - template: section_full_up header: Centered Header with text text: Full width header with centered headline and optional text + fields: + - header + text - template: section_half_right header: Split section image right text: Image right, header and text on the left. Optional button. @@ -15,13 +21,23 @@ sections: header: Full image header, text left text: Large picture background with Header and text towards the left. Text is slightly shaded for readability + fields: + - header + text - template: section_half_left header: Split section image left text: Image left, header and text on the right. Optional button. + fields: + - header + text - template: section_spacer header: Spacer text: Just for extra padding + fields: cards: - template: card_full_image header: Full background text: With text in bottom right corner, offset with solid color + fields: + - header + text