hashes for styles to reference by template

This commit is contained in:
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
def index
@sections , @cards = Style.all
@sections = Style.sections
@cards = Style.cards
end
end

View File

@ -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

View File

@ -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