mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 07:06:22 +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:
commit
aa29893704
5 changed files with 48 additions and 0 deletions
1
Gemfile
1
Gemfile
|
@ -79,6 +79,7 @@ gem 'webpacker'
|
||||||
gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git'
|
gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git'
|
||||||
gem 'kaminari'
|
gem 'kaminari'
|
||||||
gem 'device_detector'
|
gem 'device_detector'
|
||||||
|
gem 'dry-schema'
|
||||||
gem 'rubanok'
|
gem 'rubanok'
|
||||||
|
|
||||||
gem 'after_commit_everywhere', '~> 1.0'
|
gem 'after_commit_everywhere', '~> 1.0'
|
||||||
|
|
|
@ -644,6 +644,7 @@ DEPENDENCIES
|
||||||
distributed-press-api-client (~> 0.4.1)
|
distributed-press-api-client (~> 0.4.1)
|
||||||
dotenv-rails
|
dotenv-rails
|
||||||
down
|
down
|
||||||
|
dry-schema
|
||||||
ed25519
|
ed25519
|
||||||
email_address!
|
email_address!
|
||||||
exception_notification
|
exception_notification
|
||||||
|
|
|
@ -11,6 +11,7 @@ class Site < ApplicationRecord
|
||||||
include Site::BuildStats
|
include Site::BuildStats
|
||||||
include Site::LayoutOrdering
|
include Site::LayoutOrdering
|
||||||
include Site::SocialDistributedPress
|
include Site::SocialDistributedPress
|
||||||
|
include Site::DefaultOptions
|
||||||
include Tienda
|
include Tienda
|
||||||
|
|
||||||
self.filter_attributes += [/_key/, /_ciphertext\z/]
|
self.filter_attributes += [/_key/, /_ciphertext\z/]
|
||||||
|
|
44
app/models/site/default_options.rb
Normal file
44
app/models/site/default_options.rb
Normal 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
|
|
@ -29,6 +29,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
||||||
add_role_to_deploys! role
|
add_role_to_deploys! role
|
||||||
|
|
||||||
site.save &&
|
site.save &&
|
||||||
|
site.update_options_from_theme &&
|
||||||
site.config.write &&
|
site.config.write &&
|
||||||
commit_config(action: :create) &&
|
commit_config(action: :create) &&
|
||||||
site.reset.nil? &&
|
site.reset.nil? &&
|
||||||
|
|
Loading…
Reference in a new issue