5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 11:31:41 +00:00

Merge branch 'rails' into rollups

This commit is contained in:
f 2021-10-20 13:32:13 -03:00
commit b7c2061f80
11 changed files with 96 additions and 3 deletions

View file

@ -31,6 +31,11 @@ class MetadataBoolean < MetadataTemplate
self[:value] = true_values.include? self[:value]
end
# Siempre guardar el valor de este campo a menos que sea nulo
def empty?
!value.nil?
end
private
# Los valores que evalúan a verdadero

View file

@ -56,7 +56,7 @@ class MetadataContent < MetadataTemplate
uri = URI element['src']
# No permitimos recursos externos
element.remove unless uri.hostname.end_with? Site.domain
element.remove unless uri.scheme == 'https' && uri.hostname.end_with?(Site.domain)
rescue URI::Error
element.remove
end

View file

@ -0,0 +1,31 @@
# frozen_string_literal: true
# Un campo numérico de punto flotante
class MetadataFloat < MetadataTemplate
# Nada
def default_value
super || nil
end
def save
return true unless changed?
self[:value] = value.to_f
self[:value] = encrypt(value) if private?
true
end
# Indicarle al navegador que acepte números decimales
#
# @return [Float]
def step
0.05
end
private
def decrypt(value)
super(value).to_f
end
end

View file

@ -0,0 +1,24 @@
# frozen_string_literal: true
# Un campo de texto seleccionado de una lista de valores posibles
class MetadataPredefinedValue < MetadataString
# Obtiene todos los valores desde el layout, en un formato compatible
# con options_for_select.
#
# @return [Hash]
def values
@values ||= layout.dig(:metadata, name, 'values', I18n.locale.to_s)&.invert || {}
end
private
# Solo permite almacenar los valores predefinidos.
#
# @return [String]
def sanitize(string)
v = super string
return '' unless values.values.include? v
v
end
end

View file

@ -0,0 +1,3 @@
%tr{ id: attribute }
%th= post_label_t(attribute, post: post)
%td{ dir: dir, lang: locale }= metadata.value

View file

@ -0,0 +1,3 @@
%tr{ id: attribute }
%th= post_label_t(attribute, post: post)
%td{ dir: dir, lang: locale }= metadata.value

View file

@ -0,0 +1,6 @@
.form-group
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
= number_field base, attribute, value: metadata.value, step: metadata.step,
**field_options(attribute, metadata)
= render 'posts/attribute_feedback',
post: post, attribute: attribute, metadata: metadata

View file

@ -0,0 +1,7 @@
.form-group
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
= select_tag(plain_field_name_for(base, attribute),
options_for_select(metadata.values, metadata.value),
**field_options(attribute, metadata), include_blank: t('.empty'))
= render 'posts/attribute_feedback',
post: post, attribute: attribute, metadata: metadata

View file

@ -163,7 +163,7 @@ en:
signature: 'With love, Sutty'
breadcrumb:
title: 'Your location in Sutty'
logout: Exit
logout: Log out
mutual_aid: Mutual aid
collaborations:
collaborate:
@ -442,6 +442,8 @@ en:
destroy: Remove image
belongs_to:
empty: "(Empty)"
predefined_value:
empty: "(Empty)"
draft:
label: Draft
reorder:

View file

@ -163,7 +163,7 @@ es:
signature: 'Con cariño, Sutty'
breadcrumb:
title: 'Tu ubicación en Sutty'
logout: Salir
logout: Cerrar sesión
mutual_aid: Ayuda mutua
collaborations:
collaborate:
@ -450,6 +450,8 @@ es:
destroy: 'Eliminar imagen'
belongs_to:
empty: "(Vacío)"
predefined_value:
empty: "(Vacío)"
draft:
label: Borrador
reorder:

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
# Agrega índices únicos que pensábamos que ya existían.
class AddUniqueness < ActiveRecord::Migration[6.1]
def change
add_index :designs, :name, unique: true
add_index :designs, :gem, unique: true
add_index :licencias, :name, unique: true
end
end