mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 15:46:22 +00:00
feat: organizar layouts #13072
This commit is contained in:
parent
05bfc95db6
commit
a94eaceef5
3 changed files with 46 additions and 0 deletions
|
@ -9,6 +9,13 @@ Layout = Struct.new(:site, :name, :meta, :metadata, keyword_init: true) do
|
|||
name.to_s
|
||||
end
|
||||
|
||||
# Obtiene todos los layouts (schemas) dependientes de este.
|
||||
#
|
||||
# @return [Array]
|
||||
def schemas
|
||||
@schemas ||= site.layouts.to_h.slice(*site.schema_organization[name]).values
|
||||
end
|
||||
|
||||
def attributes
|
||||
@attributes ||= metadata.keys.map(&:to_sym)
|
||||
end
|
||||
|
|
|
@ -9,6 +9,7 @@ class Site < ApplicationRecord
|
|||
include Site::Api
|
||||
include Site::DeployDependencies
|
||||
include Site::BuildStats
|
||||
include Site::LayoutOrdering
|
||||
include Tienda
|
||||
|
||||
# Cifrar la llave privada que cifra y decifra campos ocultos. Sutty
|
||||
|
|
38
app/models/site/layout_ordering.rb
Normal file
38
app/models/site/layout_ordering.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Site
|
||||
# Obtiene un listado de layouts (schemas)
|
||||
module LayoutOrdering
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
|
||||
# Obtiene o genera un listado de layouts (schemas) con sus
|
||||
# dependencias, para poder generar un árbol.
|
||||
#
|
||||
# Por defecto, si el sitio no lo soporta, se obtienen los layouts
|
||||
# ordenados alfabéticamente por traducción.
|
||||
#
|
||||
# @return [Hash]
|
||||
def schema_organization
|
||||
@schema_organization ||=
|
||||
begin
|
||||
schema_organization = data.dig('schema', 'organization')
|
||||
schema_organization&.symbolize_keys!
|
||||
schema_organization&.transform_values! do |ary|
|
||||
ary.map(&:to_sym)
|
||||
end
|
||||
|
||||
schema_organization ||
|
||||
begin
|
||||
layouts = self.layouts.sort_by(&:humanized_name).map(&:name)
|
||||
Hash[layouts.zip([].fill([], 0, layouts.size))]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Deprecar cuando renombremos layouts a schemas
|
||||
alias layout_organization schema_organization
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue