hashes for styles to reference by template

This commit is contained in:
Torsten 2022-12-02 18:05:20 +02:00
parent 10cd945472
commit 2b4a89dea8
4 changed files with 37 additions and 16 deletions

View File

@ -2,7 +2,8 @@ module Merged
class StylesController < MergedController class StylesController < MergedController
def index def index
@sections , @cards = Style.all @sections = Style.sections
@cards = Style.cards
end end
end end

View File

@ -3,23 +3,21 @@ module Merged
include ActiveModel::API include ActiveModel::API
cattr_accessor :sections , :cards cattr_accessor :sections , :cards
@@sections = [] @@sections = {}
@@cards = [] @@cards = {}
attr_reader :content attr_reader :content
def initialize content def initialize content
@content = content @content = content
end end
def template
@content["template"] [:template , :text , :header, :fields].each do |meth|
define_method(meth) do
@content[meth.to_s]
end end
def header
@content["header"]
end
def text
@content["text"]
end end
def cards? def cards?
@content["cards"] == true @content["cards"] == true
end end
@ -34,6 +32,7 @@ module Merged
self.all self.all
@@cards @@cards
end end
def self.sections def self.sections
self.all self.all
@@sections @@sections
@ -42,10 +41,15 @@ module Merged
def self.all def self.all
if @@sections.length == 0 if @@sections.length == 0
all = YAML.load_file(Engine.root.join("config/styles.yaml")) all = YAML.load_file(Engine.root.join("config/styles.yaml"))
all["sections"].each { |content| @@sections << Style.new(content) } all["sections"].each do |content|
all["cards"].each { |content| @@cards << Style.new(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 end
[@@sections , @@cards]
end end
end end

View File

@ -2,7 +2,7 @@
%h1.text-4xl.font-bold %h1.text-4xl.font-bold
Section styles Section styles
.grid.grid-cols-3.gap-4.m-8 .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 %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") =image_tag(style.section_preview , class: "h-56 w-full object-contain lg:h-72")
%p.mt-2.text-sm.text-gray-500 %p.mt-2.text-sm.text-gray-500
@ -31,7 +31,7 @@
%h1.text-4xl.font-bold %h1.text-4xl.font-bold
Card styles Card styles
.grid.grid-cols-3.gap-4.m-8 .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 %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") =image_tag(style.card_preview , class: "h-56 w-full object-contain lg:h-72")
%p.mt-2.text-sm.text-gray-500 %p.mt-2.text-sm.text-gray-500

View File

@ -5,9 +5,15 @@ sections:
text: A header with text and two column layout. Columns have a little gap, so text: A header with text and two column layout. Columns have a little gap, so
background color comes through. background color comes through.
cards: true cards: true
fields:
- header
text
- template: section_full_up - template: section_full_up
header: Centered Header with text header: Centered Header with text
text: Full width header with centered headline and optional text text: Full width header with centered headline and optional text
fields:
- header
text
- template: section_half_right - template: section_half_right
header: Split section image right header: Split section image right
text: Image right, header and text on the left. Optional button. text: Image right, header and text on the left. Optional button.
@ -15,13 +21,23 @@ sections:
header: Full image header, text left header: Full image header, text left
text: Large picture background with Header and text towards the left. text: Large picture background with Header and text towards the left.
Text is slightly shaded for readability Text is slightly shaded for readability
fields:
- header
text
- template: section_half_left - template: section_half_left
header: Split section image left header: Split section image left
text: Image left, header and text on the right. Optional button. text: Image left, header and text on the right. Optional button.
fields:
- header
text
- template: section_spacer - template: section_spacer
header: Spacer header: Spacer
text: Just for extra padding text: Just for extra padding
fields:
cards: cards:
- template: card_full_image - template: card_full_image
header: Full background header: Full background
text: With text in bottom right corner, offset with solid color text: With text in bottom right corner, offset with solid color
fields:
- header
text