5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-21 22:06:21 +00:00

feat: poder traer algunas opciones de configuración desde la plantilla #174

This commit is contained in:
f 2024-03-26 15:29:58 -03:00
parent 453798dcc7
commit 263dce1435
No known key found for this signature in database
5 changed files with 48 additions and 0 deletions

View file

@ -76,6 +76,7 @@ gem 'webpacker'
gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git'
gem 'kaminari'
gem 'device_detector'
gem 'dry-schema'
# database
gem 'hairtrigger'

View file

@ -603,6 +603,7 @@ DEPENDENCIES
distributed-press-api-client (~> 0.3.0rc0)
dotenv-rails
down
dry-schema
ed25519
email_address!
exception_notification

View file

@ -11,6 +11,7 @@ class Site < ApplicationRecord
include Site::BuildStats
include Site::LayoutOrdering
include Site::SocialDistributedPress
include Site::DefaultOptions
include Tienda
# Cifrar la llave privada que cifra y decifra campos ocultos. Sutty

View file

@ -0,0 +1,44 @@
# frozen_string_literal: true
require 'dry-schema'
class Site
# Las opciones por defecto se aplican durante la creación del sitio y
# luego se permite a les usuaries modificarlas según quieran. Por el
# momento las opciones nuevas que aparezcan no modifican un sitio que
# ya existe.
module DefaultOptions
extend ActiveSupport::Concern
Schema = Dry::Schema.Params do
optional(:colaboracion_anonima).value(:bool)
optional(:contact).value(:bool)
optional(:acepta_invitades).value(:bool)
optional(:slugify_mode).value(included_in?: Jekyll::Utils::SLUGIFY_MODES)
optional(:pagination).value(:bool)
end
included do
validate :validate_options_from_theme!, if: :persisted?
# @return [Dry::Schema::Result]
def options_from_theme
@options_from_theme ||= Schema.call(data['sutty'])
end
def update_options_from_theme
return true if options_from_theme.to_h.blank?
update(**options_from_theme.to_h)
end
private
def validate_options_from_theme!
options_from_theme.errors.each do |error|
errors.add(:default_options, "#{error.path.map(&:to_s).join('/')} #{error} (#{error.input})")
end
end
end
end
end

View file

@ -27,6 +27,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
site.locales = [usuarie.lang] + I18n.available_locales
site.save &&
site.update_options_from_theme &&
site.config.write &&
commit_config(action: :create) &&
site.reset.nil? &&