From 6f6836630f9a2638d40ad8db58ab5219f90a45ec Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 29 Nov 2022 17:59:04 +0200 Subject: [PATCH] card styles and previews --- app/controllers/merged/styles_controller.rb | 4 +-- app/models/merged/style.rb | 26 +++++++++++++++--- app/views/merged/styles/index.haml | 29 +++++++++++++++++++-- config/styles.yaml | 8 +++++- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/app/controllers/merged/styles_controller.rb b/app/controllers/merged/styles_controller.rb index eaaf7fe..d9705e7 100644 --- a/app/controllers/merged/styles_controller.rb +++ b/app/controllers/merged/styles_controller.rb @@ -2,8 +2,8 @@ module Merged class StylesController < MergedController def index - @styles = Style.all + @sections , @cards = Style.all end - + end end diff --git a/app/models/merged/style.rb b/app/models/merged/style.rb index 8c5e826..ac20d19 100644 --- a/app/models/merged/style.rb +++ b/app/models/merged/style.rb @@ -2,6 +2,9 @@ module Merged class Style include ActiveModel::API + cattr_accessor :sections , :cards + @@sections = [] + @@cards = [] attr_reader :content @@ -21,14 +24,29 @@ module Merged def cards @content["cards"] == true end - def preview + def section_preview "merged/section_preview/" + template end + def card_preview + "merged/card_preview/" + template + end + + def self.cards + self.all + @@cards + end + def self.sections + self.all + @@sections + end def self.all - # should account for app styles. now just loading engines - @@styles = YAML.load_file(Engine.root.join("config/styles.yaml")) - @@styles.collect{ |content| Style.new(content) } + 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) } + end + [@@sections , @@cards] end end diff --git a/app/views/merged/styles/index.haml b/app/views/merged/styles/index.haml index 640f86c..5bb9fd4 100644 --- a/app/views/merged/styles/index.haml +++ b/app/views/merged/styles/index.haml @@ -1,7 +1,10 @@ +.px-4.py-8.mx-auto.text-center + %h1.text-4xl.font-bold + Section styles .grid.grid-cols-3.gap-4.m-8 - -@styles.each do |style| + -@sections.each do |style| %article.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm - =image_tag(style.preview , class: "h-56 w-full object-contain lg:h-72") + =image_tag(style.section_preview , class: "h-56 w-full object-contain lg:h-72") %p.mt-2.text-sm.text-gray-500 =style.template %article.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm @@ -23,3 +26,25 @@ Section may include cards. See card styles below -else Section may not include cards + +.px-4.py-8.mx-auto.text-center + %h1.text-4xl.font-bold + Card styles +.grid.grid-cols-3.gap-4.m-8 + -@cards.each do |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 + =style.template + %article.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm + .p-6 + %h3.text-lg.font-medium.text-gray-900 + =style.header + %p.mt-2.text-sm.leading-relaxed.text-gray-500.line-clamp-3 + = style.text + %article.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm + .p-6 + %h3.text-lg.font-medium.text-gray-900 + Option + %p.mt-2.text-sm.leading-relaxed.text-gray-500.line-clamp-3 + Following options: none (wip) diff --git a/config/styles.yaml b/config/styles.yaml index b04b309..4a6bcb5 100644 --- a/config/styles.yaml +++ b/config/styles.yaml @@ -1,3 +1,5 @@ +--- +sections: - template: section_2_col header: Two column layout with header text: A header with text and two column layout. Columns have a little gap, so @@ -18,4 +20,8 @@ text: Image left, header and text on the right. Optional button. - template: section_spacer header: Spacer - text: Just for extra padding + text: Just for extra padding +cards: +- template: card_full_image + header: Full background + text: With text in bottom right corner, offset with solid color