diff --git a/app/models/metadata_permalink.rb b/app/models/metadata_permalink.rb new file mode 100644 index 0000000..58feb9e --- /dev/null +++ b/app/models/metadata_permalink.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Este metadato permite generar rutas manuales. +class MetadataPermalink < MetadataString + # Los permalinks nunca pueden ser privados + def private? + false + end + + private + + # Al hacer limpieza, validamos la ruta. Eliminamos / multiplicadas, + # puntos suspensivos, la primera / para que siempre sea relativa y + # agregamos una / al final si la ruta no tiene extensión. + def sanitize(value) + value = value.strip.gsub('..', '/').gsub('./', '').squeeze('/') + value = value[1..-1] if value.start_with? '/' + value += '/' if File.extname(value).blank? + + value + end +end diff --git a/app/views/posts/attribute_ro/_permalink.haml b/app/views/posts/attribute_ro/_permalink.haml new file mode 100644 index 0000000..67642e2 --- /dev/null +++ b/app/views/posts/attribute_ro/_permalink.haml @@ -0,0 +1,3 @@ +%tr{ id: attribute } + %th= post_label_t(attribute, post: post) + %td{ dir: dir, lang: locale }= metadata.value diff --git a/app/views/posts/attributes/_permalink.haml b/app/views/posts/attributes/_permalink.haml new file mode 100644 index 0000000..8cbd92c --- /dev/null +++ b/app/views/posts/attributes/_permalink.haml @@ -0,0 +1,7 @@ +.form-group + = label_tag "post_#{attribute}", post_label_t(attribute, post: post) + = text_field 'post', attribute, value: metadata.value, + dir: dir, lang: locale, + **field_options(attribute, metadata) + = render 'posts/attribute_feedback', + post: post, attribute: attribute, metadata: metadata