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

Merge branch 'issue-174' into 'rails'

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

See merge request sutty/sutty!254
This commit is contained in:
fauno 2024-05-02 19:13:20 +00:00
commit aa29893704
5 changed files with 48 additions and 0 deletions

View file

@ -79,6 +79,7 @@ gem 'webpacker'
gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git'
gem 'kaminari'
gem 'device_detector'
gem 'dry-schema'
gem 'rubanok'
gem 'after_commit_everywhere', '~> 1.0'

View file

@ -644,6 +644,7 @@ DEPENDENCIES
distributed-press-api-client (~> 0.4.1)
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
self.filter_attributes += [/_key/, /_ciphertext\z/]

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

@ -29,6 +29,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
add_role_to_deploys! role
site.save &&
site.update_options_from_theme &&
site.config.write &&
commit_config(action: :create) &&
site.reset.nil? &&