5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-15 05:51:41 +00:00

poder elegir valores de una lista predefinida

This commit is contained in:
f 2020-03-25 16:46:16 -03:00
parent b0c2896f5f
commit 0485774507
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
5 changed files with 36 additions and 2 deletions

View file

@ -129,7 +129,7 @@ GEM
dotenv (= 2.7.5) dotenv (= 2.7.5)
railties (>= 3.2, < 6.1) railties (>= 3.2, < 6.1)
ed25519 (1.2.4) ed25519 (1.2.4)
editorial-autogestiva-jekyll-theme (0.1.0) editorial-autogestiva-jekyll-theme (0.2.2)
jekyll (~> 4.0) jekyll (~> 4.0)
jekyll-data (~> 1.1) jekyll-data (~> 1.1)
jekyll-feed (~> 0.9) jekyll-feed (~> 0.9)

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
# Una lista de valores predefinidos
class MetadataPredefinedArray < MetadataArray
def values
@values ||= layout[:metadata][name]['values'].map do |k, v|
{ v[I18n.locale.to_s] => k }
end.inject(&:merge)
end
end

View file

@ -5,7 +5,7 @@
class MetadataRelatedPosts < MetadataArray class MetadataRelatedPosts < MetadataArray
# Genera un Hash de { title | slug => uuid } # Genera un Hash de { title | slug => uuid }
def values def values
site.posts(lang: lang).map do |p| @values ||= site.posts(lang: lang).map do |p|
{ title(p) => p.uuid.value } { title(p) => p.uuid.value }
end.inject(:merge) end.inject(:merge)
end end

View file

@ -0,0 +1,5 @@
%tr{ id: attribute }
%th= post_label_t(attribute, post: post)
%td
- metadata.value.each do |v|
%span.badge.badge-primary= metadata.values.key v

View file

@ -0,0 +1,19 @@
.form-group
= label_tag "post_#{attribute}", post_label_t(attribute, post: post)
.mapable{ data: { values: metadata.value.to_json,
'default-values': metadata.values.to_json,
name: "post[#{attribute}][]", list: id_for_datalist(attribute),
remove: 'false', legend: post_label_t(attribute, post: post),
described: id_for_help(attribute) } }
= text_field(*field_name_for('post', attribute, '[]'),
value: metadata.value.join(', '),
**field_options(attribute, metadata))
= render 'posts/attribute_feedback',
post: post, attribute: attribute, metadata: metadata
%datalist{ id: id_for_datalist(attribute) }
- metadata.values.keys.each do |value|
%option{ value: value }